Skip to content
This repository was archived by the owner on Jun 20, 2019. It is now read-only.

Feature: Go to defintion #10

@andys8

Description

@andys8

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
    }

https://github.com/matheus23/elm-compiler-library/blob/502c59df4ac3df6578f99d3eb789d3eb96e3b5a0/compiler/src/Elm/Interface.hs#L34-L48

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] )

https://github.com/matheus23/elm-compiler-library/blob/502c59df4ac3df6578f99d3eb789d3eb96e3b5a0/builder/src/Elm/Project/Summary.hs#L27-L42

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

https://github.com/matheus23/elm-compiler-library/blob/502c59df4ac3df6578f99d3eb789d3eb96e3b5a0/builder/src/File/Find.hs#L30-L58

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

https://hackage.haskell.org/package/haskell-lsp-types-0.8.0.1/docs/Language-Haskell-LSP-Types.html#t:DefinitionRequest

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions