nwolverson / purescript-language-server

MIT License
184 stars 41 forks source link

Found existing IDE server on port (%d) with wrong PATH #72

Open sriharshachilakapati opened 4 years ago

sriharshachilakapati commented 4 years ago

A user of my Vim wrapper reported today that he is not able to use an existing IDE server with the language server. From the logs, this is the configuration that I'm passing to the language server.

{ "purescript":
    { "autoStartPscIde": true
    , "pscIdePort": 8898
    , "autocompleteAddImport": true
    , "pursExe": "purs"
    , "addNpmPath": true
    }
}

And he's greeted with an error as follows:

[LC] [Error] Found existing IDE server on port '8898' with wrong path: '/home/paluh/programming/purescript/projects/audiocarrier'. Correct, kill or configure a different port, and restart.

I've tried this myself, to check if it is the path that is wrong indeed, and found it is not the case:

CWD checks

Any idea on what are we doing wrong?

Original issue on my Vim plugin: https://github.com/sriharshachilakapati/vimmer-ps/issues/4

nwolverson commented 4 years ago

You know it would be more useful if that error message specified what the expected path was - I assume that either this is wrong, or there is some path normalisation of some kind getting in the way.

Can you post further logs? If I'm reading the code right there should be an info message just prior to that error which contains the other piece of information

sriharshachilakapati commented 4 years ago

These are all the log lines coming from LanguageClient before starting the server.

[LC] Project root: /Users/******/Projects/purescript-**********
[LC] [Info] Starting IDE server
[LC] [Log] PureScript Language Server started
[LC] [Info] {"capabilities":{"textDocument":{"colorProvider":null,"completion":{"completionItem":{"snippetSupport":false}},"signatureHelp":{"signatureInformation":{"parameterInformation":{"labelOffsetSupp
ort":true}}}},"workspace":{"applyEdit":true,"didChangeWatchedFiles":{"dynamicRegistration":true}}},"processId":89536,"rootPath":"/Users/*****/Projects/purescript-**********","rootUri":"file:///Users/*****/Projects/purescript-**********","trace":"verbose"}
[LC] [Log] Starting with args: ["/Users/*****/.nvm/versions/node/v13.11.0/bin/node","/usr/local/bin/purescript-language-server","--stdio","--config","{\"purescript\": {\"pscIdePort\": null, \"autoStartPs
cIde\": true, \"pursExe\": \"purs\", \"addNpmPath\": true, \"autocompleteAddImport\": true}}"]
[LC] [Log] Starting with cwd: /Users/*****/Projects/purescript-********** and using root path: /Users/*****/Projects/purescript-**********
[LC] [Info] Resolved IDE server paths (npm-bin: true) from PATH of node_modules/.bin:/usr/local/sbin:/Users/*****/.gem/ruby/2.6.0/bin:/usr/local/opt/ruby/bin:/Users/*****/.nvm/versions/nod
e/v13.11.0/bin:/Users/*****/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:/Users/*****/.gem/ruby/2.6.0/bin:/usr/local/opt/ruby/bin:/Users/*****/.nvm/vers
ions/node/v13.11.0/bin:/Users/*****/bin:/Users/*****/Library/Android/sdk/build-tools/:/Users/*****/Library/Android/sdk/platform-tools/:/Users/*****/Library/Android/sdk/tools/:/Users/*****/Library/And
roid/sdk/build-tools/:/Users/*****/Library/Android/sdk/platform-tools/:/Users/*****/Library/Android/sdk/tools/ (1st is used):
[LC] [Info] node_modules/.bin/purs: 0.12.5
[LC] [Info] Starting IDE server on port 8898 with cwd
[LC] [Error] Found existing IDE server on port '8898' with wrong path: '/Users/*****/Projects/purescript-**********'. Correct, kill or configure a different port, and restart.

I can confirm that all the paths are verified to the same directory. Tell me if you need any more information.

nwolverson commented 4 years ago

There's some oddness in the logging, but it seems that the expected root path is blank (where it says with cwd, there should be a path).

I think this is down to the starting of the language-server with a config object on the command line, which is different to the way eg vscode does it - this was hard to get working originally (basically VS Code always sends config immediately and the vim language client did not, making it hard to know when to start things up), I think things have changed and I can revisit it.

Basically a timing issue, because you have pre-supplied config, but that doesn't include the root path, the server is starting with blank cwd. Until I fix this, there may be some workaround:

sriharshachilakapati commented 4 years ago

Can you explain how does VS Code pass the config? If there is a command I have to issue, I can do that. LanguageClient_NeoVim allows me to issue custom commands.

Restart/reconnect IDE server (I don't think this will kill your server if it wasn't the one we started)

I tried this. I tried with just issuing purescript.stopPscIde and purescript.startPscIde commands, and also by terminating the entire language client and starting it again. No luck with that. CWD is still going blank.

Don't use autoStartPscIde but run the start command by hand

I don't want to do that as much as possible. The commands in my wrapper are a little verbose to type at every session.

Add the root path to that config JSON object

What is the key that I should use to send it with the JSON?

nwolverson commented 4 years ago

On connection, VS Code immediately sends didChangeConfiguration https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_didChangeConfiguration

At the time of someone first trying this with a non-vscode LSP client, I added the option to instead pass a JSON object on the command line, because that client didn't automatically send config first thing - because there are some config that is only read at startup, and nothing can happen until that config is received.

In newer versions of the LSP spec the server can also request config from the client - if this is implemented it is probably worth my trying to switch to that instead.

In any case I'm going to try to push a version this weekend that at least improves the messaging here (so we can see what the conflicting config is etc), or hopefully something better.

Edit: I just looked and it seems some log lines there are just wrong - definitely worth holding off. But if you do want to try munging that JSON config object, if you take the rootUri and rootPath that is logged there already and paste those in, there is a chance that something might work.

nwolverson commented 4 years ago

I've just published a version which supports the newer workspace/configuration message, as well as the existing client-push and command line config schemes, I believe there may be updated logging that didn't make it to a previous release too.

I'd hope any LSP implementations now will be supporting workspace/configuration, it seems to be the way to go for the future