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

Follow definitions across local packages #799

Closed
JosephLucas opened this issue Feb 21, 2020 · 9 comments
Closed

Follow definitions across local packages #799

JosephLucas opened this issue Feb 21, 2020 · 9 comments
Labels
component: ghcide os: nixos type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@JosephLucas
Copy link

Does ghcide plan to implement a feature to follow definitions across local packages ? That would be really helpful for projects built with obelisk (reflex-frp).

@cocreature
Copy link
Contributor

In principle we have the logic for that already if there are .hie files for dependencies. But to make it usable for Haskell (we use it for DAML) there are however a few open questions here:

  1. How do we locate .hie files for a dependency?
  2. How do we locate source files for a dependency?
  3. Do we want to load the source file of a dependency? If so, which flags do we use?

I think 1 and 2 probably need to come from hie-bios since that is definitely specific to each build tool. For 3 I don’t really have a great answer. At least initially the most sensible solution seems to be to just not load the source file at least not unless it’s a “local” package (e.g. for cabal that would mean that it’s listed in packagesin cabal.project).

@jneira jneira changed the title Follow definitions across packages Follow definitions across local packages Sep 24, 2020
@jneira
Copy link
Member

jneira commented Sep 24, 2020

I've just checked this one in haskell-lsp and it is not implemented yet.
I guess @wz1000 work about using a database to store the needed info could enable this

@pepeiborra pepeiborra transferred this issue from haskell/ghcide Jan 1, 2021
@jneira
Copy link
Member

jneira commented Jan 11, 2021

Hi, i've tested it out again with haskell-lsp and haskell-lsp-types and it works. However you must open a file from the dependant package (haskell-lsp-types in this case) before being able to jump from the dependent package (haskell-lsp).
@JosephLucas could you try in that order to check if it works for you?

@jneira jneira added component: ghcide status: needs info Not actionable, because there's missing information type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Jan 11, 2021
@JosephLucas
Copy link
Author

No success with ob init, ob shell, vscode with haskell plugin.

I also tried to write a minimal multi-project setup, but the feature does not work and I get this error:

Failed to parse result of calling cabal
Resolving dependencies...

Warning: The package list for 'hackage.haskell.org' is 148 days old.
Run 'cabal update' to get the latest list of available packages.
cabal: Could not resolve dependencies:
[__0] trying: B-0.0.0 (user goal)
[__1] unknown package: p1 (dependency of B)
[__1] fail (backjumping, conflict set: B, p1)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: B, p1

Since I am a bit lost in the haskell packaging, it is very probable that my fixture is wrong though.


Steps to reproduce my attempt:

  1. Download, decompress, and cd into, the attached fixture folder minimal_fixture_multi_projects.zip

  2. use a shell env with cabal v3, ghc 8.8.4 and appropriate packages thanks to shell.nix using the unstable tested branch

nix-shell
  1. Use the haskell plugin of vscode (default config).

@jneira
Copy link
Member

jneira commented Jan 12, 2021

@JosephLucas i am not using nix, but i will try to reproduce in my env with that zip

@jneira
Copy link
Member

jneira commented Mar 1, 2021

With the inclusion of hiedb go to definition has been improved (see #704)
@JosephLucas had you the opportunity of thrying hls-1.0 to see if it fixes the issue for you?

@JosephLucas
Copy link
Author

I just did it with my fixture and I keep getting the same error, while using haskell-language-server-1.0.0-linux-8.6.5.

@jneira jneira removed the status: needs info Not actionable, because there's missing information label Mar 1, 2021
@jneira
Copy link
Member

jneira commented Mar 21, 2021

@JosephLucas
The project failed to start for me with:

[client] run command: "haskell-language-server-wrapper --lsp -d"
[client] debug command: "haskell-language-server-wrapper --lsp -d"
[client] server cwd: undefined
Module "d:\dev\ws\haskell\issues\fixture\a" is loaded by Cradle: Cradle {cradleRootDir = "d:\\dev\\ws\\haskell\\issues\\fixture", cradleOptsProg = CradleAction: Cabal}
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 1.0.0.0 x86_64 ghc-8.10.4
Current directory: d:\dev\ws\haskell\issues\fixture
Operating system: mingw32
Arguments: ["--lsp","-d"]
Cradle directory: d:\dev\ws\haskell\issues\fixture
Cradle type: Cabal

Tool versions found on the $PATH
cabal:		3.4.0.0
stack:		2.6.0
ghc:		8.10.4


Consulting the cradle to get project GHC version...
Failed to get project GHC version:CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Error when calling cabal --builddir=C:\\Users\\atrey\\AppData\\Local\\hie-bios\\dist-fixture-bf37263656d27c3a995d10a73de9de97 v2-exec --with-compiler C:\\Users\\atrey\\AppData\\Local\\hie-bios\\wrapper-6ce919108ae554ccbea99268a2e8fd8e.exe ghc -v0 -- --numeric-version","","cabal: Could not resolve dependencies:\n[__0] trying: B-0.0.0 (user goal)\n[__1] unknown package: p1 (dependency of B)\n[__1] fail (backjumping, conflict set: B, p1)\nAfter searching the rest of the dependency tree exhaustively, these were the\ngoals I've had most trouble fulfilling: B, p1\n\n"]}

so no hls feature could work.

It seems you should use the package name A instead p1, as p1.cabal set the package name to A
So with a p2.cabal like

cabal-version: 1.12

name:           B
version:        0.0.0
build-type:     Simple

library
  hs-source-dirs:
      src
  build-depends:
    base ==4.*
    , A
  default-language: Haskell2010

and fixing ./p1/src/A.hs:

module A where

a :: Int
a = 1

...the project builds succesfully.

After opening A.hs in vscode, and opening B.hs i am able to jump from A.a to A.hs

@jneira jneira added the status: needs info Not actionable, because there's missing information label Mar 21, 2021
@JosephLucas
Copy link
Author

I can confirm that it works. Well done :) You can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ghcide os: nixos type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

No branches or pull requests

3 participants