nim-lang / nim-mode

An emacs major mode for the Nim programming language
138 stars 46 forks source link

company mode blocking and therefore unusable #159

Open krux02 opened 7 years ago

krux02 commented 7 years ago

something must be wrong with the company mode integration. Whenever I edit non trivial Nim files, emacs blocks input for several seconds until it continues working. Therefore I am constantly forced to disable company mode for nim files.

krux02 commented 7 years ago

Well I had to disabled company mode for nim in general because of the blocking performance issue.

yuutayamada commented 6 years ago

Please update nim-mode. Now it should work (or maybe better than before)

krux02 commented 6 years ago

I am testing it right now, I will inform you when about how it works out.

yuutayamada commented 6 years ago

ping @krux02

yuutayamada commented 6 years ago

just FYI, I added log function on latest nim-mode. you can use it by adding following config:

(let ((level :debug))
  (setq warning-minimum-level     level
        warning-minimum-log-level level))

It may help to distinguish the problem is really auto-completion or not.

krux02 commented 6 years ago

Thank you for your information, and I am very happy to see that there is some momentum in nim-mode again. I will check it out.

cipharius commented 6 years ago

Started having this issue as well. company-mode is completely unusable for me in nim-mode. Poked around source, but didn't find what exactly is causing this, but will try some more.

BontaVlad commented 6 years ago

I to had issues with company-mode. Since this is my first adventure in elisp world take everything with a grain of salt.

If you want to investigate the problem by yourself follow these steps:

Step 1: is to enable logging: (let ((level :debug)) (setq warning-minimum-level level warning-minimum-log-level level))

Step 2: If you want to debug emacs you can enable toggle-debug-on-quit and when emacs freezes hit C-g multiple times. This will stop the process and spit out a back-trace.

Step 3: Check the nim-log buffer.

Step 4: Add to nimsuggest-options located in nim-vars.el these additional flags --log, --debug. Restart emacs. These aditional flags will make nimssugest log aditional info and create a nimsuggest.log file in the home folder. If you change some elisp files and want to see the changes without restarting emacs run the function eval-buffer on the modified file.

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.

For the best nim-mode experience:

krux02 commented 6 years ago

@BontaVlad you suggested to use flymake and flycheck. I never used flymake. I don't know what it really is, but I have the impression it tries to do the same thing as flycheck and therefore should not be used at the same time. I guess I am wrong here, so how does flycheck and flymake actually interact with each other?

BontaVlad commented 6 years ago

@krux02 Yes you are right, that was a bad wording on my part. Flycheck and flymake will step on each others tows. At first I chose flymake(the nim-mode source comments recommends it), while I liked the fast feedback is not as well supported(gui stuff) in spacemacs so I switched back to flycheck. If you stick with flycheck, set the checker to nimsuggest, you already using nimssugest for completion, jump at def etc, so you might as well use it for linting. In the end nim-mode is quite usable now, completion is fast, linting also, no more big shutters. Only thing left is to automate some init hooks.

twillis commented 6 years ago

@BontaVlad s comment helped me solve my problem in spacemacs.

when I open a file initially company-diag reports it's using the company-capf backend which is indeed unusable. M-x nimsuggest-mode disables, M-x nimsuggest-mode enables and company-diag reports company-nimsuggest as backend being used and everything is snappy as expected.

So thanks @BontaVlad

krux02 commented 6 years ago

@twillis how big are the files you work with? Company mode with nimsuggest-mode works in small files, but as soon as the file as a certain size, it is just unusable to work with.

twillis commented 6 years ago

@krux02 less than 100 lines, this is just something I found when working through Nim in Action.

krux02 commented 6 years ago

@twillis well I have often more than 1000 lines of code. And I can tell you that even with company-mode disabled nim-mode is often blocking my input. I continue to disable more and more features from nim-mode to keep it usable in my project.

tavurth commented 5 years ago

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.

@BontaVlad Thank you! This resolved the issue for me. it took a long time to track this issue down as this issue was not high on my google ranking.

Perhaps we can remove --refresh from the defaults?

pigmej commented 5 years ago

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

igna92ts commented 5 years ago

@BontaVlad This happened to me as well, but how do I permanently set it to company-nimsuggest? As it is now I need to disable and re-enable nimsuggest-mode to get it to use company-nimsuggest instead of capf

yuutayamada commented 5 years ago

If you want to avoid capf stuff on nim-capf-setup function, you can configure like this:

(advice-add 'nim-capf-setup :override
            (lambda ()
              (when (bound-and-true-p company-backends)
                (add-to-list 'company-backends 'company-nimsuggest))))

I'm not sure why you need to disable and re-enable nimsuggest-mode though.

yuutayamada commented 5 years ago

@igna92ts are you putting nim-mode configuration before your company-mode's configuration? if so, please move your nim-mode configuration to after company-mode's configuration because the company-backends variable might not exist. [edit] sorry I pointed wrong person changed (from @BontaVlad to @igna92ts) and this is for disable/re-enable problem

cyruseuros commented 5 years ago

@yuutayamada, I have the same problem as @igna92ts, even though my nim config comes after my company config. Any thoughts as to why? Also worth noting that after I disable and re-enable nimsuggest-mode, company-nimsuggest appears in company-backends, but not in "Used backend:" when running company-diag.