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-on: How can I configure rubyLsp.indexing.includedPatterns from my add-on? #2948

Open
kozy4324 opened this issue Dec 3, 2024 · 3 comments
Assignees

Comments

@kozy4324
Copy link
Contributor

kozy4324 commented Dec 3, 2024

I am developing an add-on for Rake:
https://github.com/kozy4324/ruby-lsp-rake

I’d like to configure rubyLsp.indexing.includedPatterns from my add-on to include a pattern like **/Rakefile* , but it seems there is no way to do so. How can I configure this? Or do you have any plans to create an API for such a use case? If adding such an API is possible, I’d be happy to submit a pull request. Thank you for your consideration!

@andyw8
Copy link
Contributor

andyw8 commented Dec 9, 2024

@kozy4324 there may be a way do this currently, but I haven't verified:

In an add-on, you have access to @global_state, and from that you can get a reference to the index so you could try index.apply_config(...) (see configuration_test.rb for an example).

(cc @st0012).

@kozy4324
Copy link
Contributor Author

@andyw8 Thank you for your help!

@index.configuration.apply_config({ "included_patterns" => ["**/Rakefile"] }) call in the Addon#activate method works well 👍
kozy4324/ruby-lsp-rake@4667d80

I thought there might be some concerns about making this a public API, but if this approach is acceptable, I believe we can close this issue.

@andyw8
Copy link
Contributor

andyw8 commented Dec 16, 2024

@kozy4324 that's good to hear that it works.

You're right, this isn't ideal as a public API. An add-on could change configuration in a way that is detrimental to other add-ons, or overwrite a user's config.

I think a better API would look something like:

@index.configuration.include_pattern("**/Rakefile")

and its implementation would append to included_patterns (but not overwrite any existing values).

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

No branches or pull requests

2 participants