lukas-reineke / lsp-format.nvim

A wrapper around Neovims native LSP formatting.
559 stars 27 forks source link

`vim.lsp.buf.format()` formats, but `:Format` does not #73

Closed iduuck closed 6 months ago

iduuck commented 1 year ago

I am currently developing several features for trpc, but the problem here is, that the formatting is not working for me properly. My dotfiles are at iduuck/dots.

Saw #70, but didn't help me, since the formatter is working on other projects properly (also not using null-ls here).

I will try to get a minimal repro done, but I am not sure, when...


:LspLog is the following:

[DEBUG][2023-03-21 11:55:03] .../lua/vim/lsp.lua:1381   "LSP[eslint]"   "client.request"    2   "textDocument/codeAction"   {  context = {    diagnostics = {}  },  range = {    ["end"] = <1>{      character = 0,      line = 20    },    start = <table 1>  },  textDocument = {    uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"  }}  <function 1>    17
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:285    "rpc.send"  {  id = 61,  jsonrpc = "2.0",  method = "textDocument/codeAction",  params = {    context = {      diagnostics = {}    },    range = {      ["end"] = <1>{        character = 0,        line = 20      },      start = <table 1>    },    textDocument = {      uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"    }  }}
[DEBUG][2023-03-21 11:55:03] .../lua/vim/lsp.lua:1381   "LSP[tsserver]" "client.request"    4   "textDocument/codeAction"   {  context = {    diagnostics = {}  },  range = {    ["end"] = <1>{      character = 0,      line = 20    },    start = <table 1>  },  textDocument = {    uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"  }}  <function 1>    17
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:285    "rpc.send"  {  id = 44,  jsonrpc = "2.0",  method = "textDocument/codeAction",  params = {    context = {      diagnostics = {}    },    range = {      ["end"] = <1>{        character = 0,        line = 20      },      start = <table 1>    },    textDocument = {      uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"    }  }}
[DEBUG][2023-03-21 11:55:03] .../lua/vim/lsp.lua:1381   "LSP[tailwindcss]"  "client.request"    5   "textDocument/codeAction"   {  context = {    diagnostics = {}  },  range = {    ["end"] = <1>{      character = 0,      line = 20    },    start = <table 1>  },  textDocument = {    uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"  }}  <function 1>    17
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:285    "rpc.send"  {  id = 43,  jsonrpc = "2.0",  method = "textDocument/codeAction",  params = {    context = {      diagnostics = {}    },    range = {      ["end"] = <1>{        character = 0,        line = 20      },      start = <table 1>    },    textDocument = {      uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"    }  }}
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:388    "rpc.receive"   {  id = 61,  jsonrpc = "2.0",  result = {}}
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:388    "rpc.receive"   {  id = 43,  jsonrpc = "2.0"}
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:388    "rpc.receive"   {  id = 44,  jsonrpc = "2.0",  result = {}}
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:285    "rpc.send"  {  jsonrpc = "2.0",  method = "textDocument/didSave",  params = {    textDocument = {      uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"    }  }}
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:285    "rpc.send"  {  jsonrpc = "2.0",  method = "textDocument/didSave",  params = {    textDocument = {      uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"    }  }}
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:285    "rpc.send"  {  jsonrpc = "2.0",  method = "textDocument/didSave",  params = {    textDocument = {      uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"    }  }}
[DEBUG][2023-03-21 11:55:03] .../lua/vim/lsp.lua:1381   "LSP[eslint]"   "client.request"    2   "textDocument/formatting"   {  options = {    insertSpaces = true,    tabSize = 2  },  textDocument = {    uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"  }}  <function 1>    17
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:285    "rpc.send"  {  id = 62,  jsonrpc = "2.0",  method = "textDocument/formatting",  params = {    options = {      insertSpaces = true,      tabSize = 2    },    textDocument = {      uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"    }  }}
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:388    "rpc.receive"   {  id = 62,  jsonrpc = "2.0",  result = {}}
[DEBUG][2023-03-21 11:55:03] .../lua/vim/lsp.lua:1381   "LSP[eslint]"   "client.request"    2   "textDocument/codeAction"   {  context = {    diagnostics = {}  },  range = {    ["end"] = <1>{      character = 0,      line = 20    },    start = <table 1>  },  textDocument = {    uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"  }}  <function 1>    17
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:285    "rpc.send"  {  id = 63,  jsonrpc = "2.0",  method = "textDocument/codeAction",  params = {    context = {      diagnostics = {}    },    range = {      ["end"] = <1>{        character = 0,        line = 20      },      start = <table 1>    },    textDocument = {      uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"    }  }}
[DEBUG][2023-03-21 11:55:03] .../lua/vim/lsp.lua:1381   "LSP[tsserver]" "client.request"    4   "textDocument/codeAction"   {  context = {    diagnostics = {}  },  range = {    ["end"] = <1>{      character = 0,      line = 20    },    start = <table 1>  },  textDocument = {    uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"  }}  <function 1>    17
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:285    "rpc.send"  {  id = 45,  jsonrpc = "2.0",  method = "textDocument/codeAction",  params = {    context = {      diagnostics = {}    },    range = {      ["end"] = <1>{        character = 0,        line = 20      },      start = <table 1>    },    textDocument = {      uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"    }  }}
[DEBUG][2023-03-21 11:55:03] .../lua/vim/lsp.lua:1381   "LSP[tailwindcss]"  "client.request"    5   "textDocument/codeAction"   {  context = {    diagnostics = {}  },  range = {    ["end"] = <1>{      character = 0,      line = 20    },    start = <table 1>  },  textDocument = {    uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"  }}  <function 1>    17
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:285    "rpc.send"  {  id = 44,  jsonrpc = "2.0",  method = "textDocument/codeAction",  params = {    context = {      diagnostics = {}    },    range = {      ["end"] = <1>{        character = 0,        line = 20      },      start = <table 1>    },    textDocument = {      uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"    }  }}
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:388    "rpc.receive"   {  id = 63,  jsonrpc = "2.0",  result = {}}
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:388    "rpc.receive"   {  id = 44,  jsonrpc = "2.0"}
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:388    "rpc.receive"   {  id = 45,  jsonrpc = "2.0",  result = {}}
iduuck commented 1 year ago

Just to add this: :EslintFixAll is also not working, so this might be an issue with the LSP itself (however, lsp.buf.format is indeed working?

lukas-reineke commented 1 year ago

from the logs you posted it looks like the response for the format request is empty

[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:285    "rpc.send"  {  id = 62,  jsonrpc = "2.0",  method = "textDocument/formatting",  params = {    options = {      insertSpaces = true,      tabSize = 2    },    textDocument = {      uri = "file:///Users/nick/dev/trpc/packages/client/src/createTRPCClient.ts"    }  }}
[DEBUG][2023-03-21 11:55:03] .../vim/lsp/rpc.lua:388    "rpc.receive"   {  id = 62,  jsonrpc = "2.0",  result = {}}

This is a problem with the LSP, I can't help with that, sorry.

NickHu commented 1 year ago

I have also noticed this plugin has stopped working since I switched to neovim 0.9, when vim.lsp.buf.formatting* options were removed.

iduuck commented 1 year ago

@NickHu It works for me. What is your configuration?

khjorth commented 6 months ago

:Format is broken for me too, and I suspect it's caused by #75, after which it seems necessary to supply format(options) with a map that contains the correct value for buf. I don't think the user commands have been updated to reflect this, but perhaps I'm missing something.

Formatting works if I manually call format with buf set.

But #75 was merged after the present report, so it can't be the cause of OP's issue.