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

usage in a nix project? #78

Closed
o1lo01ol1o opened this issue May 2, 2018 · 14 comments
Closed

usage in a nix project? #78

o1lo01ol1o opened this issue May 2, 2018 · 14 comments

Comments

@o1lo01ol1o
Copy link

There are some notes in the documentation about using the hie wrappers to get support in nix projects, is this possible?

I've currently installed hie-nix into my project environment (I can run the hie sever from my nix-shell) and I have the following wrappers in my vscode configuration.

    "languageServerHaskell.useCustomHieWrapper": true,
    "languageServerHaskell.useCustomHieWrapperPath": "${workspaceFolder}/backend/hie.sh"

where backend/hie.sh is:

eval "nix-shell -A backend.env --run 'hie-8.0 --lsp -d -r .'"

But it looks like this doesn't work for vscode-hie-server

[Error - 10:01:51 AM] Starting client failed
Error: spawn EACCES
	at exports._errnoException (util.js:1050:11)
	at ChildProcess.spawn (internal/child_process.js:319:11)
	at Object.exports.spawn (child_process.js:390:9)
	at _getServerWorkingDir.then.serverWorkingDir (... alanz.vscode-hie-server-0.0.16/node_modules/vscode-languageclient/lib/main.js:346:40)
	at <anonymous>

can anyone advise?

@Tehnix
Copy link
Contributor

Tehnix commented May 8, 2018

Hmm, as long as VSCode can interact with the process via stdin/stdout, it should technically work 🤔

@alanz
Copy link
Collaborator

alanz commented May 19, 2018

I think you should ask this in the nix support zone, I am sure there are some people using it, but have no idea how.

@kitlangton
Copy link

Any luck with this?

@codygman
Copy link

codygman commented Sep 1, 2020

I'm late to the party... but @o1lo01ol1o you probably want to just use nix environment selector. It's a bit more manual than say the direnv plugin+ lorri but it always works.

Also until vscode supports plugin ordering microsoft/vscode#57481 (which they seem to have no interest in) any automated direnv usage will only ever work by chance since direnv needs to modify the load paths/env vars of other plugins before they start.

Related: microsoft/vscode#13292

@Rizary
Copy link

Rizary commented Dec 19, 2020

I get stuck whenever I want to save the file with Running 'Haskell Formatter', sometimes running code actions. It's just stuck.

Here is my log:

[Error - 4:07:41 PM] Request textDocument/codeAction failed.
Error: Connection got disposed.
	at Object.dispose (/home/rizary/.vscode-server-insiders/extensions/haskell.haskell-1.2.0/dist/extension.js:1:90902)
	at Object.dispose (/home/rizary/.vscode-server-insiders/extensions/haskell.haskell-1.2.0/dist/extension.js:1:74181)
	at /home/rizary/.vscode-server-insiders/extensions/haskell.haskell-1.2.0/dist/extension.js:1:70796
[Error - 4:07:41 PM] Request textDocument/formatting failed.
Error: Connection got disposed.
	at Object.dispose (/home/rizary/.vscode-server-insiders/extensions/haskell.haskell-1.2.0/dist/extension.js:1:90902)
	at Object.dispose (/home/rizary/.vscode-server-insiders/extensions/haskell.haskell-1.2.0/dist/extension.js:1:74181)
	at /home/rizary/.vscode-server-insiders/extensions/haskell.haskell-1.2.0/dist/extension.js:1:70796
[Error - 4:07:41 PM] Request textDocument/documentSymbol failed.
Error: Connection got disposed.
	at Object.dispose (/home/rizary/.vscode-server-insiders/extensions/haskell.haskell-1.2.0/dist/extension.js:1:90902)
	at Object.dispose (/home/rizary/.vscode-server-insiders/extensions/haskell.haskell-1.2.0/dist/extension.js:1:74181)
	at /home/rizary/.vscode-server-insiders/extensions/haskell.haskell-1.2.0/dist/extension.js:1:70796
Found "/home/rizary/rizichain/hie.yaml" for "/home/rizary/rizichain/a"
Module "/home/rizary/rizichain/a" is loaded by Cradle: Cradle {cradleRootDir = "/home/rizary/rizichain", cradleOptsProg = CradleAction: Cabal}
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 0.7.1.0 x86_64 ghc-8.10.2
Current directory: /home/rizary/rizichain
Operating system: linux
Arguments: ["--lsp","-d","-l","/home/rizary/hls.log"]
Cradle directory: /home/rizary/rizichain
Cradle type: Cabal

Tool versions found on the $PATH
cabal:		3.2.0.0
stack:		Not found
ghc:		8.10.2


Consulting the cradle to get project GHC version...
Project GHC version: 8.10.2
haskell-language-server exe candidates: ["haskell-language-server-8.10.2","haskell-language-server-8.10","haskell-language-server"]
Launching haskell-language-server exe at:/nix/store/mz18izh5rzskjfr9ji5kas6341scshx1-rizichain-env/bin/haskell-language-server-8.10.2
haskell-language-server version: 0.7.1.0 (GHC: 8.10.2) (PATH: /nix/store/jlwpd1fksr37ibnzz5c4cqi565n43xvr-haskell-language-server-0.7.1.0/bin/haskell-language-server)
Starting (haskell-language-server)LSP server...
  with arguments: LspArguments {argLSP = True, argsCwd = Nothing, argFiles = [], argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsDebugOn = True, argsLogFile = Just "/home/rizary/hls.log", argsThreads = 0, argsProjectGhcVersion = False}
  with plugins: [PluginId "brittany",PluginId "eval",PluginId "floskell",PluginId "fourmolu",PluginId "ghcide",PluginId "hlint",PluginId "importLens",PluginId "moduleName",PluginId "ormolu",PluginId "pragmas",PluginId "retrie",PluginId "stylish-haskell",PluginId "tactic"]
  in directory: /home/rizary/rizichain
If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option!
 Started LSP server in 0.01s

@jneira
Copy link
Member

jneira commented Mar 9, 2021

The state-of-the-art in nix usage of the haskell-language-server is in this issue: haskell/haskell-language-server#122

@jneira jneira closed this as completed Mar 9, 2021
@uhbif19
Copy link

uhbif19 commented Mar 10, 2023

@jneira The issue you mentioned seems to be about HLS installation, while this issue is about integration of HLS from Nix shell into VS Code.

@fendor
Copy link
Collaborator

fendor commented Mar 10, 2023

If you want to use this extension with nix, choose to manage your HLS installation manually by setting "haskell.manageHLS": "PATH", and make sure an appropriate HLS-wrapper or HLS installation is found on the PATH.

@uhbif19
Copy link

uhbif19 commented Mar 12, 2023

@fendor

Yes this is the hack I use.

I know three options:

  1. Set HLS path as Nix version globally. This wont work if you have multiple projects. (see also: https://plutus.readthedocs.io/en/latest/troubleshooting.html#wrong-version)
    1a. Improve to use parameterized path ${workspaceFolder}/scripts/run-hls.sh
  2. Start VS Code from Nix shell. That works but breaks functionality of restarting VS Code projects on start.
  3. Use VS Code direnv plugin. This should work (while I not checked yet), but, as I read, this may be not-stable due to VS Code does not support load order for extensions.

I see two options to improve this situation:

  1. Support by Haskell plugin autoload of project environments: direnv and/or Nix shell.
  2. Support project-wide (not global like now) HLS path

@fendor
Copy link
Collaborator

fendor commented Mar 12, 2023

  1. Support project-wide (not global like now) HLS path

This is a VSCode feature, create in your project root .vscode/settings.json and specify

{
  "haskell.serverExecutablePath": "<hls-binary>"
}

@hasufell
Copy link
Member

Support by Haskell plugin autoload of project environments: direnv and/or Nix shell.

Hard no for any code support specific to nix.

PATH is generic enough.

@uhbif19
Copy link

uhbif19 commented Mar 12, 2023

This is a VSCode feature, create in your project root .vscode/settings.json and specify

You right, this seems to be working. Would you consider adding this way into README?

@fendor
Copy link
Collaborator

fendor commented Mar 12, 2023

Suure, but I am also open to contributors to add the documentation they would like to see 😇

@mardukbp
Copy link

I struggled with this problem for several hours, until I realized that one can control the temporal order of the dependencies. The Haskell extension is loaded when the first .hs file is opened. In order for the extension to find the executables in the Nix environment (haskell-language-server-wrapper, ghc, cabal, etc.), the $PATH must already contain the paths to the Nix store. The $PATH is set when the Nix Environment Selector extension loads. Therefore, when opening a Workspace wait until this extension finishes loading and then open a .hs file. Hope this saves somebody time.

For the sake of reproducibility, here is a minimal default.nix file:

{pkgs ? import <nixpkgs> {}}: with pkgs;
let
  myHaskell = haskellPackages.ghcWithPackages myHaskellPackages;
  myHaskellPackages = packages: with packages; [
    haskell-language-server
    # put haskell packages here
  ];
in
mkShell {
  buildInputs = [
    myHaskell
    cabal-install
    ghcid
    # put any other binaries we need here
  ];
}

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