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

Support Completion for StringNode, SymbolNode #2910

Open
1 task done
tiev opened this issue Nov 26, 2024 · 3 comments
Open
1 task done

Support Completion for StringNode, SymbolNode #2910

tiev opened this issue Nov 26, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@tiev
Copy link

tiev commented Nov 26, 2024

I have checked that this feature is not already implemented

  • This feature does not exist

Use case

I'm writing an Addon and also need to support StringNode and SymbolNode.

In my tools, String is used for the keys of components in a container. So, when seeing the syntax of accessing the container, I want to have auto-completion for available keys.

E.g.,

class Dummy
  include App::Deps['component_key']
end

Description

To make the completion for component keys, the Completion should support also StringNode (and I also want to support SymbolNode)

Implementation

module RubyLsp
  module Requests
    class Completion < Request
      def initialize(document, global_state, params, sorbet_level, dispatcher)
        ...
        node_context = RubyDocument.locate(
          document.parse_result.value,
          char_position,
          node_types: [
            Prism::CallNode,
            Prism::ConstantReadNode,
            Prism::ConstantPathNode,
            Prism::GlobalVariableAndWriteNode,
            Prism::GlobalVariableOperatorWriteNode,
            Prism::GlobalVariableOrWriteNode,
            Prism::GlobalVariableReadNode,
            Prism::GlobalVariableTargetNode,
            Prism::GlobalVariableWriteNode,
            Prism::InstanceVariableReadNode,
            Prism::InstanceVariableAndWriteNode,
            Prism::InstanceVariableOperatorWriteNode,
            Prism::InstanceVariableOrWriteNode,
            Prism::InstanceVariableTargetNode,
            Prism::InstanceVariableWriteNode,
            Prism::StringNode,
            Prism::SymbolNode,
          ],
          code_units_cache: document.code_units_cache,
        )
...
@tiev tiev added the enhancement New feature or request label Nov 26, 2024
@tiev
Copy link
Author

tiev commented Nov 26, 2024

If it's OK, I'm happy to make the PR

@vinistock
Copy link
Member

Thanks for the feature suggestion! We can definitely do that, but the change is a bit more complicated than just adding the nodes to the list.

The moment you add them, it will break the completion for require and require_relative because those are currently triggering on the call node. You'll need to adjust those to work based on the string node as part of the addition.

@tiev
Copy link
Author

tiev commented Nov 28, 2024

I will consider either this or the approach for #2913
Either approach can fulfill my use case.
Let me play around with them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants