Skip to content
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

How to ignore some directories #299

Open
aveltras opened this issue Jun 28, 2021 · 4 comments
Open

How to ignore some directories #299

aveltras opened this issue Jun 28, 2021 · 4 comments
Labels
type: bug Something isn't working type: question Further information is requested

Comments

@aveltras
Copy link

Hi,

I'm currently trying to get haskell language server working with bazel and Nix.
Here is the repo for reference: https://github.com/aveltras/haskell-bazel-nix

I'm wondering if it's possible to prevent some directories from being processed, see the following for the why.

Here is the layout of my project.

The important directory here is backend which is the only one containing haskell code.

drwxr-xr-x 2 romain 4.0K Jun 27 15:10 .direnv
drwxr-xr-x 8 romain 4.0K Jun 28 18:36 .git
drwxr-xr-x 3 romain 4.0K Jun 27 19:07 .github
drwxr-xr-x 3 romain 4.0K Jun 27 12:33 backend
drwxr-xr-x 3 romain 4.0K Jun 27 12:33 frontend
-rw-r--r-- 1 romain  157 Jun 27 15:50 .bazelrc
-rw-r--r-- 1 romain    8 Jun 27 14:56 .envrc
-rw-r--r-- 1 romain   17 Jun 27 14:20 .gitignore
-rwxr-xr-x 1 romain  198 Jun 27 16:19 .hie-bios
-rw-r--r-- 1 romain  172 Jun 27 15:49 BUILD.bazel
-rw-r--r-- 1 romain  297 Jun 27 18:54 README.md
-rw-r--r-- 1 romain 2.7K Jun 28 13:35 WORKSPACE
-rw-r--r-- 1 romain 1.1M Jun 28 18:31 clean_rules_haskell.patch
-rw-r--r-- 1 romain  419 Jun 28 18:36 hie.yaml
-rw-r--r-- 1 romain 1.4K Jun 27 18:48 nixpkgs.nix
-rw-r--r-- 1 romain  306 Jun 27 15:10 shell.nix

Here is the content of hie.yaml

cradle:
  multi:
    - path: "./bazel-bin"
      config:
        cradle:
          none:
    - path: "./bazel-out"
      config:
        cradle:
          none:
    - path: "./bazel-skeleton"
      config:
        cradle:
          none:
    - path: "./bazel-testlogs"
      config:
        cradle:
          none:
    - path: "./backend"
      config:
        cradle:
          bios:
            program: ".hie-bios"

Here is the content of .hie-bios

#!/usr/bin/env bash
set -euo pipefail
bazel build //:hie-bios --output_groups=hie_bios
cat bazel-bin/hie-bios@hie-bios >"$HIE_BIOS_OUTPUT"
# Make warnings non-fatal
echo -Wwarn >>"$HIE_BIOS_OUTPUT"

Here is the result of running cat bazel-bin/hie-bios@hie-bios which get put into $HIE_BIOS_OUTPUT:

-package-id
base-4.14.1.0
-package-id
effectful-0.0.0.0-FJkj46K8yGP5azyQTr12pf
-pgma
bazel-out/host/bin/external/rules_haskell/haskell/cc_wrapper-python
-pgmc
bazel-out/host/bin/external/rules_haskell/haskell/cc_wrapper-python
-pgml
bazel-out/host/bin/external/rules_haskell/haskell/cc_wrapper-python
-pgmP
bazel-out/host/bin/external/rules_haskell/haskell/cc_wrapper-python -E -undef -traditional
-optc-fno-stack-protector
-ibackend/src
-ibazel-out/k8-fastbuild/bin/backend/src
backend/src/Main.hs

When I run haskell-language-server in the repo for the first time I get no problem as seen below.

haskell-language-server version: 1.2.0.0 (GHC: 8.10.4) (PATH: /nix/store/5vkn6fdmg7xnrfvxsknj70svjx4bbnyq-haskell-language-server-1.2.0.0/bin/haskell-language-server)
 ghcide setup tester in /home/romain/Code/skeleton.
Report bugs at https://github.com/haskell/haskell-language-server/issues

Step 1/4: Finding files to test in /home/romain/Code/skeleton
Found 1 files

Step 2/4: Looking for hie.yaml files that control setup
Found 1 cradle
  (/home/romain/Code/skeleton/hie.yaml)

Step 3/4: Initializing the IDE

Step 4/4: Type checking the files
2021-06-28 18:37:26.1797869 [ThreadId 51] INFO hls:     Consulting the cradle for "backend/src/Main.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/home/romain/Code/skeleton", cradleOptsProg = CradleAction: Multi}
> Loading:
> Loading: 0 packages loaded
> Analyzing: target //:hie-bios (0 packages loaded, 0 targets configured)
> INFO: Analyzed target //:hie-bios (0 packages loaded, 0 targets configured).
> INFO: Found 1 target...
> [0 / 1] [Prepa] BazelWorkspaceStatusAction stable-status.txt
> Target //:hie-bios up-to-date:
>   bazel-bin/hie-bios@hie-bios
> INFO: Elapsed time: 0.077s, Critical Path: 0.00s
> INFO: 1 process: 1 internal.
> INFO: Build completed successfully, 1 total action
> INFO: Build completed successfully, 1 total action
2021-06-28 18:37:26.3619936 [ThreadId 51] INFO hls:     Using interface files cache dir: /home/romain/.cache/ghcide/main-9ff5c982b40fa362ec8aa11ceb0828ccb14d1de7
2021-06-28 18:37:26.3621349 [ThreadId 51] INFO hls:     Making new HscEnv[main]
2021-06-28 18:37:26.3968677 [ThreadId 160] INFO hls:    finish: User TypeCheck (took 0.03s)

Completed (1 file worked, 0 files failed)
2021-06-28 18:37:26.3985316 [ThreadId 171] INFO hls:    finish: GetHie (took 0.00s)
2021-06-28 18:37:26.3986661 [ThreadId 172] INFO hls:    finish: GenerateCore (took 0.00s)

Having been run a first, bazel adds symlinks in the current repository as seen below:

drwxr-xr-x 2 romain 4.0K Jun 27 15:10 .direnv
drwxr-xr-x 8 romain 4.0K Jun 28 18:36 .git
drwxr-xr-x 3 romain 4.0K Jun 27 19:07 .github
drwxr-xr-x 3 romain 4.0K Jun 27 12:33 backend
lrwxrwxrwx 1 romain  117 Jun 28 18:39 bazel-bin -> /home/romain/.cache/bazel/_bazel_romain/4e0a165b088520c120efa911290fd831/execroot/skeleton/bazel-out/k8-fastbuild/bin
lrwxrwxrwx 1 romain  100 Jun 28 18:39 bazel-out -> /home/romain/.cache/bazel/_bazel_romain/4e0a165b088520c120efa911290fd831/execroot/skeleton/bazel-out
lrwxrwxrwx 1 romain   90 Jun 28 18:39 bazel-skeleton -> /home/romain/.cache/bazel/_bazel_romain/4e0a165b088520c120efa911290fd831/execroot/skeleton
lrwxrwxrwx 1 romain  122 Jun 28 18:39 bazel-testlogs -> /home/romain/.cache/bazel/_bazel_romain/4e0a165b088520c120efa911290fd831/execroot/skeleton/bazel-out/k8-fastbuild/testlogs
drwxr-xr-x 3 romain 4.0K Jun 27 12:33 frontend
-rw-r--r-- 1 romain  157 Jun 27 15:50 .bazelrc
-rw-r--r-- 1 romain    8 Jun 27 14:56 .envrc
-rw-r--r-- 1 romain   17 Jun 27 14:20 .gitignore
-rwxr-xr-x 1 romain  198 Jun 27 16:19 .hie-bios
-rw-r--r-- 1 romain  172 Jun 27 15:49 BUILD.bazel
-rw-r--r-- 1 romain  297 Jun 27 18:54 README.md
-rw-r--r-- 1 romain 2.7K Jun 28 13:35 WORKSPACE
-rw-r--r-- 1 romain 1.1M Jun 28 18:31 clean_rules_haskell.patch
-rw-r--r-- 1 romain  419 Jun 28 18:36 hie.yaml
-rw-r--r-- 1 romain 1.4K Jun 27 18:48 nixpkgs.nix
-rw-r--r-- 1 romain  306 Jun 27 15:10 shell.nix

When running haskell-language-server a second time, I know get errors related to haskell files present in my home directory.

