You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow a user to quickly add an import when in the context of a defintion, so that adding the import is just a keyboard shortcut away, without loosing the current context the user is in.
Details:
User is inside a function definition and writes Json.decodeString and presses magic key combo
The editor is able to figure out
That the only module that exposes decodeString is the Json.Decode module
That this module has not been already imported
With that knowledge is able to add a new import declaration node to the AST with module: "Json.Decode", alias: "Json" (and no exposing node)
The user may keep on typing with the knowledge the import is in place and that the Json alias know can be safely used (and will give autocompletions etc etc upon further usage)
So you would need:
a way to introspect all exposeds for all modules in the project (bar the ones you have already imported for the given module, and probably default imports)
a way to figure out based on cursor position that you are in range of a top level definition
Discusion:
Might partially be out of scope as it requires knowledge of other modules exposed functions
For it to work, an illegal state (partially) must be supported
The text was updated successfully, but these errors were encountered:
As described above, I don't think this would require parsing files with syntax errors; in this example, the file is syntactically valid, but references some variables that are not in scope.
I think the discovery of exposed modules is beyond the scope of elm-format, especially since the elm-package.json file is already in json format.
However, elm-format could be used to discover the exposed functions within a module. With a simple AST output from elm-format, three things would have to be checked:
if the module explicitly lists what it exposes, use that list
if the module exposes (..), check all the normal top-level definitions (things like a = ... and f x = ....
if the module exposes (..), check all the destructing top-level definitions (things like (a, b, c) = ... and {x, y} = ...
My current plan for the elm-format AST is to canonicalize all the variable references (meaning, for example, if you import Json.Encode exposing (Value), then an AST node of a reference to Value would actually indicate that it was referring to Json.Encode.Value rather than just Value. I think that would be ideal for tool authors, and should be doable in elm-format, but I'm not sure yet how much work will be involved.
a way to figure out based on cursor position that you are in range of a top level definition
I'm not sure what that means; aren't you always in range of top-level defintions?
a way to figure out based on cursor position that you are in range of a top level definition
I guess what I meant was a way to determine that you are in range of a valid top-level declaration (function, value, port , but not an import or module declaration, probably not if you are inside a comment etc). Thinking more about it would probably be better to let the client/tool handle this, as long as location information is present for all (relevant) ast nodes that would be simple enough.
Summary:
Allow a user to quickly add an import when in the context of a defintion, so that adding the import is just a keyboard shortcut away, without loosing the current context the user is in.
Details:
Json.decodeString
and presses magic key combodecodeString
is theJson.Decode
modulemodule: "Json.Decode", alias: "Json"
(and no exposing node)Json
alias know can be safely used (and will give autocompletions etc etc upon further usage)So you would need:
Discusion:
The text was updated successfully, but these errors were encountered: