digitallyinduced / ihp

🔥 The fastest way to build type safe web apps. IHP is a new batteries-included web framework optimized for longterm productivity and programmer happiness
https://ihp.digitallyinduced.com/
MIT License
4.92k stars 195 forks source link

HLS not working in vscode #1656

Closed Vic-M closed 1 year ago

Vic-M commented 1 year ago

I'm running vscode and trying to get HLS working with a basic ihp-new install. My setup is a windows host connecting through vscode's remote ssh extension into a CentOS 9 VM.

I'm following https://ihp.digitallyinduced.com/Guide/editors.html#using-ihp-with-visual-studio-code-vscode and I've set the nix-env environement in vscode's settings.json:

{
    "nixEnvSelector.nixFile": "${workspaceRoot}/default.nix",
    "haskell.manageHLS": "PATH",
}

However, when running HLS, I get:

2023-04-28 19:32:49.6110000 [client] INFO Finding haskell-language-server
2023-04-28 19:32:49.6110000 [client] INFO Searching for server executables haskell-language-server-wrapper,haskell-language-server in $PATH
2023-04-28 19:32:49.6110000 [client] INFO $PATH environment variable: /home/basic/.vscode-server/bin/704ed70d4fd1c6bd6342c436f1ede30d1cff4710/bin/remote-cli:/home/basic/.local/bin:/home/basic/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
2023-04-28 19:33:12.1150000 [client] ERROR Error: Project requires HLS but it isn't installed
    at /home/basic/.vscode-server/extensions/haskell.haskell-2.2.4/dist/extension.js:1:274838
    at Generator.next (<anonymous>)
    at /home/basic/.vscode-server/extensions/haskell.haskell-2.2.4/dist/extension.js:1:272698
    at new Promise (<anonymous>)
    at r (/home/basic/.vscode-server/extensions/haskell.haskell-2.2.4/dist/extension.js:1:272443)
    at g (/home/basic/.vscode-server/extensions/haskell.haskell-2.2.4/dist/extension.js:1:274499)
    at /home/basic/.vscode-server/extensions/haskell.haskell-2.2.4/dist/extension.js:1:279482
    at Generator.next (<anonymous>)
    at s (/home/basic/.vscode-server/extensions/haskell.haskell-2.2.4/dist/extension.js:1:272500)

If I manually set the HLS path with "haskell.serverExecutablePath": "/nix/store/232vdhix5bj14zgayv0i7ijhxg0b7j5h-ghc-9.2.4-with-packages/bin/haskell-language-server", I instead get:

2023-04-28 19:34:47.3040000 [client] INFO Finding haskell-language-server
2023-04-28 19:34:47.3040000 [client] INFO Trying to find the server executable in: /nix/store/232vdhix5bj14zgayv0i7ijhxg0b7j5h-ghc-9.2.4-with-packages/bin/haskell-language-server
2023-04-28 19:34:47.3110000 [client] INFO Activating the language server in working dir: /home/basic/project (the workspace folder)
2023-04-28 19:34:47.3110000 [client] INFO run command: /nix/store/232vdhix5bj14zgayv0i7ijhxg0b7j5h-ghc-9.2.4-with-packages/bin/haskell-language-server --lsp
2023-04-28 19:34:47.3110000 [client] INFO debug command: /nix/store/232vdhix5bj14zgayv0i7ijhxg0b7j5h-ghc-9.2.4-with-packages/bin/haskell-language-server --lsp
2023-04-28 19:34:47.3110000 [client] INFO server environment variables:
2023-04-28 19:34:47.3160000 [client] INFO Starting language server
2023-04-28T19:34:47.712065Z | Info | No log file specified; using stderr.
2023-04-28T19:34:47.713192Z | Info | haskell-language-server version: 1.7.0.0 (GHC: 9.2.4) (PATH: /nix/store/7bqnwlml2hmrcahqs314mvmf0k9n0q3b-haskell-language-server-1.7.0.0/bin/haskell-language-server)
2023-04-28T19:34:47.716077Z | Info | Directory: /home/basic/project
2023-04-28T19:34:47.716433Z | Info | Starting (haskell-language-server) LSP server...
  GhcideArguments {argsCommand = LSP, argsCwd = Nothing, argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsDebugOn = False, argsLogFile = Nothing, argsThreads = 0, argsProjectGhcVersion = False}
  PluginIds: [ pragmas
             , floskell
             , fourmolu
             , ormolu
             , rename
             , callHierarchy
             , eval
             , importLens
             , qualifyImportedNames
             , refineImports
             , moduleName
             , alternateNumberFormat
             , selectionRange
             , changeTypeSignature
             , ghcide-hover-and-symbols
             , ghcide-code-actions-imports-exports
             , ghcide-code-actions-type-signatures
             , ghcide-code-actions-bindings
             , ghcide-code-actions-fill-holes
             , ghcide-completions
             , ghcide-type-lenses
             , ghcide-core
             , LSPRecorderCallback ]
2023-04-28T19:34:47.735234Z | Info | Logging heap statistics every 60.00s
 2023-04-28T19:34:47.738205Z | Info | Staring LSP server...
If you are seeing this in a terminal, you probably should have run WITHOUT the --lsp option!
2023-04-28T19:34:47.740545Z | Info | Started LSP server in 0.00s
2023-04-28T19:34:47.744503Z | Error | Couldn't load cradle for ghc libdir.
  Cradle error: CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitSuccess, cradleErrorStderr = ["Couldn't execute ghc --print-libdir"]}
  Root dir path: /home/basic/project
  hie.yaml path: 
  Cradle: Cradle {cradleRootDir = "/home/basic/project", cradleOptsProg = CradleAction: Default}
2023-04-28T19:34:47.746817Z | Info | Registering IDE configuration: IdeConfiguration {workspaceFolders = fromList [NormalizedUri 6536433535877180724 "file:///home/basic/project"], clientSettings = hashed Nothing}
2023-04-28T19:34:47.767132Z | Info | Cradle path: Web/FrontController.hs
[Info  - 3:34:47 p.m.] haskell-language-server version: 1.7.0.0 (GHC: 9.2.4) (PATH: /nix/store/7bqnwlml2hmrcahqs314mvmf0k9n0q3b-haskell-language-server-1.7.0.0/bin/haskell-language-server)
[Info  - 3:34:47 p.m.] Directory: /home/basic/project
[Info  - 3:34:47 p.m.] Starting (haskell-language-server) LSP server...
  GhcideArguments {argsCommand = LSP, argsCwd = Nothing, argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsDebugOn = False, argsLogFile = Nothing, argsThreads = 0, argsProjectGhcVersion = False}
  PluginIds: [ pragmas
             , floskell
             , fourmolu
             , ormolu
             , rename
             , callHierarchy
             , eval
             , importLens
             , qualifyImportedNames
             , refineImports
             , moduleName
             , alternateNumberFormat
             , selectionRange
             , changeTypeSignature
             , ghcide-hover-and-symbols
             , ghcide-code-actions-imports-exports
             , ghcide-code-actions-type-signatures
             , ghcide-code-actions-bindings
             , ghcide-code-actions-fill-holes
             , ghcide-completions
             , ghcide-type-lenses
             , ghcide-core
             , LSPRecorderCallback ]
[Info  - 3:34:47 p.m.] Logging heap statistics every 60.00s
[Info  - 3:34:47 p.m.] Staring LSP server...
If you are seeing this in a terminal, you probably should have run WITHOUT the --lsp option!
[Info  - 3:34:47 p.m.] Started LSP server in 0.00s
[Error - 3:34:47 p.m.] Couldn't load cradle for ghc libdir.
  Cradle error: CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitSuccess, cradleErrorStderr = ["Couldn't execute ghc --print-libdir"]}
  Root dir path: /home/basic/project
  hie.yaml path: 
  Cradle: Cradle {cradleRootDir = "/home/basic/project", cradleOptsProg = CradleAction: Default}
[Info  - 3:34:47 p.m.] Registering IDE configuration: IdeConfiguration {workspaceFolders = fromList [NormalizedUri 6536433535877180724 "file:///home/basic/project"], clientSettings = hashed Nothing}
[Info  - 3:34:47 p.m.] Cradle path: Web/FrontController.hs

Is there some dependency I'm missing that ihp-new doesn't install?

Vic-M commented 1 year ago

Turns out it was the nix-env-selector extension not working properly, switching to direnv fixed the issue with:

{
    "haskell.manageHLS": "PATH",
    "direnv.path.executable": "/home/basic/.nix-profile/bin/direnv"
}
mpscholten commented 1 year ago

Thanks for sharing the solution 👍 Maybe we should consider switching from nix-env-selector to direnv as the suggested approach in our documentation

amitaibu commented 1 year ago

@Vic-M can you please give more info on how you solved it?

Here are the steps I've done:

  1. Disabled the Nix environment selector in VS code
  2. Installed https://marketplace.visualstudio.com/items?itemName=mkhl.direnv
  3. which direnv and copy directory
  4. In VScode Ctrl + P, and type `>Preferences: Open user settings (JSON)
  5. Add the code in https://github.com/digitallyinduced/ihp/issues/1656#issuecomment-1528648554 and add the correct path under direnv.path.executable
  6. Reload VScode

But on load I still see

image

amitaibu commented 1 year ago

I've removed some weirdness on my computer, and it seems to work for me now. So not sure, if it's the above steps, or that software that blocked stuff for me.