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

Add definition, hover and completion support for global variables #2644

Closed
vinistock opened this issue Oct 1, 2024 · 8 comments
Closed

Add definition, hover and completion support for global variables #2644

vinistock opened this issue Oct 1, 2024 · 8 comments
Assignees
Labels
enhancement New feature or request help-wanted Extra attention is needed pinned This issue or pull request is pinned and won't be marked as stale

Comments

@vinistock
Copy link
Member

We should provide features for global variables.

Note: this issue includes instructions on how to add indexing capabilities for globals, definition support, hover support and completion support. If you wish to contribute this, please create 4 separate pull requests for each step.

Implementation

I think the most natural implementation is to add global variables as a new entry type in the index. Hopefully, RBS should have global declarations with documentation that we can simply index like we do core declarations.

If RBS does not have global declarations, please raise it in this issue and we can reach out to Soutaro and the team to ask for guidance.

Changes to the indexer

  1. Create a new entry for global variables
  2. Start handling RBS::AST::Declarations::Global in process_declaration, so that we can insert the global entries into the index

Changes to definition

  1. We need to allow global variables (Prism::GlobalVariableReadNode) as a possible target here
  2. Then the listener has to register for the on_global_variable_read_enter event and
  3. define a handler for on_global_variable_read_enter
  4. Since we're talking about global variables, there's no need to perform any type checking. We just need to access the index and get the declarations based on the name
@index[name_of_global_variable]
  1. Then loop through the entries and push to the response as we do here

Changes to hover

Essentially, the same exact steps as definition. Simply look for the hover request and listener and apply analogous changes.

Changes to completion

  1. Allow global variables as a target here
  2. Register for the event and create the associated handler
  3. Use the following to get suggestions for global variables
# Get all declarations that start with `$`, which can only be used by globals
@index.prefix_search("$")
  1. Use candidates to build the completion list. Similar to what we do here
@vinistock vinistock added enhancement New feature or request help-wanted Extra attention is needed pinned This issue or pull request is pinned and won't be marked as stale labels Oct 1, 2024
@snutij
Copy link
Contributor

snutij commented Oct 1, 2024

Hello! I'm having a look to this, RBS declaration exists: global_variables.rbs. I'll try to push the indexer changes before EoW. 👍

@vinistock
Copy link
Member Author

Amazing! Please post here or on the DX Slack if you need any assistance.

@snutij
Copy link
Contributor

snutij commented Oct 3, 2024

Just a quick question about the completion request: can we consider adding $ as a trigger character? To my understanding, Prism isn't dispatching the node event because it's not considered valid. As a result, users have to type a second character to clear the error, which then dispatches the event and triggers the completion. This isn't ideal, especially considering that the majority of global variables are two characters long.

@andyw8
Copy link
Contributor

andyw8 commented Oct 3, 2024

Makes sense to me.

@vinistock
Copy link
Member Author

Yeah, we'll definitely need to add $ as a trigger character.

@snutij
Copy link
Contributor

snutij commented Oct 21, 2024

After #2749, I'll need to go on the definition request again, to address other types of global variable nodes as well. Sorry for initial missing, this should be done within the week.

@vinistock
Copy link
Member Author

No need to apologize at all! Thank you for contributing this 🙏.

@vinistock
Copy link
Member Author

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help-wanted Extra attention is needed pinned This issue or pull request is pinned and won't be marked as stale
Projects
None yet
Development

No branches or pull requests

3 participants