obsidiansystems / obelisk

Functional reactive web and mobile applications, with batteries included.
https://reflex-frp.org
BSD 3-Clause "New" or "Revised" License
949 stars 104 forks source link

Minimal setup for `obelisk` + `haskell-language-server` + VS Code #1024

Open benrbray opened 1 year ago

benrbray commented 1 year ago

I want to try out reflex/obelisk but I have no experience with Nix so I'm finding it quite difficult to get started.

I installed obelisk with:

nix-env -f https://github.com/obsidiansystems/obelisk/archive/master.tar.gz -iA command

I'm starting from the basic starter project,

mkdir learn-obsidian && cd learn-obsidian
ob init

I can successfully build and run the project with ob run, and ob shell drops me into a nix shell. Here's some version info:

$ nix --version
nix (Nix) 2.14.1
$ ob shell
./.obelisk/impl: command not cached, building ...
DONE Built on ./.obelisk/impl [command]
warning: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I), at (string):1:9; will use bash from your environment
(executing .bashrc)

[nix-shell:~/projects/haskell/learn-obelisk]$ cabal --version
cabal-install version 3.2.0.0
compiled using version 3.2.0.0 of the Cabal library 

[nix-shell:~/projects/haskell/learn-obelisk]$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.6.5

[nix-shell:~/projects/haskell/learn-obelisk]$ which cabal
/nix/store/3zzh2sf9h465c9vhy6m1i4w0h3dk0zln-build-tools-wrapper/bin/cabal

[nix-shell:~/projects/haskell/learn-obelisk]$ which ghc
/nix/store/3c5sjqxzwfvix55cf2x3pwndkalj47dk-ghc-8.6.5-with-packages/bin/ghc

Attempt 1: code inside ob shell

First, I tried:

$ ob shell
./.obelisk/impl: command not cached, building ...
DONE Built on ./.obelisk/impl [command]
warning: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I), at (string):1:9; will use bash from your environment
(executing .bashrc)

[nix-shell:~/projects/haskell/learn-obelisk]$ code .

However, none of the project dependencies are recognized by HLS. For example, visiting frontend/src/Frontend.hs,

image

Attempt 2: Modify default.nix, Manually Compile haskell-language-server

I tried a few of the answers at obsidiansystems/obelisk#986, but since I am new to Nix there is not quite enough information there for me to reproduce them myself. My attempts to modify default.nix caused some strange errors. I was able to compile a recent version of haskell-language-server using the cabal found in the nix shell, but the executable was installed to ~/.cabal/bin rather than somewhere within Nix like I would expect. Opening code gives the same errors.

Questions

Thanks!

rubenmoor commented 1 year ago

https://discourse.haskell.org/t/haskell-language-server-ghc-version-could-not-be-determined/5856/10?u=rubenmoor

Here, I got obelisk to work with haskell-language-server and emacs.

I run nix-shell -A shells.ghc and start emacs from within the shell. I assume the same is possible with vscode.

o1lo01ol1o commented 1 year ago

FWIW, we have a template project for obelisk and rhyolite projects running under GHC8107 with HLS here: https://github.com/BeFunctional/obelisk-rhyolite-template

IIRC Macs are still out of luck with those branches, but, if you're only linux, ob shell and code . should get you hls. If you're using the remote development, you can use a .envrc with direnv to load the PATH set by ob shell before HLS starts.

uzytkownik commented 1 year ago

@o1lo01ol1o I tried to use it but it installs HLS 1.1.0.0. Any idea how to fix it?

When I try to use nix-shell I get error:

Arguments: ["--lsp","-d","-l","/var/tmp/hls.log"]                                                                                                                                                                   
Cradle directory: ...                                                                                                                                                        
Cradle type: Cabal                                                                                                                                                                                                  

Tool versions found on the $PATH                                                                                                                                                                                    
cabal:          3.4.1.0                                                                                                                                                                                             
stack:          2.9.1                                                                                                                                                                                               
ghc:            8.10.7                                                                                                                                                                                              

Consulting the cradle to get project GHC version...                                                                                                                                                                 
2023-06-29T08:01:03.951242Z | Debug | executing command: cabal exec -v0 -- ghc --print-libdir                                                                                                                       
Failed to find the GHC version of this Cabal project.                                                                                                                                                               
Error when calling cabal exec -v0 -- ghc --print-libdir                                                                                                                                                             

cabal: Could not resolve dependencies:                                                                                                                                                                              
[__0] trying: backend-0.1 (user goal)                                                                                                                                                                               
[__1] unknown package: obelisk-route (dependency of backend)                                                                                                                                                        
[__1] fail (backjumping, conflict set: backend, obelisk-route)                                                                                                                                                      
After searching the rest of the dependency tree exhaustively, these were the                                                                                                                                        
goals I've had most trouble fulfilling: backend, obelisk-route                                                                                                                                                      

 2023-06-29T08:01:05.891538Z | Info | Starting server                                                                                                                                                               
2023-06-29T08                                                                                                                                                                                                       
Process lsp-haskell stderr finished