mattn / efm-langserver

General purpose Language Server
MIT License
1.32k stars 59 forks source link

Prettier in efm-langserver seems to be ignoring my tsx files #269

Closed Teajey closed 8 months ago

Teajey commented 8 months ago

efm-langserver seems to be ignoring my tsx files (running under Helix)

2023-11-22T18:13:25.954 helix_lsp::transport [INFO] efm-lsp-prettier -> {"jsonrpc":"2.0","method":"textDocument/formatting","params":{"options":{"insertSpaces":true,"tabSize":2},"textDocument":{"uri":"file:///Users/<REDACTED>/Account.tsx"}},"id":1}
2023-11-22T18:13:25.955 helix_lsp::transport [INFO] efm-lsp-prettier <- {"id":1,"result":null,"jsonrpc":"2.0"}
2023-11-22T18:13:25.955 helix_lsp::transport [INFO] efm-lsp-prettier <- null

Here's my config

[language-server.efm-lsp-prettier]
command = "efm-langserver"
args = [ "-logfile", "efmlog", "-loglevel", "2" ]
[language-server.efm-lsp-prettier.config]
documentFormatting = true
[[language-server.efm-lsp-prettier.config.languages.typescript]]
formatCommand ="yarn workspace foo prettier --stdin-filepath ${INPUT}"
formatStdin = true
[[language-server.efm-lsp-prettier.config.languages.css]]
formatCommand ="yarn workspace foo prettier --stdin-filepath ${INPUT}"
formatStdin = true
[[language-server.efm-lsp-prettier.config.languages.scss]]
formatCommand ="yarn workspace foo prettier --stdin-filepath ${INPUT}"
formatStdin = true
[[language-server.efm-lsp-prettier.config.languages.html]]
formatCommand ="yarn workspace foo prettier --stdin-filepath ${INPUT}"
formatStdin = true

Formatting's working for all other languages listed. Is there a [[language-server.efm-lsp-prettier.config.languages.tsx]] section that I need to add? I tried it, but couldn't see any difference.

Does efm-langserver treat ts and tsx as the same language, or seperate?

I tried to delve into efm-langserver's code https://github.com/mattn/efm-langserver/blob/d3104d56a6b7af42d81852965c9778e5cf9ec6b9/langserver/lsp.go#L90 But couldn't figure out where it gets the languageId from if Helix doesn't send it, as seen in the above Helix logs.

I tried getting some more info with args = [ "-logfile", "efmlog", "-loglevel", "2" ]. The efmlog file is created, but stays empty...

I swear it was working fine for me last week and I didn't change anything, so I've no idea what I broke 😤

FWIW here's my language settings for Helix ```toml [[language]] name = "typescript" language-servers = [ { name = "efm-lsp-prettier", only-features = [ "format" ] }, "typescript-language-server", "eslint" ] auto-format = true [[language]] name = "tsx" language-servers = [ { name = "efm-lsp-prettier", only-features = [ "format" ] }, "typescript-language-server", "eslint" ] auto-format = true [[language]] name = "css" language-servers = [ { name = "efm-lsp-prettier", only-features = [ "format" ] }, "vscode-css-language-server" ] auto-format = true [[language]] name = "scss" language-servers = [ { name = "efm-lsp-prettier", only-features = [ "format" ] }, "vscode-css-language-server" ] auto-format = true [[language]] name = "html" language-servers = [ { name = "efm-lsp-prettier", only-features = [ "format" ] }, "vscode-html-language-server" ] auto-format = true ```
mattn commented 8 months ago

Apart from the lsp configuration you need to put the efm-langserver configuration file config.yaml.

Teajey commented 8 months ago

I'm confused about why I also need a base configuration file when I have already configured Helix to send efm-langserver a configuration:

documentFormatting: true
languages:
  typescript:
    - formatCommand: yarn workspace foo prettier --stdin-filepath ${INPUT}
      formatStdin: true
  css:
    - formatCommand: yarn workspace foo prettier --stdin-filepath ${INPUT}
      formatStdin: true
  scss:
    - formatCommand: yarn workspace foo prettier --stdin-filepath ${INPUT}
      formatStdin: true
  html:
    - formatCommand: yarn workspace foo prettier --stdin-filepath ${INPUT}
      formatStdin: true

Edit: I tried duplicating this config in $HOME/.config/efm-langserver/config.yaml but haven't noticed a difference except that I no longer see this line in Helix's logs:

-- 2023-11-24T09:49:57.028 helix_lsp::transport [ERROR] efm-lsp-prettier err <- "2023/11/24 09:49:57 efm-langserver: no configuration file\n"
   2023-11-24T09:49:57.029 helix_lsp::transport [ERROR] efm-lsp-prettier err <- "2023/11/24 09:49:57 efm-langserver: reading on stdin, writing on stdout\n"

I don't think providing this base config is the problem because last week I was able to format tsx files with efm-langserver just fine without one. Something's changed since then and I'm just blind as to what it is.

Thank you for your response, mattn, btw

Teajey commented 8 months ago

I got it working. I added this at $HOME/.config/efm-langserver/config.yaml

version: 2
log-file: /Users/thomas/.logs/efm-langserver
log-level: 1

And found this in the logs:

2023/11/24 10:22:39 format for LanguageID not supported: typescriptreact

So I just needed to add this to my Helix config

[[language-server.efm-lsp-prettier.config.languages.typescriptreact]]
formatCommand ="yarn workspace iot-ex prettier --stdin-filepath ${INPUT}"
formatStdin = true

I feel like this should've worked when I set the log file via commandline args

I tried getting some more info with args = [ "-logfile", "efmlog", "-loglevel", "2" ]. The efmlog file is created, but stays empty...

But maybe that was a problem with my Helix config