haskell-language-server version: 1.2.0.0 (GHC: 8.10.4) (PATH: /nix/store/5vkn6fdmg7xnrfvxsknj70svjx4bbnyq-haskell-language-server-1.2.0.0/bin/haskell-language-server)
 ghcide setup tester in /home/romain/Code/skeleton.
Report bugs at https://github.com/haskell/haskell-language-server/issues

Step 1/4: Finding files to test in /home/romain/Code/skeleton
Found 16 files

Step 2/4: Looking for hie.yaml files that control setup
Found 2 cradles
  (/home/romain/Code/skeleton/hie.yaml)

Step 3/4: Initializing the IDE

Step 4/4: Type checking the files
2021-06-28 18:47:40.3416571 [ThreadId 70] INFO hls:     Consulting the cradle for "/home/romain/.cache/bazel/_bazel_romain/4e0a165b088520c120efa911290fd831/external/rules_haskell/tools/worker/Main.hs"
2021-06-28 18:47:40.3418609 [ThreadId 70] WARNING hls:  No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for /home/romain/.cache/bazel/_bazel_romain/4e0a165b088520c120efa911290fd831/external/rules_haskell/tools/worker/Main.hs.
 Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).

********** Elided output **************

Files that failed:
 * /home/romain/.cache/bazel/_bazel_romain/4e0a165b088520c120efa911290fd831/external/rules_haskell/tools/coverage-reports/executable/Main.hs
 * /home/romain/.cache/bazel/_bazel_romain/4e0a165b088520c120efa911290fd831/external/rules_haskell/tools/ghc-paths/Test.hs
 * /home/romain/.cache/bazel/_bazel_romain/4e0a165b088520c120efa911290fd831/external/rules_haskell/tools/runfiles/bin/Bin.hs
 * /home/romain/.cache/bazel/_bazel_romain/4e0a165b088520c120efa911290fd831/external/rules_haskell/tools/runfiles/test/Test.hs
 * /home/romain/.cache/bazel/_bazel_romain/4e0a165b088520c120efa911290fd831/external/rules_haskell/tools/worker/Compile.hs
 * /home/romain/.cache/bazel/_bazel_romain/4e0a165b088520c120efa911290fd831/external/rules_haskell/tools/worker/Main.hs
 * /home/romain/.cache/bazel/_bazel_romain/4e0a165b088520c120efa911290fd831/external/rules_haskell/tools/worker/Server.hs
 * /home/romain/.cache/bazel/_bazel_romain/4e0a165b088520c120efa911290fd831/external/rules_haskell/tools/worker/Proto/Worker.hs
2021-06-28 18:47:43.6550553 [ThreadId 2624] INFO hls:   finish: GenerateCore (took 0.00s)
 * /home/romain/.cache/bazel/_bazel_romain/4e0a165b088520c120efa911290fd831/external/rules_haskell/tools/worker/Proto/Worker_Fields.hs

Completed (7 files worked, 9 files failed)
@jneira jneira added type: question Further information is requested type: bug Something isn't working labels Jun 28, 2021
@fendor
Copy link
Collaborator

fendor commented Jun 28, 2021

As fas as I can see, you are using the debug mode of Haskell language server the executable, not hie-bios. The former discovers Haskell source files on its own to try and load them, giving you an overview of which files are available and which one HLS successfully can load.
It should not have any impact on the usual behaviour of HLS, just for this debug mode. IIRC, you can invoke HLS with haskell-language-server backend/ to only look for Haskell files in backend/.

Or are there other issues as well?

@jneira
Copy link
Member

jneira commented Jun 28, 2021

It seems the paths are fully resolved, including symlinks and then they are compared against hie.yaml relative paths. So they dont match and are not processed by the none cradle.
A workaround could be add those resolved paths to the hie.yaml:

- path: "/home/romain/.cache/bazel" # or /home/romain/.cache?
      config:
        cradle:
          none:

so maybe the actual ones ("./bazel-out", "./bazel-bin", etc) are not needed

@jneira
Copy link
Member

jneira commented Jul 13, 2021

@aveltras did you have the chance to try the above workaround?

@aveltras
Copy link
Author

@jneira it didn't work. I had to put it on hold for now and will be coming back at this (migration of a monorepo to bazel) soon hopefully. Feel free to close this issue, I'll comment again if I find anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working type: question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants