-
Notifications
You must be signed in to change notification settings - Fork 14
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
Use AST #109
base: main
Are you sure you want to change the base?
Use AST #109
Conversation
Convert lambda declaration.
Complete ternary_expression test
…ferent choices and/or a sequence of nodes.
Signed-off-by: Nikita Pivkin <nikita.pivkin@smartforce.io>
Do not ignore ERROR treesitter nodes. This reduces scenarios where incomplete source code cannot be located by cursor position while still being able to get that text content. Refactor analysis code + tests. Extract astContext to hold information about node under cursor being analyzed. Protect against variable GenDecl not having type information.
…1b4b. Grab position context by reading string under cursor instead of finding the node, as this is not always reliable due to ERROR nodes. Fix completion by announcing methods kind as methods instead of plain functions. Fix parsing access_ident.
… are no parse errors. Use string analysis when cursor is inside parse error. Completion: Improve tests on enum values and methods. Completion: solveXAtSelectorExpr does not resolve iden type so completion can decide if child symbols can be included in result or not. Drop fromPosition and use Location instead.
Add tests for autocompleting fault constants and its methods.
…14dc06aaec0ca109f9cc7a77484345a0e64118a6)
Some notes @PgBiel These take the assumption that cursor context is retrieved by reading the string under the cursor. The issue here is that these cases are actually invalid, as they are not allowed by the grammar, and the AST generated is undefined (and might be flagged with Error). Notes to discuss:
|
I haven't had the time to look at your code yet, but do you mean that Assuming it's not the last option, my code, at those commits, basically just had some extra logic to not suggest enum members / fault constants after variables. Code like |
Yes,
This is not valid, but treesitter still tries to parse it, giving a tree like this: Where the ERROR node contains the source This treesitter tree translates to my AST C3 Tree:
This affects analysis done on GoTo and Completion operations because when trying to analyze the I could obviously store the ERROR node inside I'm just exposing the difficulties I'm encountering :D |
Oh don't worry, I was just trying to contextualize my message, i.e. it's possible that the answer to my question was obvious from the code (and sorry if so), I just didn't have the time to take a proper look at it yet. Didn't mean to imply that you were applying too much pressure, or something similar - expressing tone in online text is hard. Sorry! :) Feel free to send further questions, I'll always try to answer them.
Ah I see the problem. If I'm going to be entirely fair, that particular case is evidently pathological since the syntax is invalid, but it still would be nice to be able to properly recover from those weirdnesses. I think we could blame the tree-sitter grammar here. Maybe it would be nice if they could allow any invalid ident casing anywhere, using a specific node for this, e.g. |
I guess I will still need to do string analysis on cursor position just to avoid these kind of issues... |
Not sure if that's strictly necessary... I see two options:
|
Simplify them and cover all tested cases.
Move AST builders to different module. Do not walk TypeSpec.TypeDescription as an AST node.
Motivation
Treesitter is used to obtain a structured representation of source code, which has been utilized to extract symbol declarations.
So far, Treesitter has been used to parse the source code to analyze and obtain a structured representation of the code: Context Syntax Tree (CST). The CST, also known as the Parse Tree, contains all the elements that are part of the text (spaces, brackets, etc.).
Although the CST can be navigated to analyze the code, it contains too much information about the language's syntax, making certain tasks more challenging.
On the other hand, using an AST (Abstract Syntax Tree) would allow working with a simpler structure that more accurately reflects the program's logic.
Strategy
Continuing to use Treesitter as a parser simplifies a large part of the work, as there is currently no other ready-to-use parser available.
One option is to convert the CST generated by Treesitter into an AST.
Subsequently, by using the Visitor pattern, it would be possible to implement different analyzers:
TODO
def
#105distinct
types (Supportdistinct
types #107).