Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After upgrade to 105 Emacs freezes in nim-mode in auto-complete #4403

Closed
manfredlotz opened this issue Jan 5, 2016 · 35 comments
Closed

After upgrade to 105 Emacs freezes in nim-mode in auto-complete #4403

manfredlotz opened this issue Jan 5, 2016 · 35 comments
Labels
Auto-completion Documentation ✏ Nim stale marked as a stale issue/pr (usually by a bot)

Comments

@manfredlotz
Copy link

After upgrade to 105 Emacs freeze in nim-mode in auto-complete. Same happens when running emacs -nw

After a while a message
Timeout server response.

Then when quitting Emacs a couple of processes will be displayed like this

epc:server:2 run epc:server:2 /dev/pts/19 --verbosity:0 --epc /home/manfred/t.nim
epc:server:3 run epc:server:3 /dev/pts/20 --verbosity:0 --epc /home/manfred/t.nim
epc:server:4 run epc:server:4 /dev/pts/21 --verbosity:0 --epc /home/manfred/t.nim
...
epc:server:8 run epc:server:8 /dev/pts/25 --verbosity:0 --epc /home/manfred/t.nim

@manfredlotz manfredlotz changed the title After upgrade to 105 Emacs freeze in nim-mode in auto-complete After upgrade to 105 Emacs freezes in nim-mode in auto-complete Jan 5, 2016
@manfredlotz
Copy link
Author

To help with reproducing:

  1. activate layer nim
  2. then create a new file /tmp/x.nim
    and type

proc

After proc and blank the auto-complete jumps in and there will be a timeout from the epc server(s).

@yuutayamada
Copy link

Hi, although I'm not spacemacs user, eventually I found this issue.
So, sorry if I wrote wrong thing. currently nim-mode repository only support
company-mode (company-nim.el in the repo).

If you set up https://github.com/nim-lang/nimsuggest,
basically you only need

(add-to-list 'company-backends 'company-nim)
(setq nim-nimsuggest-path "path/to/nimsuggest-binary")

in your init.el (or spacemacs does in other ways?)
nim-nimsuggest-path might be optional (I'm not sure), but if you set that
it automatically enable eldoc feature as well in recent nim-mode.

By the way, does anyone have electric-indent-mode trouble in spacemacs' nim-mode?
I saw this issue in nim-mode repo nim-lang/nim-mode#54
(it does newline-and-indent if you push return key) if it's solved already,
I would close the issue.

@yuutayamada
Copy link

I bit researched inside spacemacs and it seems already using company-mode...
In my emacs (master branch), I can use company-mode in nim files. So, I guess
emacs's byte-compile problem or nim and nimsuggest's version dependent problem?
(sometimes nimsuggest needed to update when I updated nim)
I hope this may help you.

@manfredlotz
Copy link
Author

Yes, company-mode is the default for auto-completion in spacemacs. The problem with the epc servers still persists. The nim-mode package contains a nim-suggest.el but it doesn't contain a version number. The nim-mode.el has just Version: 0.2.0.

@manfredlotz
Copy link
Author

When typing something in a nim-mode buffer comany mode jumps in, and the session hangs till getting a timeout.

In the Messages buffer I found:

Company: An error occurred in auto-begin
Timeout server response.
Company: An error occurred in auto-begin
Timeout server response.

@yuutayamada
Copy link

I'm not sure, but I seem it's failing to communicate nimsuggest via epc.
Do you have https://github.com/nim-lang/nimsuggest?
nim-mode repository doesn't include this, so if you don't have it
you can't use auto-complete feature. (it's not nim-suggest.el)

@manfredlotz
Copy link
Author

Hi Yuuta,
Thanks a lot for your help. Now, with your last advice I finally realized that the binary nimsuggest is required. Now it works.

What I did.

  1. I got me nimsuggest
    git clone https://github.com/nim-lang/nimsuggest.git
  2. I installed it
    cd nimsuggest
    nimble install
  3. Copied nimsuggest binary into /usr/local/bin (as there are my local systemwide things)
  4. In ~/.spacemacs in dotspacemacs/user-config () I set
    (setq nim-nimsuggest-path "/usr/local/bin")

Now it works fine.

What does it mean for this issue?

