-
Notifications
You must be signed in to change notification settings - Fork 5
Feature: Go to defintion #10
Description
Feature
Based on the selection the user should be able to jump to the file to the position where the selection is defined. This can be in a dependency or the codebase of the application.
Gathering information
Elm Compiler
Interfaces
are defined in Elm.Interface
.
type Interfaces =
Map.Map ModuleName.Canonical Interface
data Interface =
Interface
{ _types :: Map.Map N.Name Can.Annotation
, _unions :: Map.Map N.Name Union
, _aliases :: Map.Map N.Name Alias
, _binops :: Map.Map N.Name Binop
}
Stuff.Verify.verify
emits Summary
and is already used. Defined in Elm.Project.Summary
.
data Summary =
Summary
{ _root :: FilePath
, _project :: Project
, _exposed :: ExposedModules
, _ifaces :: Module.Interfaces
, _depsGraph :: DepsGraph
}
type ExposedModules =
Map.Map Module.Raw [Package]
type DepsGraph =
Map.Map Name ( Version, [Name] )
File.Find.find
can return the path of the file on disk, given Summary
, Origin
and Module.Raw
.
data Asset
= Local FilePath
| Kernel FilePath (Maybe FilePath)
| Foreign Pkg.Package
| ForeignKernel
find :: Summary.Summary -> E.Origin -> Module.Raw -> Task.Task_ E.Problem Asset
find (Summary.Summary root project exposed _ _) origin name =
do here <- liftIO Dir.getCurrentDirectory
let toRoot dir = FP.makeRelative here (root </> dir)
case project of
Project.App info ->
do let srcDirs = map toRoot (Project._app_source_dirs info)
findElm project srcDirs exposed origin name
Project.Pkg _ ->
if N.startsWith "Elm.Kernel." name then
if Project.isPlatformPackage project then
findKernel (toRoot "src") exposed origin name
else
Task.throw $ E.ModuleNameReservedForKernel origin name
else
findElm project [ toRoot "src" ] exposed origin name
Language Server Protocol
Called "Goto Type Definition Request".
Request:
method: ‘textDocument/definition’
params: TextDocumentPositionParams
Response:
result: Location | Location[] | null
https://microsoft.github.io/language-server-protocol/specification#textDocument_definition
Related: Goto Type Definition Request, Goto Implementation Request
Haskell LSP
type DefinitionRequest =
RequestMessage ClientMethod TextDocumentPositionParams LocationResponseParams
type DefinitionResponse =
ResponseMessage LocationResponseParams
Comparison
intellij-elm
The klazuka/intellij-elm
(elm plugin for IntelliJ in Kotlin) has the go to source feature.
https://github.com/klazuka/intellij-elm/blob/master/src/main/kotlin/org/elm/ide/navigation/ElmGoToSymbolContributor.kt