GithubHelp home page GithubHelp logo

Format not working about efm-langserver HOT 11 CLOSED

mattn avatar mattn commented on July 17, 2024
Format not working

from efm-langserver.

Comments (11)

lukas-reineke avatar lukas-reineke commented on July 17, 2024 2

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.

gbrlsnchs avatar gbrlsnchs commented on July 17, 2024 1

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.

lukas-reineke avatar lukas-reineke commented on July 17, 2024 1

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.

mattn avatar mattn commented on July 17, 2024

I'm not familier to nvim. Anyone could you handle this?

from efm-langserver.

remi-gelinas avatar remi-gelinas commented on July 17, 2024

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.

lukas-reineke avatar lukas-reineke commented on July 17, 2024

I have prettier set up fine with Neovim's LSP.
Can you both share your config, I can take a look.

from efm-langserver.

gbrlsnchs avatar gbrlsnchs commented on July 17, 2024

@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.

remi-gelinas avatar remi-gelinas commented on July 17, 2024

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.

jrock2004 avatar jrock2004 commented on July 17, 2024

I had to go to a 1500 timeout

from efm-langserver.

bradcush avatar bradcush commented on July 17, 2024

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.

gbrlsnchs avatar gbrlsnchs commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.