On the one hand it could be closed? On the other hand the need of a binary nimsuggest for working correctly (in nim-mode) with comany mode should be made clear in the layer documentation of nim-mode.

Thanks again, Yuuta.

@TheBB
Copy link
Collaborator

TheBB commented Jan 19, 2016

Sounds like a documentation bug, then.

@manfredlotz
Copy link
Author

Yes, I think so.
One additional remark: when building nimsuggest the nim compiler and the nimble package manager are required.

But people who use nim-mode should satisfy that prerequisite.

@yuutayamada
Copy link

That's good manfredlotz.

(about this issue: nim-lang/nim-mode#54) What I wanted to ask is "can
you use return key normally?"
Sorry, it's sound fanny, but old nim-mode had bug that enabling
electric-indent-mode. It does return-and-indent when you type
return key. The guy who opened that issue on nim-mode repository
still don't close the issue, so I wondered whether it's solved or not
on spacemacs.

@manfredlotz
Copy link
Author

I copied the code from that issue into a new buffer x.nim. Then I enterered (starting in column 0)
for i,c in TRange(Low:1, high: 3):

and after pressing the ENTER-Key the cursor is in the next line in column 3 (directly below the 'r' in for).

@yuutayamada
Copy link

In latest nim-mode return-key should behave as just new line, so
I guess your environment is using old version's nim-mode.
(for quick check, if you are using latest version, nim-mode
repository has nim-eldoc.el)
But I don't know why... Does spacemacs use stable package of melpa?

@manfredlotz
Copy link
Author

The nim-mode in spacemacs contains nim-eldoc.el. I like the automatic indentation.

@manfredlotz
Copy link
Author

Perhaps for clarification. In my example above the indentation of the line
for i,c in TRange(Low:1, high: 3):
did not change after I had pressed ENTER. But I endet up in the next line in column 3 which seems to be quite natural.

@yuutayamada
Copy link

Thanks manfredlotz about that information.
But I wonder spacemacs' configuration for nim.
Is there other way to insert just newline without indentation?
nim is indent sensitive language, so you might want to insert only newline
sometimes.

@manfredlotz
Copy link
Author

I don't think that spacemacs has done anything bad to nim-mode. I don't know nim-mode very good as I stumbled over nim 4 weeks ago. Then, I was looking for a major mode providing nim support in Emacs. Found nim-mode and in the meantime it works quite ok.

So I don't know (perhaps have to look up the sources) if there are ways to press enter with indentation and without.

@yuutayamada
Copy link

@manfredlotz are you using emacs 24.4?
I realized electric-indent-inhibit which is configured in nim-mode
isn't enough for specific emacs 24.4 from this discussion:
haskell/haskell-mode#377 (thanks haskellers)

can you configure this:

(add-hook 'nim-mode-hook
          (add-to-list 'electric-indent-functions-without-reindent
                       'nim-indent-line-function))

This configuration add nim-mode's indentation function to
electric-indent-mode's blocklist. If this is ok for you, I'll make a PR to nim-mode

@manfredlotz
Copy link
Author

I tried it but this is not what I want as I don't have any indentation automatically when pressing ENTER.

@yuutayamada
Copy link

I think you can use C-j instead of ENTER for insert newline and next line's auto indentation (if spacemacs doesn't change from default)
Isn't it enough for you?

EDIT:
not sure if you need, but here is a work around:

(add-hook 'nim-mode
          (lambda ()
            (define-key nim-mode-map (kbd "RET") 'newline-and-indent)))

Please discuss this issue inside spacemacs group because one spacemacs user asked at
nim-mode repo to disable newline-and-indent on enter key. or you can make your specific
configuration for nim-mode.

@robbyoconnor
Copy link
Contributor

I think there should be a PR -- I don't personally care enough to make it...but someone should make a PR to fix this ;)

@krux02
Copy link

krux02 commented Apr 20, 2016

I am not surce if this is related to this bug, but I simply can not get nim-mode to work with auto completion. I simply don't what is going wrong or how to find out what is going wrong, because I am new to spacemacs. But there is something that I think might be one of the reasons why auto completion doesn't work for me. It is this: In the documentation of nim-mode it mentions that I have to add company-nim-builtin to the company-backends

(add-to-list 'company-backends
           '(company-nim :with company-nim-builtin))

But in package.el it only adds company-nim.

:init (when (configuration-layer/package-usedp 'company)
        (push 'company-nim company-backends-nim-mode))

Unfortunately changis this line alone didn't change anything for me, so there has to be something that is wrong, too.

@manfredlotz
Copy link
Author

You have nimsuggest installed and it is to be found in your path?

@krux02
Copy link

krux02 commented Apr 20, 2016

yes it is found, this is what describe-variable RET nim-nimsuggest-path gives:

nim-nimsuggest-path is a variable defined in `nim-vars.el'.
Its value is "/home/arne/.nimble/bin/nimsuggest"

Documentation:
Path to the nimsuggest binary.

I did not set the variable manually, I just added "/home/arne/.nimble/bin" to my path

@manfredlotz
Copy link
Author

I checked my .spacemacs, and saw that I only set the path for nimsuggest in nim-nimsuggest-path. Nothing else. I have no freeze in nim-mode.

In the nim-mode documentation I cannot find anything that tells me I have to add company-nim-builtin to the company-backends.

@yuutayamada
Copy link

@krux02 and @manfredlotz the configuration about
company-nim-builtin adds additional candidates for completion
(functions and types from system.nim), but old configuration (current
spacemacs' configuration) should be worked without it as well.
(The feature was added later version's nim-mode)

So, if you don't get any completion, maybe there is another reason.

@yuutayamada
Copy link

yuutayamada commented Apr 22, 2016

@krux02 To narrow your problem, I suggest following things:

  1. Check M-. key (Meta + dot) on echo in a nim file.
    The expected behavior is jumping to the definition if
    nimsuggest is working correctly in your environment.

  2. If 1 is ok, try manual completion

    open a new nim file and then insert

    import strutils
    strutils.isd # <- move cursor after `isd`

    then move cursor after strutils.isd and then
    type M-x company-nim

    Does it show you completion result?

EDIT:
I don't know spacemacs' default keybinding, if there is another keybinding
at M-., please try M-x nim-goto-sym instead

@krux02
Copy link

krux02 commented Apr 24, 2016

alt-x nim-goto-sym with my cursor on echo has this result:

deferred error : (error "Symbol not found")

So yes there is something not working.

@yuutayamada
Copy link

I have no idea what's happening...

The error message means:

  1. your emacs is communicating with nimsuggest server
  2. but nimsuggest server returns no result for echo

I think same thing is happening for auto-completion because it
uses nimsuggest (jump to definition uses def and auto-completion uses sug instead)

I think there is nothing we can examine from emacs side.

@krux02
Copy link

krux02 commented Apr 25, 2016

Funny thing is, that in plain emacs, without spacemacs, all worked fine with the autocompletion. So I also have no idea what might have caused that error. Could there be any paths wrong that link to standard library or something?

@krux02
Copy link

krux02 commented Apr 25, 2016

so Is there anything I can do from my side? Because syntax checking does work properly, and when I have errors there, I see the correct alternatives listed properly as it should be.

@yuutayamada
Copy link

when I have errors there, I see the correct alternatives listed properly as it should be.

This is because spacemacs (flycheck-nim.el) uses nim compiler instead of nimsuggest.
(I mean nim check command)

The nim-goto-sym function is most easy way to check whether your
environment can use nimsuggest (the function doesn't depend on
company-mode and flycheck, so)

@tavurth
Copy link

tavurth commented Aug 11, 2018

nim-lang/nim-mode#159

In my case, running nimssugest with the --refresh would make nimsuggest freak out and repeatedly compile my file if it encountered an error, this in turn would trigger the timeout in nimsuggest--call-sync, and also call over and over again (sleep-for 0.01). Getting rid of the --refresh option and setting the time to 5s and the sleep-for to a 0.3 s ameliorates the problem.

Remove --refresh in the following file: ~/.emacs.d/elpa/27.0/develop/nim-mode-20180516.2009/nim-vars.el on line 143

@pigmej
Copy link

pigmej commented Sep 20, 2018

You can set this variable by M-x customize-variable and customize nimsuggest-options

No need to manually edit files.

@tavurth
Copy link

tavurth commented Sep 20, 2018

Perhaps this would be a better default, since it's causing some users issues?

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-completion Documentation ✏ Nim stale marked as a stale issue/pr (usually by a bot)
Projects
None yet
Development

No branches or pull requests

8 participants