Comments (8)
#181 may or may not be related to this.
from efm-langserver.
Oh wait, it seems the problem only occurs when the input file does not end with a newline character.
(So the file is not a text file in the sense of POSIX)
$ cat -e main.ts
import App from './App.svelte';$
$
const app = new App({$
target: document.body,$
props: {$
name: 'world'$
}$
});$
$
export default app;
When the input file has a newline character at the EOF when opening the file on neovim, it works without problem.
When the file lacks the newline character at the EOF when opening the file on neovim, the issue occurs.
Note that when I open the file and save the file immediately, the issue occurs despite the fact that the input file is now with a newline character at the EOF.
from efm-langserver.
do you set noeol
?
from efm-langserver.
It seems it is on by default. I set nothing related to EOL.
from efm-langserver.
Hmm, formatting does not modify outputs.
from efm-langserver.
I have the same issue. Did anyone find a suitable solution yet?
from efm-langserver.
I dug a little deeper today and hope I can provide additional information:
The problem only occurs for me when Prettier needs to change the last line, e.g. with semicolons required in JS:
export const test = () => {}
results in
export const test = () => {};
<-- newline here
This is the corresponding log:
2024/01/23 08:55:40 jsonrpc2: --> notif: textDocument/didChange: {"textDocument":{"version":55,"uri":"file:test.js"},"contentChanges":[{"text":"export const test = () =\u003e {}\n"}]}
2024/01/23 08:55:40 jsonrpc2: <-- notif: textDocument/publishDiagnostics: {"uri":"file:test.js","diagnostics":[],"version":55}
2024/01/23 08:55:45 jsonrpc2: --> request #14: textDocument/formatting: {"textDocument":{"uri":"file:test.js"},"options":{"insertSpaces":true,"tabSize":2}}
2024/01/23 08:55:46 eslint_d --fix-to-stdout --stdin --stdin-filename test.js:
2024/01/23 08:55:46 jsonrpc2: <-- result #14: textDocument/formatting: [{"range":{"start":{"line":0,"character":0},"end":{"line":1,"character":0}},"newText":""},{"range":{"start":{"line":1,"character":0},"end":{"line":1,"character":0}},"newText":"export const test = () =\u003e {};\n"}]
2024/01/23 08:55:46 jsonrpc2: --> notif: textDocument/didChange: {"textDocument":{"version":56,"uri":"file:test.js"},"contentChanges":[{"text":"export const test = () =\u003e {}\nexport const test = () =\u003e {};\n\n"}]}
2024/01/23 08:55:46 jsonrpc2: --> notif: textDocument/didChange: {"textDocument":{"version":57,"uri":"file:test.js"},"contentChanges":[{"text":"export const test = () =\u003e {};\n\n"}]}
2024/01/23 08:55:46 jsonrpc2: --> notif: textDocument/didSave: {"textDocument":{"uri":"file:test.js"}}
2024/01/23 08:55:46 jsonrpc2: <-- notif: textDocument/publishDiagnostics: {"uri":"file:test.js","diagnostics":[],"version":57}
2024/01/23 08:55:46 jsonrpc2: <-- notif: textDocument/publishDiagnostics: {"uri":"file:test.js","diagnostics":[],"version":57}
On the other hand
const x = 0
export const test = () => {};
correctly results in
const x = 0;
export const test = () => {};
log:
2024/01/23 08:58:42 jsonrpc2: --> notif: textDocument/didChange: {"textDocument":{"version":74,"uri":"file:test.js"},"contentChanges":[{"text":"const x = 0\nexport const test = () =\u003e {};\n"}]}
2024/01/23 08:58:42 jsonrpc2: <-- notif: textDocument/publishDiagnostics: {"uri":"file:test.js","diagnostics":[],"version":74}
2024/01/23 08:58:45 jsonrpc2: --> request #16: textDocument/formatting: {"textDocument":{"uri":"file:test.js"},"options":{"insertSpaces":true,"tabSize":2}}
2024/01/23 08:58:45 eslint_d --fix-to-stdout --stdin --stdin-filename test.js:
2024/01/23 08:58:45 jsonrpc2: <-- result #16: textDocument/formatting: [{"range":{"start":{"line":0,"character":0},"end":{"line":1,"character":0}},"newText":""},{"range":{"start":{"line":1,"character":0},"end":{"line":1,"character":0}},"newText":"const x = 0;\n"}]
2024/01/23 08:58:45 jsonrpc2: --> notif: textDocument/didChange: {"textDocument":{"version":75,"uri":"file:test.js"},"contentChanges":[{"text":"const x = 0\nconst x = 0;\nexport const test = () =\u003e {};\n"}]}
2024/01/23 08:58:45 jsonrpc2: --> notif: textDocument/didChange: {"textDocument":{"version":76,"uri":"file:test.js"},"contentChanges":[{"text":"const x = 0;\nexport const test = () =\u003e {};\n"}]}
2024/01/23 08:58:45 jsonrpc2: --> notif: textDocument/didSave: {"textDocument":{"uri":"file:test.js"}}
2024/01/23 08:58:45 jsonrpc2: <-- notif: textDocument/publishDiagnostics: {"uri":"file:test.js","diagnostics":[],"version":76}
2024/01/23 08:58:46 jsonrpc2: <-- notif: textDocument/publishDiagnostics: {"uri":"file:test.js","diagnostics":[],"version":76}
Please let me know if I can help any further in investigating.
This is the relevant part of my nvim config btw in case someone wants to try to reproduce this:
-- init.lua
local formatting_lsps = {
'efm',
}
local filter = function(client)
for _, lsp in pairs(formatting_lsps) do
if client.name == lsp then
return true
end
end
return false
end
local common_on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({
bufnr = bufnr,
filter = filter,
})
end,
})
end
end
-- efm
local eslint = {
lintCommand = "eslint_d --format unix --stdin --stdin-filename ${INPUT}",
lintIgnoreExitCode = true,
lintStdin = true,
lintFormats = {"%f:%l:%c: %m"},
formatCommand = "eslint_d --fix-to-stdout --stdin --stdin-filename ${INPUT}",
formatStdin = true,
rootMarkers = {
'.eslintrc',
'.eslintrc.cjs',
'.eslintrc.js',
'.eslintrc.json',
'.eslintrc.yaml',
'.eslintrc.yml',
'package.json',
},
}
local prettier = {
formatCanRange = true,
formatCommand = "prettierd ${INPUT} ${--range-start=charStart} ${--range-end=charEnd}",
formatStdin = true,
rootMarkers = {
'.prettierrc',
'.prettierrc.json',
'.prettierrc.js',
'.prettierrc.yml',
'.prettierrc.yaml',
'.prettierrc.json5',
'.prettierrc.mjs',
'.prettierrc.cjs',
'.prettierrc.toml',
},
}
nvim_lsp.efm.setup{
cmd = { "efm-langserver", "-logfile", "efm.log", "-loglevel", "5" },
on_attach = common_on_attach,
init_options = {documentFormatting = true},
settings = {
rootMarkers = {".git/"},
languages = {
javascript = {
prettier,
eslint,
},
},
filetypes = {
'javascript',
}
}
I was running efm version 0.0.44
and have now updated to 0.0.49
. I'll let you know if this changes anything.
from efm-langserver.
FWIW: This issue is also happening to me when using efm with helix.
This is my config:
# languages.toml
[language-server.efm]
command = "efm-langserver"
[language-server.efm.config]
documentFormatting = true
[language-server.efm.config.languages]
css = [
{ formatCommand ="prettierd --stdin-filepath ${INPUT}", formatStdin = true },
{ lintCommand = "stylelint_d --stdin --stdin-filename ${INPUT} --formatter compact", lintIgnoreExitCode = true, lintStdin = true, lintFormats = [ "%f: line %l, col %c, %tarning - %m", "%f: line %l, col %c, %trror - %m" ], formatCommand = "stylelint_d --fix --stdin-filename ${INPUT}", formatStdin = true, rootMarkers = [ ".stylelintrc", ".stylelintrc.json", "stylelint.config.js", "stylelint.config.cjs", "stylelint.config.mjs", "stylelint.config.ts" ] },
]
[[language]]
name = "css"
scope = "source.css"
language-servers = [ "efm" ]
auto-format = true
from efm-langserver.
Related Issues (20)
- There's no way to actually use the default value of `InitializationOptions` (inferred from the config file) since the zero value is false (that is, you must manually specify all the specs of the `InitializeOptions` in the lsp client) HOT 1
- [Question] How to inject combination of variables in flag? HOT 2
- Language with .(dot) in the name for neovim lsp HOT 2
- skip lint request if rootMarker not found HOT 1
- feature request - add way to filter by filename is in root path
- use intermediate / temporary file HOT 5
- Don't create a force creating an `~/.config/efm-langserver` folder HOT 2
- `json` config isn't working HOT 2
- How to configure codeactions? HOT 5
- Cannot work in termux (workaround is to build `efm` with `GOOS=android`)
- Prettier in efm-langserver seems to be ignoring my tsx files HOT 3
- New --line-ranges optin for black HOT 1
- PHP issue
- feature: support %-G HOT 2
- Need more clear errors instead of "format for LanguageID not supported" HOT 1
- Will not work properly if the path contains brackets
- When "lint-on-save", also lint when document is first opened HOT 1
- prettier: formatter is executed even if rootMarkers have no match HOT 2
- More markdownlint rules triggered from CLI than from efm
- Text edits which have the same start position are reversed HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from efm-langserver.