Editors & Tooling
- Introduction
- Using IHP with Visual Studio Code / VSCode
- Using IHP with Sublime Text
- Using IHP with Emacs
- Using IHP with Vim / NeoVim
- Haskell Language Server
- IHP Dev Server
Introduction
This place describes all the steps needed to get your code editors and other tooling working with IHP. When your favorite code editor is not described here, feel free to add your setup to this list.
You will also find steps on how to get autocompletion and smart IDE features. This is provided by haskell-language-server. IHP already comes with a bundled haskell-language-server, so you don’t need to install it manually.
Using IHP with Visual Studio Code / VSCode
Install the following extensions:
-
nix-env-selector
, this loads the projectdefault.nix
file, so all the right Haskell packages are available to VSCode -
Haskell
, this gets smart IDE features with haskell-language-server -
Haskell HSX
, provides support for HSX
To make file paths clickable inside the web browser (e.g. when a type error happens), export this env var in your shell (e.g. in .bashrc
):
export IHP_EDITOR="code --goto"
VSCode + Haskell Language Server Troubleshooting
“Couldn’t figure out what GHC version the project is using”
If you get an error Couldn't figure out what GHC version the project is using
in Visual Studio Code make sure that the Nix Env Selector plugin was started correctly:
- Open the project in VS Code
-
Click
View
->Command Palette
->Nix-Env: Select Environment
->default.nix
- This will restart VS Code. After that Haskell Language Server should be working.
VSCode on Windows with Windows Subsystem for Linux
It is important to not access the files within the WSL from Windows itself (however, the other way around is ok). You can seamlessly (including auto-save) work on your projects within WSL from VS Code in Windows by adding the Remote WSL
extension from Microsoft.
Using IHP with Sublime Text
Works great already out of the box.
Recommended packages:
-
Nix
for syntax highlighting of nix files -
Haskell HSX
for syntax highlighting of Haskell with HSX -
Direnv
to load the.envrc
file of the project. -
LSP
for smart IDE features. UseLSP: Enable Language Server in Project -> Haskell Language Server
to activate. In you don’t have that option in the menu, selectOpen Preferences > Package Settings > LSP > Settings
and add the"haskell-language-server"
client configuration to the"clients"
:{ "clients": { "haskell-language-server": { "enabled": true, "command": ["haskell-language-server-wrapper", "--lsp"], "selector": "source.haskell" } } }
To make file paths clickable inside the web browser (e.g. when a type error happens), export this env var in your shell (e.g. in .bashrc
):
export IHP_EDITOR="sublime"
Using IHP with Emacs
Install the following packages from Melpa:
-
dante
– gives IDE features via ghci, see https://github.com/jyp/dante#installation -
direnv-mode
– lets haskell-mode and dante-mode find the PATH to ghci, see https://github.com/wbolster/emacs-direnv#installation -
attrap
(optional) – apply fixes at point, see https://github.com/jyp/attrap
and put a .dir-locals.el
file in your project root with:
((nil
(dante-repl-command-line . ("ghci"))
(haskell-process-type . ghci)))
Using IHP with Vim / NeoVim
Using CoC
Provided you already have CoC setup, just run :CocConfig
and add the following segment.
{
"languageserver": {
"haskell": {
"command": "haskell-language-server-wrapper",
"args": ["--lsp"],
"rootPatterns": [
"*.cabal",
"stack.yaml",
"cabal.project",
"package.yaml",
"hie.yaml"
],
"filetypes": ["haskell", "lhaskell"]
}
}
}
Haskell Language Server
Because haskell-language-server is tightly coupled to the GHC version it comes pre-bundled with IHP. In case you also have a local install of haskell-language-server you need to make sure that the one provided by IHP is used. Usually, this is done automatically when your editor is picking up the .envrc
file.
When something goes wrong you can also run haskell-language-server
inside the project directory (within a nix-shell
). This might output some helpful error messages.
IHP Dev Server
Customizing the Web Browser used by IHP
When running ./start
the application will automatically be opened in your default browser. You can manually specificy a browser by setting the env var IHP_BROWSER
:
export IHP_BROWSER=firefox
You can disable the auto-start of the browser completely using echo
as your browser:
export IHP_BROWSER=echo
Running the IHP Dev Server On a Host Different From localhost
If you run the IHP dev server on computer different from your local machine (e.g. a second computer in your network or a Cloud Dev Env like GitPod), you need to specify the right base url:
export IHP_BASEURL=http://some-other-host:8000 # App Url, Default: http://localhost:8000
export IHP_IDE_BASEURL=http://some-other-host:8001 # SchemaDesigner etc., Default: http://localhost:8001
Next time you use the dev server via ./start
all links will use the right IHP_BASEURL
instead of using localhost:8000
;
Hoogle
To quickly look up function type signatures you can use the built-in hoogle server.
To install it:
-
Open
default.nix
-
Add
withHoogle = true;
to thehaskellEnv
block, like this:
let
ihp = builtins.fetchGit {
url = "https://github.com/digitallyinduced/ihp.git";
ref = "refs/tags/v0.14.0";
};
haskellEnv = import "${ihp}/NixSupport/default.nix" {
ihp = ihp;
haskellDeps = p: with p; [
cabal-install
base
wai
text
hlint
p.ihp
];
otherDeps = p: with p; [
# Native dependencies, e.g. imagemagick
];
projectPath = ./.;
withHoogle = true; # <-------
};
in
haskellEnv
Run nix-shell --run 'make -B .envrc'
to remake your dev env.
After that you can use the following command to start hoogle at localhost:8080
:
hoogle server --local -p 8080