Skip to content

unify pre-commit hook & update Gitpod config #2991

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

Merged
merged 8 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ test/testdata/**/hie.yaml
# shake build folder (used in benchmark suite)
.shake/

# pre-commit-hook.nix
.pre-commit-config.yaml

# direnv
/.direnv/
/.envrc
Expand Down
18 changes: 18 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM gitpod/workspace-full

RUN sudo install-packages build-essential curl libffi-dev libffi7 libgmp-dev libgmp10 \
libncurses-dev libncurses5 libtinfo5 && \
BOOTSTRAP_HASKELL_NONINTERACTIVE=1 \
BOOTSTRAP_HASKELL_MINIMAL=1 \
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh && \
echo 'source $HOME/.ghcup/env' >> $HOME/.bashrc && \
echo 'export PATH=$HOME/.cabal/bin:$HOME/.local/bin:$PATH' >> $HOME/.bashrc && \
. /home/gitpod/.ghcup/env && \
ghcup install ghc --set && \
ghcup install hls --set && \
ghcup install cabal --set && \
ghcup install stack --set && \
cabal update && \
cabal install stylish-haskell hoogle implicit-hie && \
pip install pre-commit && \
npm install -g http-server
73 changes: 41 additions & 32 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,51 @@
image:
file: .gitpod.Dockerfile
# List the start up tasks. Learn more https://www.gitpod.io/docs/config-start-tasks/
tasks:
- before: |
# Only the /workspace folder is persistent
export XDG_DATA_HOME=/workspace/.local/share
export XDG_CONFIG_HOME=/workspace/.local/config
export XDG_STATE_HOME=/workspace/.local/state
export XDG_CACHE_HOME=/workspace/.cache
export CABAL_DIR=/workspace/.cabal
export STACK_ROOT=/workspace/.stack
- name: Setup
before: |
# Make sure some folders not in /workspace persist between worksapce restarts.
# You may add additional directories to this list.
declare -a CACHE_DIRS=(
$HOME/.local
$HOME/.cabal
$HOME/.stack
$HOME/.ghcup
/nix
)
for DIR in "${CACHE_DIRS[@]}"; do
mkdir -p $(dirname /workspace/cache$DIR)
mkdir -p $DIR # in case $DIR doesn't already exist
# On a fresh start with no prebuilds, we move existing directory
# to /workspace. 'sudo mv' fails with 'no permission', I don't know why
if [ ! -d /workspace/cache$DIR ]; then
sudo cp -rp $DIR /workspace/cache$DIR
sudo rm -rf $DIR/*
fi
mkdir -p /workspace/cache$DIR # make sure it exists even if cp fails
# Now /workspace/cache$DIR exists.
# Use bind mount to make $DIR backed by /workspace/cache$DIR
sudo mount --bind /workspace/cache$DIR $DIR
done

# install ghcup, ghc and cabal
export GHCUP_INSTALL_BASE_PREFIX=/workspace
export BOOTSTRAP_HASKELL_NONINTERACTIVE=1
export BOOTSTRAP_HASKELL_MINIMAL=1
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
/workspace/.ghcup/bin/ghcup install ghc --set
/workspace/.ghcup/bin/ghcup install cabal

# Add ghcup binaries to the PATH since VSCode does not see 'source .ghcup/env'
pushd /usr/local/bin
sudo ln -s /workspace/.ghcup/bin/* /usr/local/bin
popd

# Fix the Cabal dir since VSCode does not see CABAL_DIR
cabal update
echo "Symlinking /workspace/.cabal to ~/.cabal"
ln -s /workspace/.cabal ~
# Install pre-commit hook
pre-commit install

# Configure VSCode to use the locally built version of HLS
mkdir -p .vscode
echo '{ "haskell.serverExecutablePath": "/workspace/.cabal/bin/haskell-language-server" }' > .vscode/settings.json
if [ ! -f .vscode/settings.json ]; then
# Only write to .vscode/settings.json if it doesn't exist.
echo '{ "haskell.serverExecutablePath": "/home/gitpod/.cabal/bin/haskell-language-server" }' > .vscode/settings.json
fi

init: |
pushd docs
pip install -r requirements.txt
popd
init: |
cabal update
cabal configure --enable-executable-dynamic
cabal build --enable-tests
cabal install exe:haskell-language-server
command: |
cabal build --enable-tests
cabal build --enable-tests all
cabal install exe:haskell-language-server

# List the ports to expose. Learn more https://www.gitpod.io/docs/config-ports/
ports: []
Expand All @@ -62,4 +71,4 @@ vscode:
extensions:
- "haskell.haskell"
- "justusadam.language-haskell"
- "usernamehw.errorlens"
- "EditorConfig.EditorConfig"
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
# Build
*.nix @berberman @michaelpj @guibou
*.project @jneira
.gitpod.* @kokobd
46 changes: 5 additions & 41 deletions docs/contributing/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,49 +170,13 @@ Please, try to follow those basic settings to keep the codebase as uniform as po

### Formatter pre-commit hook

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.
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.

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

``` bash
nix-shell
```

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.

```json
{
"repos": [
{
"hooks": [
{
"entry": "stylish-haskell --inplace",
"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$)",
"files": "\\.l?hs$",
"id": "stylish-haskell",
"language": "system",
"name": "stylish-haskell",
"pass_filenames": true,
"types": [
"file"
]
}
],
"repo": "local"
},
{
"repo": "https://github.com/pre-commit/pre-commit-hooks",
"rev": "v4.1.0",
"hooks": [
{
"id": "mixed-line-ending",
"args": ["--fix", "lf"],
"exclude": "test/testdata/.*CRLF*.hs$"
}
]
}
]
}
```sh
pre-commit install
```

#### Why some components are excluded from automatic formatting?
Expand Down
49 changes: 0 additions & 49 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 8 additions & 42 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
flake = false;
};
flake-utils.url = "github:numtide/flake-utils";
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
};
gitignore = {
url = "github:hercules-ci/gitignore.nix";
flake = false;
Expand Down Expand Up @@ -92,7 +89,7 @@
flake = false;
};
myst-parser = {
url = "github:smunix/MyST-Parser?ref=fix.hls-docutils";
url = "github:smunix/MyST-Parser?ref=fix.hls-docutils";
flake = false;
};
# For https://github.com/readthedocs/sphinx_rtd_theme/pull/1185, otherwise lists are broken locally
Expand All @@ -103,7 +100,7 @@
poetry2nix.url = "github:nix-community/poetry2nix/master";
};
outputs =
inputs@{ self, nixpkgs, flake-compat, flake-utils, pre-commit-hooks, gitignore, ... }:
inputs@{ self, nixpkgs, flake-compat, flake-utils, gitignore, ... }:
{
overlays.default = final: prev:
with prev;
Expand All @@ -123,7 +120,7 @@
in hsuper.mkDerivation (args // {
jailbreak = if broken then true else jailbreak;
doCheck = if broken then false else check;
# Library profiling is disabled as it causes long compilation time
# Library profiling is disabled as it causes long compilation time
# on our CI jobs. Nix users are free tor revert this anytime.
enableLibraryProfiling = false;
doHaddock = false;
Expand Down Expand Up @@ -215,42 +212,11 @@
config = { allowBroken = true; };
};

# Pre-commit hooks to run stylish-haskell
pre-commit-check = hpkgs: pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
stylish-haskell.enable = true;
# use stylish-haskell with our target ghc
stylish-haskell.entry = pkgs.lib.mkForce "${hpkgs.stylish-haskell}/bin/stylish-haskell --inplace";
stylish-haskell.excludes = [
# Ignored files
"^Setup.hs$"
"test/testdata/.*$"
"test/data/.*$"
"test/manual/lhs/.*$"
"^hie-compat/.*$"
"^plugins/hls-tactics-plugin/.*$"

# Temporarily ignored files
# Stylish-haskell (and other formatters) does not work well with some CPP usages in these files
"^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$"
];
};
};

ghc902Config = (import ./configuration-ghc-90.nix) { inherit pkgs inputs; };
ghc922Config = (import ./configuration-ghc-92.nix) { inherit pkgs inputs; };

# GHC versions
# While HLS still works fine with 8.10 GHCs, we only support the versions that are cached
# While HLS still works fine with 8.10 GHCs, we only support the versions that are cached
# by upstream nixpkgs, which now only includes GHC version 9+
supportedGHCs = let
ghcVersion = "ghc" + (pkgs.lib.replaceStrings ["."] [""] pkgs.haskellPackages.ghc.version);
Expand All @@ -268,14 +234,14 @@
myst-parser = pkgs.poetry2nix.mkPoetryEnv {
projectDir = inputs.myst-parser;
python = pkgs.python39;
overrides = [
overrides = [
pkgs.poetry2nix.defaultPoetryOverrides
];
};
sphinx_rtd_theme = pkgs.poetry2nix.mkPoetryEnv {
projectDir = inputs.sphinx_rtd_theme;
python = pkgs.python39;
overrides = [
overrides = [
pkgs.poetry2nix.defaultPoetryOverrides
(self: super: {
# The RTD theme doesn't work with newer docutils
Expand Down Expand Up @@ -334,8 +300,8 @@
export DYLD_LIBRARY_PATH=${gmp}/lib:${zlib}/lib:${ncurses}/lib:${capstone}/lib
export PATH=$PATH:$HOME/.local/bin

# Enable the shell hooks
${self.checks.${system}.pre-commit-check.shellHook}
# Install pre-commit hook
pre-commit install

# If the cabal project file is not the default one.
# Print a warning and generate an alias.
Expand Down