-
Notifications
You must be signed in to change notification settings - Fork 541
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
bug: LSP completion dialog should only recommend members of a struct #5664
Comments
Hello @misicnenad, I would like to help with this one if possible! |
@danielcdz awesome, please check with @mkaput if he can assign this to you |
ty @misicnenad, hey @mkaput can I help with this? |
@danielcdz yes of course! Task is assigned to you :) Thanks 💖 |
@danielcdz hey, how's it going? Would you like some assistance from my side in this area? |
@mkaput that would be great! I would write some questions below 👇 |
I'm trying to look where the completions for a struct are being made but I didn't find anything useful, I saw that on issue #5660 you left some comments with examples of where completions are computed, can you help me with something similar for this 🙏 |
It looks like you have to add a new completion kind for struct fields, here: cairo/crates/cairo-lang-language-server/src/ide/completion/mod.rs Lines 68 to 149 in 88f0506
This is basically traversing AST up to learn where you are. So you have to check out if you are within braces ( Then, you have to hook completion implementation, starting here add a clause for your new completion kind: cairo/crates/cairo-lang-language-server/src/ide/completion/mod.rs Lines 45 to 57 in 88f0506
The body of this function is pretty wild west now. You have to get the semantic model of the struct that you are completing. I think you can find a lot of logic to copy in dot completions (i.e. cairo/crates/cairo-lang-language-server/src/ide/completion/completions.rs Lines 182 to 254 in 57ffe18
For example, this is the function to get struct members (concrete, i.e. with generic parameters resolved to concrete types according to type inference context): cairo/crates/cairo-lang-semantic/src/items/structure.rs Lines 260 to 284 in 448c234
|
Hey @mkaput ty for all the explanations you gave me, I think I got the main idea on how to solve it, but I prefer to let this issue to a person more experienced in Rust, also I'm participating in a Hackathon and I don't have enough time to solve this issue at the moment, I'm sorry for this 😞 |
@danielcdz understood :)
Do you think you can add your own two cents to this? This would be a great contribution on its own! 😍 |
@KevinMB0220 feel free to submit a PR. We're not assigning tasks to external contributors anymore |
Bug Report
Cairo version:
2.6.3
Current behavior:
When creating a struct instance, there is no completion dialog support - the one that does appear contains some values that can only be described as random.
Example 1: struct in the same module:
Example 2: public struct in a different module with a public field:
Example 3: public struct in a different module with a private field:
Expected behavior:
Completion dialog for struct instances should only list its available fields and nothing else.
Expected for examples above:
Example 1: struct in the same module - should only list
field
.Example 2: public struct in a different module with a public field - should only list
field_2
.Example 3: public struct in a different module with a private field - should list nothing.
Steps to reproduce:
lib.cairo
in VS Code (ensure Cairo 1.0 extension is installed)CTRL + Space
)Related code:
Other information:
Related issue: #5660
The text was updated successfully, but these errors were encountered: