nwolverson / purescript-language-server

MIT License
185 stars 42 forks source link

Neovim configuration #176

Closed mkohlhaas closed 2 years ago

mkohlhaas commented 2 years ago

As it seems the language server does not call spago sources when using Neovim.

Steps to reproduce:

git clone https://github.com/mkohlhaas/qqqq
cd qqqq
nvim src/Main.purs

Then using goto definition for log works fine and jumps to source code in the .spago directory. But then I get the following error:

Output directory does not exist at '/home/schmidh/Gitrepos/qqqq/.spago/console/v5.0.0/output'. Ensure project is built, or check configuration of output directory and build command..                  

Ensure project is built with the same purs version as the IDE server is using                                                                                                                           

Request Actions:                                                                                                                                                                                        
1. Build project                                                                                                                                                                                        
Type number and <Enter> or click with the mouse (q or empty cancels):    

and further code navigation is not possible.

Language server configuration:

        → purescript.addNpmPath               default: false
        → purescript.addPscPackageSources     default: false
        → purescript.addSpagoSources          default: true
        → purescript.autoStartPscIde          default: true
        → purescript.autocompleteAddImport    default: true
        → purescript.autocompleteAllModules   default: true
        → purescript.autocompleteGrouped      default: true
        → purescript.autocompleteLimit        default: null
        → purescript.buildCommand             default: "spago build --purs-args --json-errors"
        → purescript.buildOpenedFiles         default: false
        → purescript.censorWarnings           default: []
        → purescript.codegenTargets           default: null
        → purescript.declarationTypeCodeLens  default: true
        → purescript.exportsCodeLens          default: true
        → purescript.fastRebuild              default: true
        → purescript.formatter                default: "purty"
        → purescript.fullBuildOnSave          default: false
        → purescript.importsPreferredModules  default: ["Prelude"]
        → purescript.outputDirectory          default: "output\/"
        → purescript.packagePath              default: ""
        → purescript.preludeModule            default: "Prelude"
        → purescript.pscIdePort               default: null
        → purescript.pscIdelogLevel           default: ""
        → purescript.pursExe                  default: "purs"
        → purescript.sourcePath               default: "src"
        → purescript.trace.server             default: "off"

Code navigation with the same project in VS Code works perfectly fine!

nwolverson commented 2 years ago

It looks like your editor is incorrectly configured regarding the workspace root, are you using nvim-lspconfig per the README? In particular the root_dir should be set correctly

I don't use neovim so I don't know how this works, but regardless of editing a file nested inside .spago, you should connect to the language server with a workspace folder of the actual purescript project (the folder with output/ in).

The LSP output logs should show this: "Starting with cwd: [...] and using root path: [...]" which should let you confirm that the root directory is configured correctly.

(Edited the title, this has nothing to do with spago sources, which you have actually confirmed was working correctly)

mkohlhaas commented 2 years ago

Thanks Nicolas,

I was investigating the problem a bit more and it seems to be a problem with nvim-lspconfig. I will open an issue over there.

As it seems I am one of the few who work with PureScript under Neovim. Visual Studio Code is much more popular these days.

Thanks a lot for your language server. Makes working with PureScript a lot easier.

Purerl is also an amazing project!

nwolverson commented 2 years ago

Neovim setup (with built in lsp implementation) should definitely be working, I'm aware of people who are using it - I'm happy to update the suggested config if there's any changes required. Not sure the best place to look for support for that configuration.

I could imagine that if the strategy is to traverse upwards looking for a spago.dhall/etc there is an issue inside .spago directory as those packages do have those files - in a vscode-like model where you edit code relative to some folder, that issue doesn't arise

mkohlhaas commented 2 years ago

Your imagination is spot on! :-)

mkohlhaas commented 2 years ago

Nicolas,

Michael from the nvim-lspconfig project is asking if setting the root directory to where the output directory is, would solve the problem. I use PureScript only with Spago, so I'm not sure how it would work with other project schemes (Bower, ...).

So the question is: Would setting the root directory to output be the solution to the problem?

Thanks for your help!

nwolverson commented 2 years ago

That's not a general solution, because output is configurable, but for a particular user, if you do not reconfigure output, it's a pretty good indicator. However that will only be present if the project is already built, which will be a difference even in the working case today.

Otherwise you can have some random file that your projects use but is never checked into git for a dependency