mattn / efm-langserver

General purpose Language Server
MIT License
1.36k stars 61 forks source link

use intermediate / temporary file #258

Open davidosomething opened 1 year ago

davidosomething commented 1 year ago

for markdownlint-cli it can only fix files in place (no stdin) so needs to copy current file to a temp file, apply fix, and then copy contents back

davidosomething commented 1 year ago

e.g. how null-ls creates a temporary buffer: https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/lua/null-ls/formatting.lua

chrisgrieser commented 1 year ago

yes please 🙏

There are a bunch of formatters/linters with auto-fix which do not work with stdin. Of the top of my head:

creativenull commented 1 year ago

There is some confusion here. formatStdin dictates how the input will be sent to the cli tool. Will it be from stdin? Or will it be handled externally (like pass in the filename/filepath)? This works as expected.

I think what you are referring to is to somehow control stdout that is passed back to the LSP client.

I think what is needed is something similar to lintIgnoreExitCode like formatIgnoreStdout if the cli tool does not support outputting the changes to stdout then just ignore them.

creativenull commented 1 year ago

However I don't see the LSP server like efm provide a way to channel these changes from a temp file to stdout.

I think it's the LSP client's responsibility to make sure the changes are shown if done externally just like it was done from stdout.

For vim/neovim we have :edit! to reload the buffer if the file changed outside of neovim but is kinda hacky but is the only way I know to see these changes.

mattn commented 6 months ago

Some linter/formatter command looks current directory, file name, file extension, or configuration files. So temporary file might not fix something.

chrisgrieser commented 2 weeks ago

found a workaround. Feels a bit whack, but simply cating the resulting again to get the content into stdout does work.

format-command: "markdownlint --fix '${INPUT}' ; cat '${INPUT}'"