helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
33.6k stars 2.49k forks source link

Use Helix in conjunction with MATLAB Language Server #8947

Closed SubtleMuffin closed 11 months ago

SubtleMuffin commented 11 months ago

Quick background

MathWorks published their own MATLAB language server, and it is now working with neovim (via nvim-lspconfig and mason. In the discussions under issue 4, people can compile the language server and interact with it through neovim. I tried to do the same thing with Helix, but failed. Here are my steps so far:

  1. Clone the MATLAB language server via

    git clone https://github.com/mathworks/MATLAB-language-server ~/.local/share/MATLAB-language-server
  2. Compile the package via

    cd ~/.local/share/MATLAB-language-server && npm install . && npm run package
  3. Verify that it is working via

    node out/index.js --stdio
  4. Make a short script matlab_ls as follows, mark it executable via chmod, and store it somewhere on the $PATH. Below, I am using mason installed version, but it should be the same.

#!/usr/bin/env bash
exec node "/home/$USER/.local/share/nvim/mason/packages/matlab-language-server/out/index.js" "$@"
  1. Add the following to the Helix language settings, i.e., <config_dir>/helix/languages.toml
    
    [[language]]
    name = "matlab"
    scope = "source.m"
    file-types = ["m"]
    comment-token = "%"
    shebangs = ["matlab"]
    indent = { tab-width = 2, unit = "  " }
    language-servers = ["matlab_ls"]

[language-server.matlab_ls] command = "matlab_ls" args = ["--stdio"] config = { provideFormatter = true } environment = { "installPath" = "/usr/share/matlab", "indexWorkspace" = "true", "matlabConnectionTiming" = "onStart", "telemetry" = "false" }


6. Open a `.m` file under a `git`-managed folder with `helix -v test.m`, and see if the language server is responding.

Here are the relevant log files:

1. `~/.cache/helix/helix.log`

2023-11-29T18:39:42.207 helix_vcs [INFO] file is untracked 2023-11-29T18:39:42.207 helix_vcs [INFO] failed to open diff base for /home/$USER/Documents/folder/test.m 2023-11-29T18:39:42.207 helix_lsp::client [INFO] Using custom LSP config: {"provideFormatter":true} 2023-11-29T18:39:42.207 helix_lsp::transport [INFO] matlab_ls -> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"general":{"positionEncodings":["utf-8","utf-32","utf-16"]},"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dataSupport":true,"disabledSupport":true,"isPreferredSupport":true,"resolveSupport":{"properties":["edit","command"]}},"completion":{"completionItem":{"deprecatedSupport":true,"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"snippetSupport":true,"tagSupport":{"valueSet":[1]}},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]},"inlayHint":{"dynamicRegistration":false},"publishDiagnostics":{"versionSupport":true},"rename":{"dynamicRegistration":false,"honorsChangeAnnotations":false,"prepareSupport":true},"signatureHelp":{"signatureInformation":{"activeParameterSupport":true,"documentationFormat":["markdown"],"parameterInformation":{"labelOffsetSupport":true}}}},"window":{"workDoneProgress":true},"workspace":{"applyEdit":true,"configuration":true,"didChangeConfiguration":{"dynamicRegistration":false},"didChangeWatchedFiles":{"dynamicRegistration":true,"relativePatternSupport":false},"executeCommand":{"dynamicRegistration":false},"inlayHint":{"refreshSupport":false},"symbol":{"dynamicRegistration":false},"workspaceEdit":{"documentChanges":true,"failureHandling":"abort","normalizesLineEndings":false,"resourceOperations":["create","rename","delete"]},"workspaceFolders":true}},"clientInfo":{"name":"helix","version":"23.10"},"initializationOptions":{"provideFormatter":true},"processId":33265,"rootPath":"/home/$USER/Documents/folder","rootUri":"file:///home/$USER/Documents/folder","workspaceFolders":[{"name":"folder","uri":"file:///home/$USER/Documents/folder"}]},"id":0} 2023-11-29T18:39:42.370 helix_lsp::transport [ERROR] matlab_ls err <- "(node:33293) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.\n" 2023-11-29T18:39:42.370 helix_lsp::transport [ERROR] matlab_ls err <- "(Use node --trace-deprecation ... to show where the warning was created)\n" 2023-11-29T18:39:42.372 helix_lsp::transport [INFO] matlab_ls <- {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":4,"message":"(18:39:42) matlabls: Log Directory: /tmp/matlabls_33293"}} 2023-11-29T18:39:42.372 helix_term::application [INFO] window/logMessage: LogMessageParams { typ: Log, message: "(18:39:42) matlabls: Log Directory: /tmp/matlabls_33293" } 2023-11-29T18:39:42.374 helix_lsp::transport [INFO] matlab_ls <- {"jsonrpc":"2.0","id":0,"result":{"capabilities":{"codeActionProvider":true,"completionProvider":{"triggerCharacters":[".","("," ",",","/","\"]},"definitionProvider":true,"documentFormattingProvider":true,"executeCommandProvider":{"commands":["matlabls.lint.suppress.line","matlabls.lint.suppress.file"]},"referencesProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"documentSymbolProvider":true,"textDocumentSync":2}}} 2023-11-29T18:39:42.374 helix_lsp::transport [INFO] matlab_ls <- {"capabilities":{"codeActionProvider":true,"completionProvider":{"triggerCharacters":[".","("," ",",","/","\"]},"definitionProvider":true,"documentFormattingProvider":true,"documentSymbolProvider":true,"executeCommandProvider":{"commands":["matlabls.lint.suppress.line","matlabls.lint.suppress.file"]},"referencesProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"textDocumentSync":2}} 2023-11-29T18:39:42.374 helix_lsp::transport [INFO] matlab_ls -> {"jsonrpc":"2.0","method":"initialized","params":{}} 2023-11-29T18:39:42.374 helix_lsp::transport [INFO] matlab_ls -> {"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"provideFormatter":true}}} 2023-11-29T18:39:42.374 helix_lsp::transport [INFO] matlab_ls -> {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"matlab","text":"a = 3;\n","uri":"file:///home/$USER/Documents/folder/test.m","version":0}}} 2023-11-29T18:39:42.377 helix_lsp::transport [INFO] matlab_ls <- {"jsonrpc":"2.0","id":0,"method":"client/registerCapability","params":{"registrations":[{"id":"e64ea922-6bff-4ad7-93b8-c87065e27d40","method":"workspace/didChangeConfiguration","registerOptions":{}}]}} 2023-11-29T18:39:42.377 helix_term::application [WARN] Ignoring a client/registerCapability request because dynamic capability registration is not enabled. Please report this upstream to the language server 2023-11-29T18:39:42.377 helix_lsp::transport [INFO] matlab_ls -> {"jsonrpc":"2.0","result":null,"id":0} 2023-11-29T18:39:42.377 helix_lsp::transport [INFO] matlab_ls <- {"jsonrpc":"2.0","id":1,"method":"client/registerCapability","params":{"registrations":[{"id":"50e746db-07a7-490d-96c6-0f66a6dc6519","method":"workspace/didChangeWorkspaceFolders","registerOptions":{}}]}} 2023-11-29T18:39:42.377 helix_term::application [WARN] Ignoring a client/registerCapability request because dynamic capability registration is not enabled. Please report this upstream to the language server 2023-11-29T18:39:42.377 helix_lsp::transport [INFO] matlab_ls -> {"jsonrpc":"2.0","result":null,"id":1} 2023-11-29T18:39:42.378 helix_lsp::transport [INFO] matlab_ls <- {"jsonrpc":"2.0","id":2,"method":"workspace/configuration","params":{"items":[{"section":"MATLAB"}]}} 2023-11-29T18:39:42.378 helix_lsp::transport [INFO] matlab_ls -> {"jsonrpc":"2.0","result":[null],"id":2} 2023-11-29T18:39:42.378 helix_lsp::transport [INFO] matlab_ls <- {"jsonrpc":"2.0","id":3,"method":"workspace/configuration","params":{"items":[{"section":"MATLAB"}]}} 2023-11-29T18:39:42.378 helix_lsp::transport [INFO] matlab_ls -> {"jsonrpc":"2.0","result":[null],"id":3} 2023-11-29T18:39:42.379 helix_lsp::transport [INFO] matlab_ls <- {"jsonrpc":"2.0","method":"telemetry/logdata","params":{"eventKey":"ACTIONS","data":{"action_type":"openFile","result":"1"}}} 2023-11-29T18:39:42.379 helix_lsp::transport [INFO] matlab_ls <- {"jsonrpc":"2.0","id":4,"method":"workspace/configuration","params":{"items":[{"section":"MATLAB"}]}} 2023-11-29T18:39:42.379 helix_term::application [ERROR] received malformed notification from Language Server: Unhandled 2023-11-29T18:39:42.379 helix_lsp::transport [INFO] matlab_ls -> {"jsonrpc":"2.0","result":[null],"id":4} 2023-11-29T18:39:42.384 helix_lsp::transport [ERROR] matlab_ls err <- "/home/$USER/.local/share/nvim/mason/packages/matlab-language-server/out/index.js:1\n" 2023-11-29T18:39:42.384 helix_lsp::transport [ERROR] matlab_ls err <- "" 2023-11-29T18:39:42.385 helix_lsp::transport [ERROR] matlab_ls err <- "Node.js v21.2.0\n" 2023-11-29T18:39:42.389 helix_lsp::transport [ERROR] matlab_ls err: <- StreamClosed


2. File `/tmp/matlabls_12345/languageServerLog.txt`:

(18:39:42) matlabls: Log Directory: /tmp/matlabls_33293



## What I have observed

`Helix` is able to talk to the language server just momentarily. `:lsp-workspace-command` can show two items, which are correct: `matlabls.lint.suppress.line` and `matlabls.lint.suppress.file`. However, the server is shutdown as above log shows.

Any suggestions / ideas? Thank you!
gabydd commented 11 months ago

Hmm two things does it work properly in neovim? Also the stuff under environment should be under config.matlab I think

SubtleMuffin commented 11 months ago

Thanks for the info! I can confirm that it works properly in neovim. I cannot seem to find the documentation for config.<language>. Could you please elaborate?