haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.72k stars 368 forks source link

Cabal go to module's definition #4380

Closed VenInf closed 3 months ago

VenInf commented 3 months ago

Go to the module's definition

If you click go-to definition on the field under exposed-module or other-module it will open the file where this module was defined.

Video with an example:

https://github.com/user-attachments/assets/c5cdcb9e-4d24-4d6b-a83a-de34d8dcedf6

Implementation details

The go-to definition function compares the highlighted text with modules in the cabal file. If there is a match, it takes the respective build target and tries to fetch their hsSourceDirs from the PackageDescription. (by looking at all buildInfos with matching names).

After finding them, it constructs a path using directory where the cabal file is located, the info from hsSourceDirs and a name of the module converted to a path. If the file exists it returns the Definition with the acquired location.

What isn't implemented

VenInf commented 3 months ago

Noteworthy change: Split one large gotoDefinition function to multiple specific ones. This will hurt the performance a little bit, but hopefully make the addition of other definitions easier.