Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make code range work on comments #3005

Open
sloorush opened this issue Jun 30, 2022 · 3 comments · May be fixed by #3054
Open

Make code range work on comments #3005

sloorush opened this issue Jun 30, 2022 · 3 comments · May be fixed by #3054
Labels
component: hls-code-range-plugin for code range related functionalities, such as selection range and folding range type: enhancement New feature or request

Comments

@sloorush
Copy link
Contributor

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

@kokobd kokobd added component: hls-code-range-plugin for code range related functionalities, such as selection range and folding range and removed status: needs triage labels Jul 1, 2022
@sloorush
Copy link
Contributor Author

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.

@kokobd
Copy link
Collaborator

kokobd commented Jul 17, 2022

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.
#2565 (comment)

@kokobd
Copy link
Collaborator

kokobd commented Jul 17, 2022

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

@sloorush sloorush linked a pull request Jul 22, 2022 that will close this issue
@kokobd kokobd changed the title Make shrink/expand selection work on comments Make code range work on comments Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: hls-code-range-plugin for code range related functionalities, such as selection range and folding range type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants