mattn / efm-langserver

General purpose Language Server
MIT License
1.32k stars 59 forks source link

`json` config isn't working #264

Closed hinell closed 8 months ago

hinell commented 10 months ago
local clang_format = require("efmls-configs.formatters.clang_format")
local lua_format   = require("efmls-configs.formatters.lua_format")
local clang_tidy   = require("efmls-configs.formatters.clang_tidy")

...
-- This config is passed to lspconfig efm.setup()
config = {
    log_level = 5,
    init_options = {
        documentFormatting = true
    },

    settings = {
        rootMarkers = {
            ".git/",
        },
        languages = {
            json = {
                -- clang_format
                -- formatCommand = "clang-format -i ${INPUT}",
                formatCommand = "echo ${INPUT} > /tmp/efm-log.txt",
                formatStdin = true
            },
            lua = {
                lua_format
            },
            cpp = {
                clang_format,
                clang_tidy
            }
        }
    }
}

Hi. I'm using the config above and nothing happens when I call vim.lsp.buf.format().

I'm using lspconfig and creativenull/efmls-configs-nvim btw.

Any ideas why? Thanks.

I got the following log (same for Lua):

2023/09/29 00:49:47 lint for LanguageID not supported: json
2023/09/29 00:49:47 lint for LanguageID not supported: json
2023/09/29 00:49:54 format for LanguageID not supported: json
2023/09/29 00:49:58 lint for LanguageID not supported: json
2023/09/29 00:49:58 lint for LanguageID not supported: json
2023/09/29 00:49:58 lint for LanguageID not supported: json
2023/09/29 00:49:58 lint for LanguageID not supported: json

Version

efm-langserver 0.0.44 (rev: HEAD/go1.18.1)
NVIM v0.10.0-dev-ac1c23442f
mattn commented 10 months ago

I'm not good at neovim, anyone please help this.

hinell commented 8 months ago

SOLVED

We have to set the server version to 2 and language sub-fields should be lists:

M.config = {
    log_level = 5,
    cmd = {"/usr/bin/efm-langserver", "-logfile", "/tmp/efm.log", "-loglevel", "5"},
    filetypes = {"json", "jsx", "lua", "yaml"},
    init_options = {
        codeAction = true,
        completion = false,
        documentFormatting = true,
        documentRangeFormatting = true,
        documentSymbol = true, -- this may interfere with navic.nvim
        hover = true
    },
    settings = {
        version = 2, -- NOTE: DO NOT FORGET TO SPECIFY VERSION
        rootMarkers = {".git/"},
        languages = {
            json = {
                {
                    formatCommand = "clang-format --assume-filename=.json",
                    formatStdin = false

                }
            },
            lua = { {formatCommand = "lua-format -i", formatStdin = true} }
        }
    }
}