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

Local modules not discovered #38

Closed
moigagoo opened this issue Jan 13, 2020 · 16 comments
Closed

Local modules not discovered #38

moigagoo opened this issue Jan 13, 2020 · 16 comments

Comments

@moigagoo
Copy link
Contributor

When invoked by nimlsp, nimsuggest won't see local modules.

Consider the following structure:

$ ls

Mode  Last Write Time                Size Name
----  ---------------                ---- ----
d---- 2020-01-13   05:23:01               bar/
-a--- 2020-01-13   05:24:11         32 B  spam.nim

$ ls .\bar\

Mode  Last Write Time                Size Name
----  ---------------                ---- ----
-a--- 2020-01-13   05:23:34         35 B  baz.nim

$ cat .\spam.nim
import bar/baz

echo eggs(3)

$ cat .\bar\baz.nim
proc eggs*(x: int): int = discard

If I open spam.nim in Sublime Text 3 with nimlsp, I'm getting this error:

 ◌ spam.nim:
        1:11  	nimsuggest chk	error     	cannot open file: bar/baz
        3:6   	nimsuggest chk	error     	undeclared identifier: 'eggs'
        3:10  	nimsuggest chk	error     	attempting to call routine: 'eggs'
             	            	          	  found 'eggs' of kind 'unknown'
        3:10  	nimsuggest chk	error     	attempting to call routine: 'eggs'
             	            	          	  found 'eggs' of kind 'unknown'
        3:10  	nimsuggest chk	error     	expression 'eggs' cannot be called

Vanilla nimsuggest, however, doesn't have this issue:

$ nimsuggest.exe .\spam.nim
Hint: used config file 'C:\Users\moigagoo\.choosenim\toolchains\nim-1.0.4\config\nim.cfg' [Conf]
usage: sug|con|def|use|dus|chk|mod|highlight|outline|known file.nim[;dirtyfile.nim]:line:col
type 'quit' to quit
type 'debug' to toggle debug mode on/off
type 'terse' to toggle terse mode on/off
> chk spam.nim
chk     skUnknown               Hint    ???     0       -1      "spam [Processing]"     0
@moigagoo
Copy link
Contributor Author

moigagoo commented Sep 5, 2020

@PMunch sorry for bumping an old issue, but I feel that I'm doing something wrong, this is such an obvious problem I just can't believe everyone else suffers the same.

Do you have the same issue? It basically decimates LSP functionality.

@PMunch
Copy link
Owner

PMunch commented Sep 5, 2020

Hmm, that error message doesn't actually look like anything NimLSP spits out. Do you have any other Nim plug-in?

@moigagoo
Copy link
Contributor Author

moigagoo commented Sep 6, 2020

I also have installed NimLime as suggested in the installation instructions. If I disable it, the suggestion feature is totally disabled and there's no Nim syntax at all. I'm not really sure where the suggestions are coming from, NimLSP or NimLime 🤔 But I thought NimLime lost nimsuggest integration a long time ago.

@moigagoo
Copy link
Contributor Author

moigagoo commented Sep 7, 2020

@PMunch Here's some more info on NimLime and NimLSP interaction.

  1. If I enable NimLime and disable NimLSP, I have syntax highlighting and keyword completion (e.g. proc, iterator, let, etc.). No checks are performed, no output in LSP Diagnostics Panel.

  2. If I disable NimLime and enable NimLSP, I have no syntax highlighting or completion. No checks are performed, no output in LSP Diagnostics Panel. I think this is because there is no Nim syntax which NimLSP is enabled for.

  3. If I enable both, I get the error I initially submitted. The error is shown in LSP Diagnostics Panel, so it must be yielded by NimLSP, which must fetch it from nimsuggest.

@PMunch
Copy link
Owner

PMunch commented Sep 7, 2020

