Use nim track for goto definition and find usages - #434
Conversation
Update the code to match the updated dependencies. This PR is cherrypicked from #412.
Version 0.20.1 used before would install Nim with mismatching checksum.
Turns out it causes more problems than benefits; config value is enough to toggle nim-track mode.
Nimble resolves nim#head to nim 2.2.10 if unittest2 is required.
Callsite directory was used, which doesn't make much sense.
Previously, we would blindly call `nim` from PATH. Also, the proc is called exclusively in async context so I made it async.
…rectory. Previously, we would call it in the callsite directory returning the wrong nimsuggest (and subsequently nim).
|
I had to rewrite some things not directly related to To test the new mode locally:
$ nimble install https://github.com/nim-lang/langserver@#feature/nim_track
$ nimble install https://github.com/moigagoo/nimble@#bugfix/nimble_dump_with_nim_head
[[language]]
name = "nim"
language-servers = ["nimlangserver"]
[language-server.nimlangserver]
command = "nimlangserver"
args = ["--lsp", "--stdio"]
[language-server.nimlangserver.config.nim]
useNimTrack = true
If everything is fine so far, launch your editor and try doing goto def and find refs ( The commands are slow at first because Happy testing! |
|
This is what the AI says, verify and let me know so I can take a closer look. Thanks!
|
Fixed.
This is interesting. The thing is, I deliberately chose to run So my options were to only serve saved files, fallback to nimsuggest, or invent something to work around that limitation. I chose the first option because it was the simplest solution. Using nimsuggest kind of defeats the whole purpose of |
There was a problem hiding this comment.
Initially, I got confused between project dependencies and langserver dependencies and so tried setting up Nim#head as a dependency to langserver. This didn't work with lock files.
Later on this all became irrelevant since it's the project that must depend on Nim#head, not langserver. But I forgot to revert these commits.
Reverted.
| requires "nim == 2.0.8", | ||
| "chronos >= 4.0.4", "json_rpc >= 0.5.0", "with", "chronicles", "serialization", | ||
| "json_serialization", "stew", "regex", "unittest2 >= 0.2.4" | ||
| requires "nim >= 2.2.10", |
There was a problem hiding this comment.
I feel like bumping deps doesnt belong to this pr
There was a problem hiding this comment.
Answered in a comment above: https://github.com/nim-lang/langserver/pull/434/changes/BASE..98e62df8720397ee8292b3c7a14787b5422843c0#r3748271486
| nimExpandMacro*: Option[bool] | ||
| maxNimsuggestProcesses*: Option[int] | ||
| #max number of nimsuggest processes to keep alive. zero means unlimited | ||
| useNimTrack*: Option[bool] |
There was a problem hiding this comment.
what happens when it is enabled in a nim version that doesnt support track?
There was a problem hiding this comment.
You'll get an error:
"nim track not supported (requires nim >= 2.3.1)"
The reasoning behind this decision is, this is a very experimental feature, it requires development version of Nim and some dedication. You can't accidentally turn it on, if it's on, you know what you did. So I thought I shouldn't invest too much into handling this, the simplest logic will do. If invalid command: track is in the stderr, that means you're not using Nim#devel.
Then a follow up must be done where its supported, otherwise it wont work 99% of the times when working with code, no? Or am I missing something else? AFAIR a file becomes dirty when there is unsaved modification. For the time being, we should fallback to ns if thats the case |
This reverts commit 1ddab8b.
This resolves "Error: Exception can raise an unlisted exception: Exception."
This was unintentionally removed in the previous commit.
You are right, since most people don't use autosave this won't work for them.
When, exactly.
Removed immediate |
Nim 2.4.0 adds a new command
nim track --def|--usages|--defusagesthat replaces nimsuggest'sdefandusecommands.This PR adds an experimental implementation of goto def and find refs based on
nim track.