Code Monkey home page Code Monkey logo

Comments (9)

Mange avatar Mange commented on June 3, 2024 2

I created a badly formatted shell script and tried to :Format it with some logging added on the previously mentioned lines. Here's what I got:

-- client.request call
{
  bufnr = 1,
  handler = <function 1>,
  method = "textDocument/formatting",
  params = {
    options = {
      insertSpaces = true,
      tabSize = 2
    },
    textDocument = {
      uri = "file:///home/mange/Projects/dotfiles/foo.sh"
    }
  }
}

-- _handler being called with
{
  ctx = {
    bufnr = 1,
    client_id = 1,
    method = "textDocument/formatting",
    params = {
      options = {
        insertSpaces = true,
        tabSize = 2
      },
      textDocument = {
        uri = "file:///home/mange/Projects/dotfiles/foo.sh"
      }
    }
  },
  err = {
    code = -32601,
    message = "Unhandled method textDocument/formatting",
    <metatable> = {
      __tostring = <function 1>
    }
  }
}

I have two LSPs for shells: bashls and null-ls. bashls does not handle formatting, so the error makes sense. However, I would expect the handler and formatting to be called again for null-ls, but there's only this one call.

I then tried disabling bashls and restarted so only null-ls was attached. If I run :Format now nothing is logged at all.

By stepping through all the conditionals I figured out that the problem was that M.buffers were empty.

…aaaand, here we are. Turns out I set up on_attach on all LSP servers but null-ls, since it was placed in a different section much further down and I forgot to check it.

So another one one the pile; misconfiguration in the PEBKAC module. πŸ˜…

from lsp-format.nvim.

lukas-reineke avatar lukas-reineke commented on June 3, 2024 1

πŸ‘
Yes the behavior changed, but I consider it a bug that this worked before.
To be used for formatting, each LSP now needs to be attached individually.
Before it used all servers once it was called for one server on the buffer.

from lsp-format.nvim.

Mange avatar Mange commented on June 3, 2024

I went to my checked out package and jumped between different versions.

It broke completely on v2.3.0, same symptoms as listed in description.

The version before it, v2.2.3 still works, but only when formatting a saved changed buffer. Running :Format on an unchanged buffer does nothing. Seems this is a separate problem.

from lsp-format.nvim.

lukas-reineke avatar lukas-reineke commented on June 3, 2024

can you make a minimal init.lua file that reproduces this?

from lsp-format.nvim.

bmulholland avatar bmulholland commented on June 3, 2024

I just tried installing for the first time and formatting using this plugin is not working for me either. Using nvim 0.7 stable, though.

from lsp-format.nvim.

bmulholland avatar bmulholland commented on June 3, 2024

Also confirm that this PR broke :Format: https://github.com/lukas-reineke/lsp-format.nvim/pull/33/files. If you've got any debug statements I can try adding to help, happy to tell you the result. I don't have time to make a minimal repro, sorry.

from lsp-format.nvim.

lukas-reineke avatar lukas-reineke commented on June 3, 2024

Alright, let's try to add some logging to debug then.

The first obvious ones are here

client.request(method, params, M._handler, bufnr)
log what is send to the server

And here

M._handler = function(err, result, ctx)
the result that comes back

from lsp-format.nvim.

bmulholland avatar bmulholland commented on June 3, 2024

I figured it out, at least for me. What has changed is the behaviour when LSP on_attach is not properly configured. The fix is to properly attach lsp-format to your LSPs. (FWIW, the requirement to do careful configuration didn't jump out at me, and I just blindly copy/pasted the default config, go and all πŸ™ˆ)

Specifically, if an LSP is missing the require("lsp-format").on_attach(client) requirement, as mine was, then on commit db45b37 autoformat will not work (and perhaps never did). :Format will, though.

The commit that "broke" :Format is actually 4ba2f95f78af8b2d4d99c8ebe32074c529101b32 (I bisected). And this makes sense, considering that commit says "Don't format with client if on_attach was not called for that client"

Thanks for your time @lukas-reineke, appreciate the debug help (and the plugin!)

from lsp-format.nvim.

bmulholland avatar bmulholland commented on June 3, 2024

I consider it a bug that this worked before

Me too :). Thanks again.

from lsp-format.nvim.

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.