ElmCast / elm-oracle

Query for information about values in elm source files.
150 stars 16 forks source link

Code intelligence #11

Closed mrmurphy closed 8 years ago

mrmurphy commented 8 years ago

Hi there!

I was thinking it'd be fun to take a shot at adding code intelligence (or local project autocomplete) support to Elm-Oracle. I dug into the code a bit this morning to see how the completions are generated for modules, and learned that you're using the output from the documentation generator to drive autocomplete.

I played with the idea of having elm-oracle generate docs for whatever Elm project is being worked on at the moment, and then use those to provide autocomplete suggestions, but in order for any docs to be generated at all, proper docstrings must be written, and all documented modules must be exported in elm-package.json, which renders that approach impractical for most work-in-progress development.

So I'm wondering what a better approach would be. If only Elm were self-hosted, parts of the compiler could be used to parse source files and build an AST. From that point autocomplete wouldn't be hard (I don't think), but it's not self-hosted. So in order to be able to use parts of the compiler (I don't even know that this is possible, just making assumptions here), at least part of elm-oracle would need to be written in Haskell.

Alternately, one could write an elm parser package in Elm, to take in Elm source files, and spit out some sort of AST. That sounds like a big project (though interesting!). But, would it be worth it?

A nice thing about that last idea is that an AST generator for Elm written in Elm could be useful in more cases than just autocomplete. It could be used to write a package for doing codemods on Elm code, for example.

Those are my thoughts. Any input?

zkessin commented 8 years ago

I for one would love to see this as it would open the way for all sorts of interesting tools for elm devs

TheoAndersen commented 8 years ago

+1 would be very helpfull

ajhager commented 8 years ago

So I implemented the first way you described, but like you said, all modules must be exposed and documented. This is disabled for now because it isn't very useful and slows down the process.

I will try to investigate better completion for code in your own project.

mrmurphy commented 8 years ago

@ajhager Very cool! Thanks for working on this.

ajhager commented 8 years ago

Elm Oracle 2.0 (which you can track in issue #13) will be adding support for most of what you have suggested. Closing this issue in favor of that one. Thanks again!