Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

Add a method to find builtins with server name. #1190

Closed
1 task done
DoeringChristian opened this issue Oct 16, 2022 · 7 comments
Closed
1 task done

Add a method to find builtins with server name. #1190

DoeringChristian opened this issue Oct 16, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@DoeringChristian
Copy link

Issues

  • I have checked existing issues and there are no existing ones with the same request.

Feature description

Hi,

I am using Mason to install null-ls servers with the plugin mason-null-ls.nvim.
This plugin gives me a string with the name of the installed server. I would like to automatically enable all builtins for that server. When testing if there exists a formatter, code_action etc using:

if null_ls.builtins.formatting[source_name] ~= nil then
    null_ls.register(null_ls.builtins.formatting[source_name])
end

I get a warning if the server does not support formatting.
Is there a way to test if this builtin does exist?
If not could this be implemented?

Thanks for your Help.

Help

Yes, but I don't know how to start. I would need guidance

Implementation help

No response

@DoeringChristian DoeringChristian added the enhancement New feature or request label Oct 16, 2022
@jose-elias-alvarez
Copy link
Owner

Sorry, I'm not sure I understand the request. Don't the source names from mason-null-ls match the source names here?

@DoeringChristian
Copy link
Author

They do but when indexing the builtin tables to lookup weather that source does exist and the source does not it generates a warning here.

@jose-elias-alvarez
Copy link
Owner

Right, so if the names match, then what is the issue? At what point do you access a built-in that doesn't exist?

The existing warning is important to prevent issues caused by typos, and I'd be hesitant to add a method for such a specific use case.

@DoeringChristian
Copy link
Author

The problem is that I don't know if the source supports formatting, code_actions etc. I would need to test if the source is in builtin.formatting, builtin.code_action etc.
example.

@jose-elias-alvarez
Copy link
Owner

I see. This is something we could add here, but I think a better solution might be to have mason-null-ls pass more information than just the source's name to user-defined handlers. As you've seen, the name alone is not enough context to properly handle the source, especially since sources like ESLint have the same name but 3 different methods.

@DoeringChristian
Copy link
Author

That makes sense I think having both would be useful nonetheless. If for example the source supports something that has not yet been implemented in null-ls' bultins one could check if the "feature" exists there.

@jose-elias-alvarez
Copy link
Owner

jose-elias-alvarez commented Oct 23, 2022

I think there's some confusion about terminology here because I'm not sure what you mean by "source" (maybe Mason has its own definition?). If I understand correctly, you want to know if a given command (e.g. eslint) is supported by null-ls, and if so, you want to know which methods it supports. Is that right?

If so, it's a pretty niche use case, but it's not something that's easy to do right now, so I think we can support it.

Edit: I originally wrote an example of an approach we could use, but the issue with that approach is that the name of null-ls source doesn't always match the name of the command. Honestly I think your best solution is to copy this logic instead of indexing the builtins metatable to avoid the error.

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

No branches or pull requests

2 participants