neovim / nvim-lspconfig

Quickstart configs for Nvim LSP
Apache License 2.0
9.77k stars 2.02k forks source link

LspInfo not show border #3158

Closed xfdj closed 2 weeks ago

xfdj commented 2 weeks ago

Description

I think I have configured the border to "solid" (which I defined in require("config/options").border). But after I assign the variable as help page said require("lspconfig/ui/windows").default_options.border = require("config/options").border. LspInfo command still give a float window with border 'none'. I don't know where is wrong. Can anyone offer some help. Thanks very much. image My neovim version:

NVIM v0.10.0-dev-2135+g98a4ed0a1
Build type: RelWithDebInfo
LuaJIT 2.1.1703358377

My package manager: Lazy.nvim nvim-lspconfig commit: 94513a5 My lspconfig configuration file:

-- LSP

---@diagnostic disable-next-line: unused-local
local function on_attach(client, bufnr)
    local function bmap(lhs, rhs, desc)
        if desc then
            desc = "LSP: " .. desc
        end
        vim.keymap.set("n", lhs, rhs, { buffer = bufnr, desc = desc })
    end

    bmap("gs", vim.lsp.buf.signature_help, "[s]ignature help")
    bmap("gl", function()
        vim.diagnostic.open_float({ border = require("config/options").border })
    end, "[l]ine diagnostic")
    bmap("g=", function()
        vim.lsp.buf.format({ async = true })
    end, "[=] buffer format")
    -- use lspsaga hover instead
    -- bmap("gh", vim.lsp.buf.hover, "[h]over doc")
    bmap("gd", vim.lsp.buf.definition, "[d]efinition")
    bmap("gt", vim.lsp.buf.type_definition, "[t]ype definition")
    bmap("gr", vim.lsp.buf.references, "[r]eferences")
    bmap("gI", vim.lsp.buf.implementation, "[I]mplementation")
end

return {
    -- enable LSP
    {
        "neovim/nvim-lspconfig",
        dependencies = {
            "folke/neodev.nvim",
        },
        event = { "BufReadPre", "BufNewFile" },
        config = function()
            require("lspconfig/ui/windows").default_options.border = require("config/options").border
        end,
    },
    -- LSP installer and manager
    {
        "williamboman/mason.nvim",
        build = ":MasonUpdate", -- :MasonUpdate updates registry contents
        cmd = {
            "Mason",
            "MasonUpdate",
            "MasonInstall",
            "MasonUninstall",
            "MasonUninstallAll",
            "MasonLog",
        },
        config = function()
            require("mason").setup({
                ui = {
                    check_outdated_packages_on_open = false,
                    border = require("config/options").border,
                },
                pip = {
                    upgrade_pip = true,
                },
                github = {
                    -- download_url_template = "https://hub.njuu.cf/%s/releases/download/%s/%s",
                },
            })
        end,
    },
    -- mason-lspconfig bridges mason.nvim with the lspconfig plugin - making it easier to use both plugins together
    {
        "williamboman/mason-lspconfig.nvim",
        event = { "BufReadPre", "BufNewFile" },
        dependencies = {
            "neovim/nvim-lspconfig",
            "williamboman/mason.nvim",
            {
                "hrsh7th/cmp-nvim-lsp",
                dependencies = {
                    "hrsh7th/nvim-cmp",
                },
            },
            "b0o/schemastore.nvim", -- Providing access to the SchemaStore catalog
        },
        config = function()
            local mason_lspconfig = require("mason-lspconfig")
            mason_lspconfig.setup({
                -- mason-lspconfig uses the 'lspconfig' server names in the APIs it exposes - not 'mason.nvim' package names
                -- https://github.com/williamboman/mason-lspconfig.nvim/blob/main/doc/server-mapping.md
                ensure_installed = {
                    "clangd",
                    "jsonls",
                    "lua_ls",
                    "marksman",
                    "texlab",
                    "tsserver",
                    "vimls",
                    "sourcery",
                    "jedi_language_server",
                    "ruff_lsp",
                },
                automatic_installation = true,
            })
            local lspconfig = require("lspconfig")

            local servers = {
                lua_ls = {
                    settings = {
                        Lua = {
                            -- Tell the language server which version of Lua you're using
                            runtime = {
                                version = "LuaJIT",
                            },
                            diagnostics = {
                                -- Get the language server to recognize the 'vim' global
                                globals = { "vim" },
                            },
                            workspace = {
                                -- Make the server aware of Neovim runtime files
                                library = vim.api.nvim_get_runtime_file("", true),
                            },
                            telementary = {
                                enable = false,
                            },
                            completion = {
                                enable = true,
                                autoRequire = true,
                                showParams = true,
                                requireSeparator = "/",
                                callSnippet = "Both",
                                displayContext = 5,
                            },
                            hint = {
                                arrayIndex = "Auto",
                                enable = true,
                                setType = true,
                            },
                        },
                    },
                },
                jsonls = {
                    settings = {
                        json = {
                            -- Find more schemas here: https://www.schemastore.org/json/
                            schemas = require("schemastore").json.schemas(),
                            validate = { enable = true },
                        },
                    },
                    setup = {
                        commands = {
                            Format = {
                                function()
                                    vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line("$"), 0 })
                                end,
                            },
                        },
                    },
                    filetypes = {
                        "json",
                        "jsonc",
                        "toml",
                    },
                },
                sourcery = {
                    init_options = {
                        token = "user_yoXVvq7_oanbWjvLGUPDm6u3rL3V3kaj6xhCTgI2kq_jijd9dlz7IwbQjiA",
                        extension_version = "vim.lsp",
                        editor_version = "vim",
                    },
                },
                jedi_language_server = {
                    settings = {
                        initializationOptions = {
                            diagnostics = {
                                enable = true,
                                didOpen = true,
                                didChange = false,
                                didSave = true,
                            },
                        },
                    },
                },
            }

            local capabilities = vim.lsp.protocol.make_client_capabilities()
            capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
            capabilities = vim.tbl_deep_extend("force", capabilities, {
                offsetEncoding = { "utf-16" },
                general = {
                    positionEncodings = { "utf-16" },
                },
            })

            mason_lspconfig.setup_handlers({
                function(server_name)
                    local opts = {
                        on_attach = on_attach,
                        capabilities = capabilities,
                        bind = true,
                        handlers = {
                            ["textDocument/hover"] = vim.lsp.with(
                                vim.lsp.handlers.hover,
                                { border = require("config/options").border }
                            ),
                            ["textDocument/signatureHelp"] = vim.lsp.with(
                                vim.lsp.handlers.signature_help,
                                { border = require("config/options").border }
                            ),
                        },
                        handler_opts = {
                            border = require("config/options").border,
                        },
                        offset_encoding = "utf-16",
                    }
                    if servers[server_name] then
                        opts = vim.tbl_extend("force", opts, servers[server_name])
                    end
                    lspconfig[server_name].setup(opts)
                end,
            })
        end,
    },
    {
        "nvimtools/none-ls.nvim",
        event = { "BufReadPre", "BufNewFile" },
        dependencies = {
            "nvim-lua/plenary.nvim",
            "lewis6991/gitsigns.nvim",
            {
                "ckolkey/ts-node-action",
                dependencies = "nvim-treesitter/nvim-treesitter",
                opts = {},
            },
        },
        config = function()
            local null_ls = require("null-ls")
            -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting
            -- local formatting = null_ls.builtins.formatting
            -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics
            local diagnostics = null_ls.builtins.diagnostics
            -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/code_actions
            local code_actions = null_ls.builtins.code_actions

            null_ls.setup({
                debug = false,
                sources = {
                    -- Anything not supported by mason.
                    diagnostics.zsh,
                    code_actions.gitsigns,
                    code_actions.ts_node_action.with({
                        disabled_filetypes = { "", "text" },
                    }),
                },
                on_attach = on_attach,
                on_init = function(new_client, _)
                    new_client.offset_encoding = "utf-16"
                end,
                border = require("config/options").border,
            })
        end,
    },
    -- mason-null-ls bridges mason.nvim with the null-ls plugin - making it easier to use both plugins together.
    {
        "jay-babu/mason-null-ls.nvim",
        event = { "BufReadPre", "BufNewFile" },
        dependencies = {
            "williamboman/mason.nvim",
            "nvimtools/none-ls.nvim",
        },
        config = function()
            require("mason-null-ls").setup({
                ensure_installed = {
                    -- Opt to list sources here, when available in mason.
                    "beautysh",
                    -- "black",
                    -- "isort",
                    "clang-format",
                    "cpplint",
                    "prettier",
                    "stylua",
                },
                automatic_installation = true,
                handlers = {
                    ---@diagnostic disable-next-line: unused-local
                    stylua = function(source_name, methods)
                        local null_ls = require("null-ls")
                        null_ls.register(null_ls.builtins.formatting.stylua.with({
                            extra_args = {
                                "--indent-type=Spaces",
                            },
                        }))
                    end,
                },
            })
        end,
    },
}
glepnir commented 2 weeks ago

Please read doc first

require('lspconfig.ui.windows').default_options.border = 'single'
xfdj commented 2 weeks ago

Please read doc first

require('lspconfig.ui.windows').default_options.border = 'single'

I tried. Still not work.

glepnir commented 2 weeks ago

can't reproduce you need use minimal config for test

xfdj commented 2 weeks ago

can't reproduce you need use minimal config for test

Lots of thanks for advice. I read Minimal init.lua to Reproduce an Issue · folke/lazy.nvim Wiki and learned to test in minimal config. Finally locate the problem. It turns out that require('lspconfig.ui.windows').default_options.border = 'single' can work but require('lspconfig/ui/windows').default_options.border = 'single' cannot. But I'm still very confused about it. I didn't notice it before because I always thought "/" and "." are the same as delimiters in modname. glepnir/nvim-lua-guide-zh gave me that thought. But the result shows that they are different.

glepnir commented 2 weeks ago

The argument to a require call is a module name and not a path to a module file without a file extension. This is why the first one is broken and the second one is ok.

xfdj commented 2 weeks ago

Thanks very much!