Comments (11)
I think your timeout for formatting_sync
is just too short, everything else looks fine.
The default is 100 milliseconds, which is really low.
If I set it to a second (lua vim.lsp.buf.formatting_sync({}, 1000)
) your config works for me.
from efm-langserver.
I have prettier set up fine with Neovim's LSP.
Can you both share your config, I can take a look.
Hi @lukas-reineke, thanks for your help. My config is more or less the following (I'm omitting some non-related things):
local nvim_lsp = require('lspconfig')
local on_attach = function(client)
if client.resolved_capabilities.document_formatting then
vim.cmd [[augroup lsp_formatting]]
vim.cmd [[autocmd!]]
vim.cmd [[autocmd BufWritePre <buffer> :lua vim.lsp.buf.formatting_sync()]]
vim.cmd [[augroup END]]
end
end
local efm_formatters = {
prettier = {
formatCommand = './node_modules/.bin/prettier',
rootMarkers = {'package.json'},
},
}
nvim_lsp.efm.setup({
on_attach = on_attach,
cmd = {'efm-langserver', '-logfile', '/tmp/efm.log', '-loglevel', '5'},
init_options = {
documentFormatting = true,
},
filetypes = {'typescript', 'typescriptreact'},
settings = {
rootMarkers = {'.git/'},
languages = {
typescript = {efm_formatters.prettier},
typescriptreact = {efm_formatters.prettier},
},
},
})
nvim_lsp.tsserver.setup({
on_attach = function(client)
client.resolved_capabilities.document_formatting = false
on_attach(client)
end,
})
from efm-langserver.
Both async and sync formatting work fine for me except the input passed to prettier in this case is only what's been saved so running the formatting before save ends up replacing the entire buffer with and saving the file without any changes. Am I missing something to have the unsaved contents of the buffer used? My setup is a bit different but quite similar to the above, I'm just using a config file with efm instead.
Please open a new issue, this is not related to the original issue here.
Also, most likely your issue is a mistake in the configuration. It does not matter to EFM if the buffer is saved or not.
from efm-langserver.
I'm not familier to nvim. Anyone could you handle this?
from efm-langserver.
Just chiming in to say that I'm have the exact same problem, but with loglevel
at 10, I don't get any events or requests for textDocument/formatting
in the logfile at all. It's like efm
doesn't even attempt to reformat anything. I can confirm the document formatting capability and prettier command are both correct in when workspace/didChangeConfiguration
is sent though.
from efm-langserver.
I have prettier set up fine with Neovim's LSP.
Can you both share your config, I can take a look.
from efm-langserver.
@lukas-reineke That might be it then. All formatters worked fine with the default timeout, so it never crossed my mind efm + prettier needed a higher value. Thank you very much!
from efm-langserver.
Odd - I took the setup from @gbrlsnchs's config, and I now see the event populating in the efm log, and the response coming back. Immediately after I get the response though, the request seems to get cancelled:
2021/02/10 10:55:14 jsonrpc2 handler: notification "$/cancelRequest" handling error: jsonrpc2: code -32601 message: method not supported: $/cancelRequest
I'm using the one second timeout you suggested @lukas-reineke - maybe it's still not enough?
EDIT: After trying several, it seems the minimum timeout that allows formatting to work for me is 2.5 seconds - weird that it's so much longer :/
from efm-langserver.
I had to go to a 1500 timeout
from efm-langserver.
Both async and sync formatting work fine for me except the input passed to prettier in this case is only what's been saved so running the formatting before save ends up replacing the entire buffer with and saving the file without any changes. Am I missing something to have the unsaved contents of the buffer used? My setup is a bit different but quite similar to the above, I'm just using a config file with efm instead.
from efm-langserver.
Both async and sync formatting work fine for me except the input passed to prettier in this case is only what's been saved so running the formatting before save ends up replacing the entire buffer with and saving the file without any changes. Am I missing something to have the unsaved contents of the buffer used? My setup is a bit different but quite similar to the above, I'm just using a config file with efm instead.
Yeah, I have noticed that too. Other LSP servers like rust-analyzer format unsaved buffer correctly. It might be worth opening a new issue in order to specifically track that issue.
from efm-langserver.
Related Issues (20)
- Filetypes empty with "nim" files and formatting doesn't work
- Unexpected newline at the end of file when formatting it HOT 8
- Latest release 0.0.45 does not have binary assets HOT 1
- 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
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.