Skip to content

Commit 771d8f4

Browse files
author
Kobayashi
authored
unify pre-commit hook & update Gitpod config (#2991)
* update Gitpod config * update nix shellHook & docs * install pre-commit hook * add kokobd as code owner to .gitpod.* * add gen-hie to Gitpod * add tools for doc * remove .pre-commit-config.yaml from .gitignore * set vscode formatter to stylish-haskell in Gitpod
1 parent 0b8c793 commit 771d8f4

File tree

7 files changed

+76
-167
lines changed

7 files changed

+76
-167
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ test/testdata/**/hie.yaml
3030
# shake build folder (used in benchmark suite)
3131
.shake/
3232

33-
# pre-commit-hook.nix
34-
.pre-commit-config.yaml
35-
3633
# direnv
3734
/.direnv/
3835
/.envrc

.gitpod.Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM gitpod/workspace-full
2+
3+
RUN sudo install-packages build-essential curl libffi-dev libffi7 libgmp-dev libgmp10 \
4+
libncurses-dev libncurses5 libtinfo5 && \
5+
BOOTSTRAP_HASKELL_NONINTERACTIVE=1 \
6+
BOOTSTRAP_HASKELL_MINIMAL=1 \
7+
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh && \
8+
echo 'source $HOME/.ghcup/env' >> $HOME/.bashrc && \
9+
echo 'export PATH=$HOME/.cabal/bin:$HOME/.local/bin:$PATH' >> $HOME/.bashrc && \
10+
. /home/gitpod/.ghcup/env && \
11+
ghcup install ghc --set && \
12+
ghcup install hls --set && \
13+
ghcup install cabal --set && \
14+
ghcup install stack --set && \
15+
cabal update && \
16+
cabal install stylish-haskell hoogle implicit-hie && \
17+
pip install pre-commit && \
18+
npm install -g http-server

.gitpod.yml

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,54 @@
1+
image:
2+
file: .gitpod.Dockerfile
13
# List the start up tasks. Learn more https://www.gitpod.io/docs/config-start-tasks/
24
tasks:
3-
- before: |
4-
# Only the /workspace folder is persistent
5-
export XDG_DATA_HOME=/workspace/.local/share
6-
export XDG_CONFIG_HOME=/workspace/.local/config
7-
export XDG_STATE_HOME=/workspace/.local/state
8-
export XDG_CACHE_HOME=/workspace/.cache
9-
export CABAL_DIR=/workspace/.cabal
10-
export STACK_ROOT=/workspace/.stack
5+
- name: Setup
6+
before: |
7+
# Make sure some folders not in /workspace persist between worksapce restarts.
8+
# You may add additional directories to this list.
9+
declare -a CACHE_DIRS=(
10+
$HOME/.local
11+
$HOME/.cabal
12+
$HOME/.stack
13+
$HOME/.ghcup
14+
/nix
15+
)
16+
for DIR in "${CACHE_DIRS[@]}"; do
17+
mkdir -p $(dirname /workspace/cache$DIR)
18+
mkdir -p $DIR # in case $DIR doesn't already exist
19+
# On a fresh start with no prebuilds, we move existing directory
20+
# to /workspace. 'sudo mv' fails with 'no permission', I don't know why
21+
if [ ! -d /workspace/cache$DIR ]; then
22+
sudo cp -rp $DIR /workspace/cache$DIR
23+
sudo rm -rf $DIR/*
24+
fi
25+
mkdir -p /workspace/cache$DIR # make sure it exists even if cp fails
26+
# Now /workspace/cache$DIR exists.
27+
# Use bind mount to make $DIR backed by /workspace/cache$DIR
28+
sudo mount --bind /workspace/cache$DIR $DIR
29+
done
1130
12-
# install ghcup, ghc and cabal
13-
export GHCUP_INSTALL_BASE_PREFIX=/workspace
14-
export BOOTSTRAP_HASKELL_NONINTERACTIVE=1
15-
export BOOTSTRAP_HASKELL_MINIMAL=1
16-
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
17-
/workspace/.ghcup/bin/ghcup install ghc --set
18-
/workspace/.ghcup/bin/ghcup install cabal
19-
20-
# Add ghcup binaries to the PATH since VSCode does not see 'source .ghcup/env'
21-
pushd /usr/local/bin
22-
sudo ln -s /workspace/.ghcup/bin/* /usr/local/bin
23-
popd
24-
25-
# Fix the Cabal dir since VSCode does not see CABAL_DIR
26-
cabal update
27-
echo "Symlinking /workspace/.cabal to ~/.cabal"
28-
ln -s /workspace/.cabal ~
31+
# Install pre-commit hook
32+
pre-commit install
2933
3034
# Configure VSCode to use the locally built version of HLS
3135
mkdir -p .vscode
32-
echo '{ "haskell.serverExecutablePath": "/workspace/.cabal/bin/haskell-language-server" }' > .vscode/settings.json
36+
if [ ! -f .vscode/settings.json ]; then
37+
# Only write to .vscode/settings.json if it doesn't exist.
38+
echo '{' > .vscode/settings.json
39+
echo ' "haskell.serverExecutablePath": "/home/gitpod/.cabal/bin/haskell-language-server",' >> .vscode/settings.json
40+
echo ' "haskell.formattingProvider": "stylish-haskell"' >> .vscode/settings.json
41+
echo '}' >> .vscode/settings.json
42+
fi
3343
34-
init: |
44+
pushd docs
45+
pip install -r requirements.txt
46+
popd
47+
init: |
48+
cabal update
3549
cabal configure --enable-executable-dynamic
36-
cabal build --enable-tests
37-
cabal install exe:haskell-language-server
38-
command: |
39-
cabal build --enable-tests
50+
cabal build --enable-tests all
51+
cabal install exe:haskell-language-server
4052
4153
# List the ports to expose. Learn more https://www.gitpod.io/docs/config-ports/
4254
ports: []
@@ -62,4 +74,4 @@ vscode:
6274
extensions:
6375
- "haskell.haskell"
6476
- "justusadam.language-haskell"
65-
- "usernamehw.errorlens"
77+
- "EditorConfig.EditorConfig"

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@
4444
# Build
4545
*.nix @berberman @michaelpj @guibou
4646
*.project @jneira
47+
.gitpod.* @kokobd

docs/contributing/contributing.md

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -170,49 +170,13 @@ Please, try to follow those basic settings to keep the codebase as uniform as po
170170

171171
### Formatter pre-commit hook
172172

173-
We are using [pre-commit-hook.nix](https://github.com/cachix/pre-commit-hooks.nix) to configure git pre-commit hook for formatting. Although it is possible to run formatting manually, we recommend you to use it to set pre-commit hook as our CI checks pre-commit hook is applied or not.
173+
We are using [pre-commit](https://pre-commit.com/) to configure git pre-commit hook for formatting. Although it is possible to run formatting manually, we recommend you to use it to set pre-commit hook as our CI checks pre-commit hook is applied or not.
174174

175-
You can configure the pre-commit-hook by running
175+
If you are using Nix or Gitpod, pre-commit hook is automatically installed. Otherwise, follow instructions on
176+
[https://pre-commit.com/](https://pre-commit.com/) to install the `pre-commit` tool, then run the following command:
176177

177-
``` bash
178-
nix-shell
179-
```
180-
181-
If you don't want to use [nix](https://nixos.org/guides/install-nix.html), you can instead use [pre-commit](https://pre-commit.com) with the following config.
182-
183-
```json
184-
{
185-
"repos": [
186-
{
187-
"hooks": [
188-
{
189-
"entry": "stylish-haskell --inplace",
190-
"exclude": "(^Setup.hs$|test/testdata/.*$|test/data/.*$|test/manual/lhs/.*$|^hie-compat/.*$|^plugins/hls-tactics-plugin/.*$|^ghcide/src/Development/IDE/GHC/Compat.hs$|^ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs$|^ghcide/src/Development/IDE/GHC/Compat/Core.hs$|^ghcide/src/Development/IDE/Spans/Pragmas.hs$|^ghcide/src/Development/IDE/LSP/Outline.hs$|^plugins/hls-splice-plugin/src/Ide/Plugin/Splice.hs$|^ghcide/test/exe/Main.hs$|ghcide/src/Development/IDE/Core/Rules.hs|^hls-test-utils/src/Test/Hls/Util.hs$)",
191-
"files": "\\.l?hs$",
192-
"id": "stylish-haskell",
193-
"language": "system",
194-
"name": "stylish-haskell",
195-
"pass_filenames": true,
196-
"types": [
197-
"file"
198-
]
199-
}
200-
],
201-
"repo": "local"
202-
},
203-
{
204-
"repo": "https://github.com/pre-commit/pre-commit-hooks",
205-
"rev": "v4.1.0",
206-
"hooks": [
207-
{
208-
"id": "mixed-line-ending",
209-
"args": ["--fix", "lf"],
210-
"exclude": "test/testdata/.*CRLF*.hs$"
211-
}
212-
]
213-
}
214-
]
215-
}
178+
```sh
179+
pre-commit install
216180
```
217181

218182
#### Why some components are excluded from automatic formatting?

flake.lock

Lines changed: 0 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
flake = false;
1515
};
1616
flake-utils.url = "github:numtide/flake-utils";
17-
pre-commit-hooks = {
18-
url = "github:cachix/pre-commit-hooks.nix";
19-
};
2017
gitignore = {
2118
url = "github:hercules-ci/gitignore.nix";
2219
flake = false;
@@ -92,7 +89,7 @@
9289
flake = false;
9390
};
9491
myst-parser = {
95-
url = "github:smunix/MyST-Parser?ref=fix.hls-docutils";
92+
url = "github:smunix/MyST-Parser?ref=fix.hls-docutils";
9693
flake = false;
9794
};
9895
# For https://github.com/readthedocs/sphinx_rtd_theme/pull/1185, otherwise lists are broken locally
@@ -103,7 +100,7 @@
103100
poetry2nix.url = "github:nix-community/poetry2nix/master";
104101
};
105102
outputs =
106-
inputs@{ self, nixpkgs, flake-compat, flake-utils, pre-commit-hooks, gitignore, ... }:
103+
inputs@{ self, nixpkgs, flake-compat, flake-utils, gitignore, ... }:
107104
{
108105
overlays.default = final: prev:
109106
with prev;
@@ -123,7 +120,7 @@
123120
in hsuper.mkDerivation (args // {
124121
jailbreak = if broken then true else jailbreak;
125122
doCheck = if broken then false else check;
126-
# Library profiling is disabled as it causes long compilation time
123+
# Library profiling is disabled as it causes long compilation time
127124
# on our CI jobs. Nix users are free tor revert this anytime.
128125
enableLibraryProfiling = false;
129126
doHaddock = false;
@@ -215,42 +212,11 @@
215212
config = { allowBroken = true; };
216213
};
217214

218-
# Pre-commit hooks to run stylish-haskell
219-
pre-commit-check = hpkgs: pre-commit-hooks.lib.${system}.run {
220-
src = ./.;
221-
hooks = {
222-
stylish-haskell.enable = true;
223-
# use stylish-haskell with our target ghc
224-
stylish-haskell.entry = pkgs.lib.mkForce "${hpkgs.stylish-haskell}/bin/stylish-haskell --inplace";
225-
stylish-haskell.excludes = [
226-
# Ignored files
227-
"^Setup.hs$"
228-
"test/testdata/.*$"
229-
"test/data/.*$"
230-
"test/manual/lhs/.*$"
231-
"^hie-compat/.*$"
232-
"^plugins/hls-tactics-plugin/.*$"
233-
234-
# Temporarily ignored files
235-
# Stylish-haskell (and other formatters) does not work well with some CPP usages in these files
236-
"^ghcide/src/Development/IDE/GHC/Compat.hs$"
237-
"^ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs$"
238-
"^ghcide/src/Development/IDE/GHC/Compat/Core.hs$"
239-
"^ghcide/src/Development/IDE/Spans/Pragmas.hs$"
240-
"^ghcide/src/Development/IDE/LSP/Outline.hs$"
241-
"^plugins/hls-splice-plugin/src/Ide/Plugin/Splice.hs$"
242-
"^ghcide/test/exe/Main.hs$"
243-
"ghcide/src/Development/IDE/Core/Rules.hs"
244-
"^hls-test-utils/src/Test/Hls/Util.hs$"
245-
];
246-
};
247-
};
248-
249215
ghc902Config = (import ./configuration-ghc-90.nix) { inherit pkgs inputs; };
250216
ghc922Config = (import ./configuration-ghc-92.nix) { inherit pkgs inputs; };
251217

252218
# GHC versions
253-
# While HLS still works fine with 8.10 GHCs, we only support the versions that are cached
219+
# While HLS still works fine with 8.10 GHCs, we only support the versions that are cached
254220
# by upstream nixpkgs, which now only includes GHC version 9+
255221
supportedGHCs = let
256222
ghcVersion = "ghc" + (pkgs.lib.replaceStrings ["."] [""] pkgs.haskellPackages.ghc.version);
@@ -268,14 +234,14 @@
268234
myst-parser = pkgs.poetry2nix.mkPoetryEnv {
269235
projectDir = inputs.myst-parser;
270236
python = pkgs.python39;
271-
overrides = [
237+
overrides = [
272238
pkgs.poetry2nix.defaultPoetryOverrides
273239
];
274240
};
275241
sphinx_rtd_theme = pkgs.poetry2nix.mkPoetryEnv {
276242
projectDir = inputs.sphinx_rtd_theme;
277243
python = pkgs.python39;
278-
overrides = [
244+
overrides = [
279245
pkgs.poetry2nix.defaultPoetryOverrides
280246
(self: super: {
281247
# The RTD theme doesn't work with newer docutils
@@ -334,8 +300,8 @@
334300
export DYLD_LIBRARY_PATH=${gmp}/lib:${zlib}/lib:${ncurses}/lib:${capstone}/lib
335301
export PATH=$PATH:$HOME/.local/bin
336302
337-
# Enable the shell hooks
338-
${self.checks.${system}.pre-commit-check.shellHook}
303+
# Install pre-commit hook
304+
pre-commit install
339305
340306
# If the cabal project file is not the default one.
341307
# Print a warning and generate an alias.

0 commit comments

Comments
 (0)