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

Enable Metals for java files #5707

Closed

Conversation

ayoub-benali
Copy link
Contributor

It is very common in Scala projects to use java dependencies and in such context Metals should be enabled for java files.

@@ -1057,7 +1057,7 @@ source = { git = "https://github.com/UserNobody14/tree-sitter-dart", rev = "2d7f
name = "scala"
scope = "source.scala"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if I should add source.java here as well

@pascalkuthe
Copy link
Member

pascalkuthe commented Jan 27, 2023

This messes with java development. Java is it's own language with it's own languages.toml entry, tree sitter queried grammar and lsp.

Multiple languages with the same filed types causes conflicts (helix will more or less randomly decide which language to associate with a file then). Instead you can change the lsp for java in your personal config.

@the-mikedavis
Copy link
Member

This could be a recommended configuration under https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers#metals, but you would want to change the language-server configuration for the java language config entry rather than the file-types for scala because then the scala tree-sitter parser could be used on java files as Pascal says.

# ~/.config/helix/languages.toml
[[language]]
name = "java"
language-server = { command = "metals", language-id = "java" }

@pascalkuthe pascalkuthe added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 27, 2023
@ayoub-benali
Copy link
Contributor Author

Thanks for the explanation, I will update doc then https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers#metals. But regarding the proposed config in ~/.config/helix/languages.toml: would it start a new metals instance if I jump from Scala file to a Java file ? The expected behavior would be to keep the same one

@ayoub-benali
Copy link
Contributor Author

Also could the language config be done per project one #3207 is merged ?

@pascalkuthe
Copy link
Member

#3207 is only required for config.toml.
Per project language.toml settings are already possible. Just add a .helix/languages.toml folder to the root of your repository. There you can overwrite settings youw would normally add to ~/.config/languages.toml

@the-mikedavis
Copy link
Member

I'm not sure if it will spawn a new one: I think the language server registry is keyed off of language-id if I remember correctly rather than binary name so I would guess that Helix will spawn a new metals server. I don't think there's a way to tell Helix to re-use a language server across languages currently. That might be a nice improvement for front-end languages too since javascript, jsx, typescript and tsx all use the same language server configuration but for different language-id's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants