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

Unable to get settings working on Helix editor #207

Closed
in0ni opened this issue Aug 21, 2024 · 16 comments
Closed

Unable to get settings working on Helix editor #207

in0ni opened this issue Aug 21, 2024 · 16 comments

Comments

@in0ni
Copy link

in0ni commented Aug 21, 2024

Hey, thanks for this language server, very much needed!

I will be maintaining the aur package for arch, and thinking about contributing to helix editor in terms of documenting on the wiki, and seeing about having it as one of the default lsp's for scss.

I have been unable to get the settings to work with Helix, I am using the aur package (npm 1.5.2). I know the lsp is working, as I have disabled vscode-css-language-server, and I'm able to get completion for modules (finally!!).

In particular I cannot get the following settings to work:

  • somesass.suggestFromUseOnly
  • somesass.loadPaths

I have tried various methods to configure, last syntax (not too familiar with toml) is this:

[language-server.some-sass-lsp]
command="some-sass-language-server"
args = ["--stdio"]

[language-server.some-sass-lsp.config]
somesass = { suggestFromUseOnly = true, loadPaths = ["test/"]}

I also tried variations such as:

[language-server.some-sass-lsp.config.somesass]
suggestFromUseOnly = true
loadPaths = ["test/"]

and

[[language-server.some-sass-lsp.config.somesass]]
suggestFromUseOnly = true
loadPaths = ["test/"]

For reference here are all the language server configs that come with Helix out-of-the-box: https://github.com/helix-editor/helix/blob/master/languages.toml

I have several language servers configured, and only efm-language-server with config settings -- and all works well. From my understanding the suggestFromUseOnly would avoid me getting map-get as a suggestion, if I start typing map (unless I have added it with a @use.

Lastly, and a little unrelated:

  • In your documentation, why do you mention this is meant to work with vscode-css-lsp?

Thanks much in advance!

@wkillerud
Copy link
Owner

Hey, cool that you're setting up a Helix client and aur package @in0ni 🥳

I see from the Helix docs that config is used for initialization options.

LSP initialization options

The way I'm reading that, config will be passed on the initialize lifecycle message (likely becoming initializationOptions in the message).

some-sass-language-server doesn't read settings from that message. Instead it does a request to the client for its settings in the editor and somesass "namespaces".

const somesassConfiguration: Partial<ISettings> =
await this.connection.workspace.getConfiguration("somesass");
const editorConfiguration: Partial<IEditorSettings> =
await this.connection.workspace.getConfiguration("editor");

What you want is probably to add this to your config.toml.

[somesass]
suggestFromUseOnly = true
loadPaths = ["test/"]

And then this would be (ish) what language.toml looks like.

[language-server.some-sass-language-server]
command = "some-sass-language-server"
args = ["--stdio"]

[[language]]
name = "scss"
scope = "source.scss"
injection-regex = "scss"
file-types = ["scss"]
block-comment-tokens = { start = "/*", end = "*/" }
language-servers = [ "some-sass-language-server" ]

@wkillerud
Copy link
Owner

In your documentation, why do you mention this is meant to work with vscode-css-lsp?

It's a bit of legacy, and for sure can be a bit confusing.

This whole project began as a language server that filled the gaps in VS Code. For that reason, I don't include things like completions and hover info for CSS attributes, among other things, since those shipped with the built-in CSS/SCSS/Less language features in Code.

What I mean by that line is, you probably want to run both some-sass-language-server and vscode-css-language-server at the same time. That way vscode-css handles all the CSS stuff, and some-sass handles all the extra workspace magic for SCSS.

@wkillerud
Copy link
Owner

Hmm, seems Helix is strict about what goes in config.toml – that won't work 😅

I see this PR is what introduced support for the workspace/configuration message that we use. You might have some luck digging there.

helix-editor/helix#1684

@in0ni
Copy link
Author

in0ni commented Aug 21, 2024

Hey @wkillerud, took a brief look at this -- and did some quick checking of the verbose logs. I do think the workspace/config is passed. I hope to get some time today/tomorrow to dig deeper, will keep you posted. Thanks for the links/info, they are very helpful.

@in0ni
Copy link
Author

in0ni commented Aug 22, 2024

I'm attaching a log file, that might help, I think we're getting a little closer:

  • I found out that I have to pass the keys with quotes to ensure they are properly passed (not nested)
  • Helix seems to be using workspace/didChangeConfiguration, and from what I can tell it's passing the settings properly (see below)
  • I do see the request from server to client for workspace/configuration you mentioned

From logs:

helix_lsp::transport [INFO] some-sass-lsp -> {"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"somesass.loadPaths":["web/themes/uw/theme/"],"somesass.suggestFromUseOnly":true}}}

I see you are working with didChangeConfiguration, but unfamiliar with LSP

this.connection.onDidChangeConfiguration((params) => {

Would you mind taking a quick look at the log?
helix-some-sass.log

Maybe I need to tweak how the settings are sent, let me know if I can assist with anything on my end.

@wkillerud
Copy link
Owner

wkillerud commented Sep 5, 2024

Sorry for the late reply @in0ni, I missed your last post.

That's great that the Helix language client "speaks" workspace/didChangeConfiguration 🥳 We should be close I think.

Looking at the logs, I think I see a potential issue in the message that's sent to the server.

{
  "settings": {
    "somesass.loadPaths": ["web/themes/uw/theme/"],
    "somesass.suggestFromUseOnly": true
  }
}

The server expects that somesass is an object with keys like loadPaths, suggestFromUseOnly etc.

This is the shape of the params sent by VS Code/VSCodium

{
    "settings": {
        "somesass": {
            "loadPaths": [],
            "scannerDepth": 30,
            "scannerExclude": [
                "**/.git/**",
                "**/node_modules/**",
                "**/bower_components/**"
            ],
            "scanImportedFiles": true,
            "suggestionStyle": "all",
            "suggestAllFromOpenDocument": false,
            "suggestFromUseOnly": true,
            "suggestFunctionsInStringContextAfterSymbols": " (+-*%",
            "triggerPropertyValueCompletion": false
        }
    }
}

I added a note to the docs on how you can log the messages sent by VS Code/VSCodium to the server in case you want to compare other messages.

@wkillerud
Copy link
Owner

wkillerud commented Sep 7, 2024

I tried running hx -v and the :log-open command to see. This config in languages.toml seems to work for me @in0ni

[language-server.some-sass-language-server]
command = "some-sass-language-server"
args = ["--stdio"]
config = { somesass = { suggestFromUseOnly = true, loadPaths = ["test/"], completion = { afterModule = "", beforeVariable = "" } } }

[[language]]
name = "scss"
scope = "source.scss"
injection-regex = "scss"
file-types = ["scss"]
block-comment-tokens = { start = "/*", end = "*/" }
language-servers = [ "some-sass-language-server" ]
auto-format = true
indent = { tab-width = 2, unit = "  " }

@wkillerud
Copy link
Owner

wkillerud commented Sep 7, 2024

I see the completions are a bit quirky in some cases, adding an extra . or $.

I think this is due to the grammar Helix uses for SCSS. We might be able to add some settings to the language server to work around that.

Edit: added here, available in some-sass-language-server@1.7.0:

I updated the config example above with these new settings.

@in0ni
Copy link
Author

in0ni commented Sep 7, 2024

Hey @wkillerud, saw this but have not had a change to implement and test. I will try these settings soon -- and confirm. Thank you. In terms of the bugs of extra . or $ I doubt it's the grammar being used as I have not had any issues thus far using vscode-css-language server or default completions for some time now. I should be able to test all this in the upcoming days.

Really appreciate it and look forward to finally using this lang server!

@in0ni
Copy link
Author

in0ni commented Sep 11, 2024

Hey, so have updated to 1.7.0 -- no longer see the issue with double . or $ but it seems like loadPaths is not working properly. I don't want to get ahead of myself -- will do some more testing (kinda rushed it now). Tomorrow I'll invest a little time and get back to you.

@wkillerud
Copy link
Owner

Gah, of course I missed the most important setting you were after in the handler for workspace/didChangeConfiguration 😄 Sorry about that @in0ni, fixed in 1.7.1.

@in0ni
Copy link
Author

in0ni commented Sep 17, 2024

Whooohooo! I finally see loadPath working!

I had updated to 1.7.1 -- but have not had a chance to tests (have not been working with scss and been a bit swamped). I see one bug which is I still get double $ after tabbing to auto-complete, but perhaps that is fixed in your recent release. I have to head out soon, but will update the aur, install, test and get back to you.

Thanks much, this is something I've been needing for quite some time~! I will be ensuring colleagues install as well now that I have tested (for those that have vscode).

@wkillerud
Copy link
Owner

Glad to hear that!

I'll be shipping #232 soon which makes the settings completion = { afterModule = "", beforeVariable = "" } obsolete. It replaces the current method for inserting text with a much more predictable edit. I tested it in Helix and it should at least not make things worse 😄

@wkillerud
Copy link
Owner

Version 1.8.1 is out now, which rewrites the code that has caused us some grief with auto-complete.

It makes the somesass.completion.afterModule and somesass.completion.beforeVariable settings obsolete, so they can be removed from the config.

I tested the release in Helix and completions seem to work as they should. Of course I might have missed something, so let me know if you still get weird double $ or other problems with the auto-complete.

@in0ni
Copy link
Author

in0ni commented Sep 18, 2024

Ok, aur updated -- and from initial tests, all is looking great! No more issues with double $ or ..
Once I have time, I will see about having this included in helix list of default language servers, as vscode doesn't support these useful features yet -- and updating the config section as well in their wiki. FYI this is my config:

[language-server.some-sass-lsp]
command="some-sass-language-server"
args = ["--stdio"]

[language-server.some-sass-lsp.config]
somesass = { suggestFromUseOnly = true, loadPaths = ["some/path/"] }

Nothing else is needed (well add it to the list of lang servers for scss), so you may update your docs :)

In case you're interested I have this for scss config

[[language]]
name="scss"
auto-format=true
formatter = { command = "npx", args = ["--no-install", "prettier", "--stdin-filepath ${INPUT}", "--parser", "scss"] }
language-servers = [
  "cspell",
  { name = "some-sass-lsp", except-features = ["format"] },
  { name = "vscode-css-language-server", except-features = ["format"] },
  # stylelint
  { name = "efm-langserver", except-features = ["format"] },
  { name = "emmet-ls", only-features = ["completion"] },
]

Thanks much!

@wkillerud
Copy link
Owner

Glad to hear that! I'll close this issue now that we have it working.

Thank you for testing and doing the config work and all 🙌

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