nim-lang / vscode-nim

A VS Code plugin for the Nim language
Other
75 stars 8 forks source link

Can't connect to Nim Language Server #95

Closed Xkonti closed 4 days ago

Xkonti commented 3 weeks ago

Note: The old extension (before 1.0) somewhat worked from time to time, but it was crashing when including / importing other nim files.

Whenever I turn on VSCode and open a .nim file / project the following set of errors shows up:

image

Current extension version:

1.0.2 - but the problem started with 1.0.0

NimLangServer output:

[Error - 1:59:09 PM] Stopping server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099 

Nim extension output:

2024-08-04 0013:0059:09.0010 - nimlangserver found: C:\Users\onlin\.nimble\bin\nimlangserver.cmd
2024-08-04 0013:0059:09.0010 - Starting nimlangserver.
2024-08-04 0013:0059:09.000368 - Nim Language Server started
2024-08-04 0013:0059:09.000390 - [info] Extension Activated
2024-08-04 0013:0059:0010.000195 - [info] Using NimDir from nimble dump. NimDir: D:\\tools\\Nim\\bin
2024-08-04 0013:0059:0013.000543 - Your lsp version is updated

Versions:

Windows 11

nim -v 
Nim Compiler Version 2.1.99 [Windows: amd64]
Compiled at 2024-09-05
Copyright (c) 2006-2024 by Andreas Rumpf
active boot switches: -d:release

nimble -v
nimble v0.16.0 compiled at 2024-09-05 02:11:30
git hash: couldn't determine git hash

nimlangserver -v
1.4.0

Nim installation process

Just in case I'm doing something wrong:

  1. Get prebuild Nim Devel from Github releases
  2. Remove contents of the existing ~\.nimble and D:\tools\Nim
  3. Extract contents of the Nim.x directory from the .zip to D:\tools\Nim
  4. Get Powershell with admin privileges, get to D:\tools\Nim
  5. Run .\finish.exe to install new Nim version
    • Entry in Path already exists
    • Reinstall mingw
  6. Run nimble install nimlangserver - takes a while but completes successfully
jmgomez commented 4 days ago

Is this still the case with the latest release?

Xkonti commented 4 days ago

@jmgomez I'm on 1.2.0. I just updated the NimLangServer per notification that there's a new version. Now getting a different error set:

image

image

VSCode output in Nim Lsp:

[Trace - 10:13:05 AM] Received notification 'window/showMessage'.
[Trace - 10:13:05 AM] Received notification 'extension/statusUpdate'.
[Trace - 10:13:05 AM] Received notification 'extension/statusUpdate'.
[Trace - 10:13:05 AM] Sending request 'textDocument/inlayHint - (25)'.
An exception occured 
key not found: d:\repos\surreal\tests\test_cbor_decoder_integers.nim
tables.nim(232)          raiseKeyError
ls.nim(761)              tryGetNimsuggest
routes.nim(511)          inlayHint
lstransports.nim(64)     anonymous
lstransports.nim(152)    runRpc
DBG [Processsing Message]                      request="\"textDocument/inlayHint\""
DBG inlayHint received...                     
[Trace - 10:13:05 AM] Received notification 'extension/statusUpdate'.
[Trace - 10:13:05 AM] Received notification 'extension/statusUpdate'.
DBG ShowMessage                                message="Using Nim Compiler Version 2.0.2 [Windows: amd64] from C:\\\\Users\\\\onlin\\\\.nimble\\\\pkgs2\\\\nim-2.0.2-3aa3fb7ac65816001bf960eb3a458681cebb1ff7\\\\bin"
INF Starting nimsuggest                        root="d:\\repos\\surreal\\tests\\test_cbor_decoder_integers.nim" timeout=120000 path="C:\\Users\\onlin\\.nimble\\pkgs2\\nim-2.0.2-3aa3fb7ac65816001bf960eb3a458681cebb1ff7\\bin\\nimsuggest" workingDir="d:\\repos\\surreal"
[Trace - 10:13:05 AM] Received notification 'window/showMessage'.
DBG Nimsuggest Capabilities                    capabilities={}
[Trace - 10:13:05 AM] Received notification 'extension/statusUpdate'.
ERR NimSuggest Error (stderr)                  err=
DBG NimSuggest needed to be restarted due to an error 
WRN Server stopped.                            projectFile="d:\\repos\\surreal\\tests\\test_cbor_decoder_integers.nim"
DBG ShowMessage                                message="Server failed with ."
ERR [RunRPC]                                   msg="key not found: d:\\repos\\surreal\\tests\\test_cbor_decoder_integers.nim" req=ok(textDocument/inlayHint)

The project I'm trying it on (branch cbor): https://github.com/Xkonti/surrealdb.nim/tree/cbor

jmgomez commented 4 days ago

Please, update your Nim version, you are running 2.0.2 It also sounds like you are not running the latest nimlangserver. The version is ouput in the LSP Status in the Nim Panel and at the beginning of the Nim Lsp output log Works fine for me image

Xkonti commented 4 days ago

@jmgomez I'm using Nim devel:

PS D:\repos\surreal> nim -v
Nim Compiler Version 2.1.99 [Windows: amd64]
Compiled at 2024-09-12
Copyright (c) 2006-2024 by Andreas Rumpf

The NimLangServer installs it's own 2.0.2 version in as Nimble package for some unknown to me reason, and the extension seems to use it or something.

I outlined my installation procedure in the issue description. Not sure why this isn't working on my end :/

jmgomez commented 4 days ago

The fact that it installs 2.0.2 tells that you are using an old version. Latest version (1.16.0) use nim 2.0.8 (due to the lock file). Also please, make sure you are using latest nimble (0.16.1)

Xkonti commented 4 days ago

@jmgomez I reinstalled Nim as the newest Devel and this made the nimble 0.16.1 available and that installed the NimLangServer with the proper 2.0.8. The extension actually works this time! This is great!