durkiewicz / elm-plugin

Elm language support plugin for IntelliJ IDEA.
MIT License
136 stars 15 forks source link

Fix #37: insert import clauses in the correct place relative to comments #39

Closed klazuka closed 7 years ago

klazuka commented 7 years ago

Fix for #37

@durkiewicz where's the right place to capture the special knowledge about doc comments and the initial "|" character in a multi-line comment? I did it all inline, but it seems like it would be helpful if we brought this more formally into the domain types.

Also, does the IntelliJ/PSI SDK have any convenience utils for working with multi-line PsiComments? It seems strange to me that they parse as 3 siblings instead of as a single element.

durkiewicz commented 7 years ago

The only place where the knowledge of the "|" character in a doc comment should be put is the lexer. The lexer should return a START_DOC_COMMENT token and then the parser should produce a level_comment or a doc_comment in the PSI depending whether the comment starts with START_COMMENT or a START_DOC_COMMENT.

The reason why we need to parse comments like that it the concept of level comments in Elm. If you want to see how it works, put something like that in the middle of any Elm code:

{- comment {- inner comment -} -}

And then try removing some "-}".

I'm closing the pull request because, as you see, it needs to be implemented in a different way.