mattn / efm-langserver

General purpose Language Server
MIT License
1.34k stars 61 forks source link

Clangd format on save: warning: multiple different client offset_encodings detected for buffer, this is not supported yet #192

Closed pact0 closed 2 years ago

pact0 commented 2 years ago

What does this error mean? Relevant parts of the config, I am setting up efm with lsp.installer but it is manually installed with go. clang_format.lua

local command = string.format('%s ${INPUT}', "/usr/bin/clang-format")

return {formatCommand = command, formatStdin = true}
local on_attach = function(client, bufnr)
    print("LSP started.");
    if client.resolved_capabilities.document_formatting then
        vim.api.nvim_command [[augroup Format]]
        vim.api.nvim_command [[autocmd! * <buffer>]]
        vim.api
            .nvim_command [[autocmd BufWritePost <buffer> lua vim.lsp.buf.formatting_sync({},1500)]]
        vim.api.nvim_command [[augroup END]]
    end
end

local clang_format = require 'efm/clang_format'
local languages = {
    clangd = {clang_format},
    cpp = {clang_format}
}
.
.
.
        ['efm'] = function()
            default_opts = {
                root_dir = lspconfig.util.root_pattern {'.git/', '.'},
                init_options = {documentFormatting = true},
                settings = {
                    rootMarkers = {".git/", ".", "stylua.toml"},
                    languages = languages,
                    log_level = 1,
                    log_file = '~/efm.log'
                },
                filetypes = vim.tbl_keys(languages),
                on_attach = function(client)
                    client.resolved_capabilities.document_formatting = true
                    on_attach(client)
                end
            }
        end,

After :LspInfo I can see efm and clangd attached with no problems. It even seems to be formatting on save since I have efm set up to do so, but each time the error shows up and it is really annoying. Is there any way to fix this/disable the error?

pact0 commented 2 years ago

I sort of managed to "fix" this, found a workaround at least. I disabled formatting by efm and added this as a specific clangd cmd. It seems to be working, but I am still unsure about the error which I was getting earlier.

        ['clangd'] = function()
            default_opts = {
                root_dir = lspconfig.util.root_pattern("compile_commands.json",
                                                       "compile_flags.txt",
                                                       ".git") or
                    lspconfig.util.dirname,
                on_attach = function(client, bufnr)
                    client.resolved_capabilities.document_formatting = true
                    on_attach(client, bufnr)
                end,
                filetypes = {"c", "cpp", "objc", "objcpp"},
                cmd = {
                    "clangd", "--background-index", "--pch-storage=memory",
                    "--clang-tidy", "--suggest-missing-includes"
                },
                capabilities = capabilities,
                single_file_support = true
            }
        end
levouh commented 2 years ago

I am getting the same thing (on every single character I type) when using null-ls, so it is likely something that changed either with the core LSP client in Neovim (I'm using the latest nightly build) as I have not updated clangd itself in a long time @pact0.

levouh commented 2 years ago

Yea, this was added recently here (at least the vim.notify call itself)

pact0 commented 2 years ago

Okay, any idea what causes it? I am not that familiar with this code, any way to temporary fix this?

levouh commented 2 years ago

I made a kind of hacky PR and got some advice on how to do it better, see here. Basically you just manually specify the capabilities to be { "utf-16" } explicitly.

pact0 commented 2 years ago

Adding this line to the clangd's capabilities fixed the error capabilities.offsetEncoding = { "utf-16" } .