Open andys8 opened 5 years ago
This is a dump of interface representations for a sample package elm-geohash
created by deriving Show
instances:
https://pastebin.com/raw/6GeLnsGj
Hi there. I'm working on an experimental project where I want access to the type definitions generated from the compiler. I arrived at a similar discovery, that Elm.Interface has the goods, and deriving Show can be used to dump contents of a real package. I found http://hackage.haskell.org/package/show-prettyprint useful for a more readable output.
@mbylstra Oh, thanks! I even know the author of the package.
Summary
Note: There is a part missing in the middle because of file limits.
https://gist.github.com/andys8/d73996fa4739a179406a19da9e08c43f
Compare with https://github.com/stoeffel/elmi-to-json
@matheus23 documented the elm-compiler
architecture: https://github.com/matheus23/elm-compiler-library/blob/502c59df4ac3df6578f99d3eb789d3eb96e3b5a0/COMPILER.md
Compile.runTypeInference
returns a Map with Annotations. The result contains more information than exposed modules.
runTypeInference :: L.Localizer -> Can.Module -> Result i (Map.Map N.Name Can.Annotation)
runTypeInference localizer canonical =
case unsafePerformIO (Type.run =<< Type.constrain canonical) of
Right annotations ->
Result.ok annotations
Left errors ->
Result.throw (Error.Type localizer errors)
Dump: https://gist.github.com/andys8/3ab81b72fee326df726779c532bf14f8
flipTuple : a -> b -> ( b, a )
flipTuple a b =
( b, a )
(Name {_name = "flipTuple"}
,Forall (fromList [(Name {_name = "a"},()),(Name {_name = "b"},())])
(TLambda (TVar (Name {_name = "a"}))
(TLambda (TVar (Name {_name = "b"}))
(TTuple (TVar (Name {_name = "b"}))
(TVar (Name {_name = "a"}))
Nothing))))
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 inElm.Interface
.https://github.com/matheus23/elm-compiler-library/blob/502c59df4ac3df6578f99d3eb789d3eb96e3b5a0/compiler/src/Elm/Interface.hs#L34-L48
Stuff.Verify.verify
emitsSummary
and is already used. Defined inElm.Project.Summary
.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, givenSummary
,Origin
andModule.Raw
.https://github.com/matheus23/elm-compiler-library/blob/502c59df4ac3df6578f99d3eb789d3eb96e3b5a0/builder/src/File/Find.hs#L30-L58
Language Server Protocol
Called "Goto Type Definition Request".
https://microsoft.github.io/language-server-protocol/specification#textDocument_definition
Related: Goto Type Definition Request, Goto Implementation Request
Haskell LSP
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