haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

Make shrink/expand selection work on comments

Open sloorush opened this issue 3 years ago • 3 comments

Is your feature request related to a problem? Please describe.

@kokobd had pointed this out. When you expand selection(using shift+alt+right arrow) from within a comment, expand selection does not work on comments.

Describe the solution you'd like It is because comments are not included in HieAST, which we use for constructing ranges in the hls-selection-range-plugin. Annotated ParsedSource can be used to handle structures not in HieAST properly.

More information about it --> https://gitlab.haskell.org/ghc/ghc/-/wikis/api-annotations#comments

cc: @kokobd

sloorush avatar Jun 30 '22 11:06 sloorush

Can someone please point me to some documentation/explaination about how Annotated parse source is built/how it works? I am stuck at how it relates with the hieAST and how to add it to the CodeRange tree.

sloorush avatar Jul 17 '22 05:07 sloorush

Disclaimer: I'm not an expert in this field, below is what I have learned from some exact-print related issues. @wz1000 knows much more.

@sloorush Annotated ParsedSource is the original GHC AST plus some so-called "annotations". HieAST is the serializable AST containing the structure, type info, etc.

The main difference between them is that HieAST is easier to query, but it can not be used to modify the source code, as it doesn't contain the full "exact-print" information. Doc of HieFile might help you

By the way, HIE doesn't stands for "haskell ide engine", it means "hi file extended". If you have tried to compile source code with ghc command directly, you may have noticed some .hi files. So this is a GHC structure.

So what is Annotated ParsedSource? Annotated is defined in HLS, for compatible purposes. Before GHC 9.2, the GHC AST type ParsedSource doesn't contain "annotations" in it. Instead, you need to have Anns at hand. But in GHC 9.2, Anns is no longer required, it's built directly into the AST, ParsedSource. To make us not write too many C Pre Processor directives, we have Annotated ParsedSource to represent "AST plus exact print information"

Pepe Iborra's comments may also help you. https://github.com/haskell/haskell-language-server/pull/2565#issuecomment-1019453473

kokobd avatar Jul 17 '22 08:07 kokobd

I believe you don't need to remove the usage of HieAST, you just need to add new nodes to the tree. In ASTPreProcess.hs, we already have some "custom node" (nodes doesn't exist in the original HieAST). Maybe you can pull in Annotated ParsedSource, and inject comment nodes into HieAST

kokobd avatar Jul 17 '22 08:07 kokobd