2nd makes sense as Sublime needs to know when to run NimLSP, this is done by NimLime recognising Nim and telling Sublime what language it is. At least in Vim there is a way to manually set what syntax a file is and have LSP kick in that way (without any highlighting or anything), could you see if you have anything like that?

3rd is a bit strange, because as far as I know NimLSP should never output that kind of messages, it uses nimsuggest as a library and not as a separate program, so it has full control over how the messages are formatted.. Which version of NimLSP do you have installed?

@moigagoo
Copy link
Contributor Author

moigagoo commented Sep 7, 2020

could you see if you have anything like that?

Without NimLime enabled, ST won't even offer nim as a syntax highighting options. So, unfortunately, I can't check NimLSP isolated from NimLime, at least I don't know how to do that.

Which version of NimLSP do you have installed?

I have nimlsp 0.2.4 installed via Nimble:

$ nimlsp.cmd --version
nimlsp v0.2.4

@PMunch
Copy link
Owner

PMunch commented Sep 8, 2020

Hmm, okay, could you try to compile a copy yourself and enable the debug logging? That log might shed some light on what's going on.

@moigagoo
Copy link
Contributor Author

moigagoo commented Sep 8, 2020

Sure, I'm happy to help.

I've compiled nimlsp with nimble debug -d:debugLogging, placed the binary to ~/.nimble/bin/nimlsp.exe instead of the previous binary added with nimble install nimlsp.

Here's what I'm getting in LSP Log Panel: https://pastebin.com/MNZyGB9M

@PMunch
Copy link
Owner

PMunch commented Sep 8, 2020

Very strange, NimLSP seems to do what it is supposed to, but nimsuggest keeps giving it errors. Not 100% sure what is happening there, especially since you said that a manually invoked version of nimsuggest worked fine. Did you try to run nimsuggest manually with a "dirty file" e.g. an edited version of the original file as you can see in the logs there?

@moigagoo
Copy link
Contributor Author

moigagoo commented Sep 8, 2020

UPD: I think I got what you meant:

> chk /Users/moigagoo/AppData/Local/Temp/nimlsp/000000009BF83C41.nim
chk     skUnknown               Error   ???     0       -1      "invalid module name: 000000009BF83C41" 0
chk     skUnknown               Hint    ???     0       -1      "000000009BF83C41 [Processing]" 0
chk     skUnknown               Error   C:\Users\moigagoo\AppData\Local\Temp\nimlsp\000000009BF83C41.nim     10       "cannot open file: bar/baz"     0
chk     skUnknown               Error   C:\Users\moigagoo\AppData\Local\Temp\nimlsp\000000009BF83C41.nim     "undeclared identifier: \'eggs\'"        0
chk     skUnknown               Error   C:\Users\moigagoo\AppData\Local\Temp\nimlsp\000000009BF83C41.nim     "attempting to call routine: \'eggs\'\x0A  found \'eggs\' of kind \'unknown\'"   0
chk     skUnknown               Error   C:\Users\moigagoo\AppData\Local\Temp\nimlsp\000000009BF83C41.nim     "attempting to call routine: \'eggs\'\x0A  found \'eggs\' of kind \'unknown\'"   0
chk     skUnknown               Error   C:\Users\moigagoo\AppData\Local\Temp\nimlsp\000000009BF83C41.nim     "expression \'eggs\' cannot be called"   0

Is that what you wanted me to try?


Did you try to run nimsuggest manually with a "dirty file" e.g. an edited version of the original file as you can see in the logs there?

Sorry, I don't think I follow. I haven't edited the file, I'm just saving it to trigger a check, Maybe, add then remove a blank line to create a diff, but that's it. So, there is no dirty file as in “a file with a modification applied.”

Running $ nimsuggest.exe .\spam.nim still yields no error:

Hint: used config file 'C:\Users\moigagoo\.choosenim\toolchains\nim-1.2.6\config\nim.cfg' [Conf]
usage: sug|con|def|use|dus|chk|mod|highlight|outline|known|project file.nim[;dirtyfile.nim]:line:col
type 'quit' to quit
type 'debug' to toggle debug mode on/off
type 'terse' to toggle terse mode on/off
> chk spam.nim
chk     skUnknown               Hint    ???     0       -1      "spam [Processing]"     0

Please correct me if I misunderstood your question.

@moigagoo
Copy link
Contributor Author

moigagoo commented Sep 8, 2020

OK, it's starting to make sense. Here's the content of the tmp file, C:\Users\moigagoo\AppData\Local\Temp\nimlsp\000000009BF83C41.nim:

import bar/baz


echo eggs(3)

And here's the content if the directory it's in:

ll C:\Users\moigagoo\AppData\Local\Temp\nimlsp\

Mode  Last Write Time                Size Name
----  ---------------                ---- ----
-a--- 2020-09-04   12:16:01        932 B  000000002CBCFEA9.nim
-a--- 2020-09-04   12:16:01          0 B  000000003276C89B.nim
-a--- 2020-09-04   12:18:27        346 B  00000000499D62B6.nim
-a--- 2020-09-08   03:22:55         31 B  000000009BF83C41.nim
-a--- 2020-09-06   10:11:08         35 B  000000009CC337B9.nim
-a--- 2020-09-08   12:11:23          6 KB 00000000CD3B2032.nim
-a--- 2020-09-04   12:18:13        732 B  00000000F4C89EB8.nim
-a--- 2020-09-08   03:20:41          0 B  nimlsp.log

So, of course import from bar/baz fails, there is no bar or baz in there.

@PMunch
Copy link
Owner

PMunch commented Sep 8, 2020

Yeah that's normal. That directory contains files with modifications in them that haven't been saved. Nimsuggest supports passing both a file and a dirty file when doing the check or asking for e.g. hover information. In that case it will behave as if the contents of the file where the contents of the dirty file, but it should still look for imports and such in the original folder. Try to run chk C:/Users/moigagoo/Projects/foo/spam.nim;C:\Users\moigagoo\AppData\Local\Temp\nimlsp\000000009BF83C41.nim that should use the dirtyfile (obviously change the name). Looking at the log though it seems like maybe only the dirtyfile has / replaced with \ in Windows, I wonder if that might be the issue.

@moigagoo
Copy link
Contributor Author

moigagoo commented Sep 8, 2020

Try to run chk C:/Users/moigagoo/Projects/foo/spam.nim;C:\Users\moigagoo\AppData\Local\Temp\nimlsp\000000009BF83C41.nim

Here you go:

> chk /Users/moigagoo/Projects/foo/spam.nim;/Users/moigagoo/AppData/Local/Temp/nimlsp/000000009BF83C41.nim
chk     skUnknown               Hint    ???     0       -1      "spam [Processing]"     0

Note that I have to deplace C:/ with just /, otherwise it fails:

> chk C:/Users/moigagoo/Projects/foo/spam.nim;C:\Users\moigagoo\AppData\Local\Temp\nimlsp\000000009BF83C41.nim
chk     skUnknown               Hint    ???     0       -1      "C [Processing]"        0
chk     skUnknown               Error   ???     0       -1      "cannot open \'C\'"     0

@moigagoo
Copy link
Contributor Author

moigagoo commented Sep 8, 2020

Looking at the log though it seems like maybe only the dirtyfile has / replaced with \ in Windows, I wonder if that might be the issue.

According to what I'm seeing with nimsuggest, it's the opposite: \ should be replaced with /, and C:\ should be /.

@PMunch
Copy link
Owner

PMunch commented Sep 9, 2020

Hmm, this is pretty hard for me to debug as I don't have any Windows machines.. If you want you can have a poke around the code and see if you can get the paths into a format that works. It's a bit odd though, there are definitely people who have tried it on Windows before, even had PRs to fix some other path related issues in the past.

@moigagoo
Copy link
Contributor Author

@PMunch I've fixed the issue in #62.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants