Giter VIP home page Giter VIP logo

lsp-setup.nvim's Introduction

lsp-setup.nvim

A simple wrapper for nvim-lspconfig and mason-lspconfig (optional) to easily setup LSP servers.

Installation

  • Neovim >= 0.8 (>= 0.10 or nightly for inlay hints)
  • nvim-lspconfig
  • mason.nvim & mason-lspconfig.nvim (optional)
{
    'junnplus/lsp-setup.nvim',
    dependencies = {
        'neovim/nvim-lspconfig',
        'williamboman/mason.nvim', -- optional
        'williamboman/mason-lspconfig.nvim', -- optional
    },
}
use {
    'junnplus/lsp-setup.nvim',
    requires = {
        'neovim/nvim-lspconfig',
        'williamboman/mason.nvim', -- optional
        'williamboman/mason-lspconfig.nvim', -- optional
    }
}

Usage

require('lsp-setup').setup({
    servers = {
        pylsp = {},
        clangd = {}
    }
})

You can replace pylsp with the LSP server name you need, see available LSPs.

Also support installing custom versions of LSP servers (requires mason and mason-lspconfig), for example:

require('lsp-setup').setup({
    servers = {
        ['rust_analyzer@nightly'] = {}
    }
})

LSP servers returns a table will automatically setup server process using lspconfig. You can also pass a nil function to setup the server manually, see Integrations/rust-tools.nvim.

Inlay hints

Inlay hints are only available in Neovim >= 0.10 or nightly.

require('lsp-setup').setup({
    inlay_hints = {
        enabled = true,
    }
})
typescript-language-server https://github.com/typescript-language-server/typescript-language-server#inlay-hints-textdocumentinlayhint
require('lsp-setup').setup({
    servers = {
        tsserver = {
            settings = {
                typescript = {
                    inlayHints = {
                        includeInlayParameterNameHints = 'all',
                        includeInlayParameterNameHintsWhenArgumentMatchesName = false,
                        includeInlayFunctionParameterTypeHints = true,
                        includeInlayVariableTypeHints = true,
                        includeInlayVariableTypeHintsWhenTypeMatchesName = false,
                        includeInlayPropertyDeclarationTypeHints = true,
                        includeInlayFunctionLikeReturnTypeHints = true,
                        includeInlayEnumMemberValueHints = true,
                    }
                },
            }
        },
    }
})
vue-language-server
require('lsp-setup').setup({
    servers = {
        volar = {
            settings = {
                typescript = {
                    inlayHints = {
                        enumMemberValues = {
                            enabled = true,
                        },
                        functionLikeReturnTypes = {
                            enabled = true,
                        },
                        propertyDeclarationTypes = {
                            enabled = true,
                        },
                        parameterTypes = {
                            enabled = true,
                            suppressWhenArgumentMatchesName = true,
                        },
                        variableTypes = {
                            enabled = true,
                        },
                    }
                },
            }
        }
    }
})
gopls https://github.com/golang/tools/blob/master/gopls/doc/inlayHints.md
require('lsp-setup').setup({
    servers = {
        gopls = {
            settings = {
                gopls = {
                    hints = {
                        rangeVariableTypes = true,
                        parameterNames = true,
                        constantValues = true,
                        assignVariableTypes = true,
                        compositeLiteralFields = true,
                        compositeLiteralTypes = true,
                        functionTypeParameters = true,
                    },
                },
            },
        },
    }
})
rust-analyzer https://github.com/simrat39/rust-tools.nvim/wiki/Server-Configuration-Schema
require('lsp-setup').setup({
    servers = {
        rust_analyzer = {
            settings = {
                ['rust-analyzer'] = {
                    inlayHints = {
                        bindingModeHints = {
                            enable = false,
                        },
                        chainingHints = {
                            enable = true,
                        },
                        closingBraceHints = {
                            enable = true,
                            minLines = 25,
                        },
                        closureReturnTypeHints = {
                            enable = 'never',
                        },
                        lifetimeElisionHints = {
                            enable = 'never',
                            useParameterNames = false,
                        },
                        maxLength = 25,
                        parameterHints = {
                            enable = true,
                        },
                        reborrowHints = {
                            enable = 'never',
                        },
                        renderColons = true,
                        typeHints = {
                            enable = true,
                            hideClosureInitialization = false,
                            hideNamedConstructor = false,
                        },
                    }
                },
            },
        },
    }
})
lua-language-server https://github.com/LuaLS/lua-language-server/wiki/Settings#hint
require('lsp-setup').setup({
    servers = {
        lua_ls = {
            settings = {
                Lua = {
                    hint = {
                        enable = false,
                        arrayIndex = "Auto",
                        await = true,
                        paramName = "All",
                        paramType = true,
                        semicolon = "SameLine",
                        setType = false,
                    },
                },
            },
        },
    }
})
zls https://github.com/zigtools/zls
require('lsp-setup').setup({
    servers = {
        zls = {
            settings = {
                zls = {
                    enable_inlay_hints = true,
                    inlay_hints_show_builtin = true,
                    inlay_hints_exclude_single_argument = true,
                    inlay_hints_hide_redundant_param_names = false,
                    inlay_hints_hide_redundant_param_names_last_token = false,
                }
            }
        },
    }
})

Setup structure

require('lsp-setup').setup({
    -- Default mappings
    -- gD = 'lua vim.lsp.buf.declaration()',
    -- gd = 'lua vim.lsp.buf.definition()',
    -- gt = 'lua vim.lsp.buf.type_definition()',
    -- gi = 'lua vim.lsp.buf.implementation()',
    -- gr = 'lua vim.lsp.buf.references()',
    -- K = 'lua vim.lsp.buf.hover()',
    -- ['<C-k>'] = 'lua vim.lsp.buf.signature_help()',
    -- ['<space>rn'] = 'lua vim.lsp.buf.rename()',
    -- ['<space>ca'] = 'lua vim.lsp.buf.code_action()',
    -- ['<space>f'] = 'lua vim.lsp.buf.formatting()',
    -- ['<space>e'] = 'lua vim.diagnostic.open_float()',
    -- ['[d'] = 'lua vim.diagnostic.goto_prev()',
    -- [']d'] = 'lua vim.diagnostic.goto_next()',
    default_mappings = true,
    -- Custom mappings, will overwrite the default mappings for the same key
    -- Example mappings for telescope pickers:
    -- gd = 'lua require"telescope.builtin".lsp_definitions()',
    -- gi = 'lua require"telescope.builtin".lsp_implementations()',
    -- gr = 'lua require"telescope.builtin".lsp_references()',
    mappings = {},
    -- Global on_attach
    on_attach = function(client, bufnr)
        -- Support custom the on_attach function for global
        -- Formatting on save as default
        require('lsp-setup.utils').format_on_save(client)
    end,
    -- Global capabilities
    capabilities = vim.lsp.protocol.make_client_capabilities(),
    -- Configuration of LSP servers 
    servers = {
        -- Install LSP servers automatically (requires mason and mason-lspconfig)
        -- LSP server configuration please see: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
        -- pylsp = {},
        -- rust_analyzer = {
        --     settings = {
        --         ['rust-analyzer'] = {
        --             cargo = {
        --                 loadOutDirsFromCheck = true,
        --             },
        --             procMacro = {
        --                 enable = true,
        --             },
        --         },
        --     },
        -- },
    },
    -- Configuration of LSP inlay hints
    inlay_hints = {
        enabled = false,
        highlight = 'Comment',
    }
})

Integrations

If installed, will auto advertise capabilities to LSP servers.

-- Setup lua_ls with neodev
require('neodev').setup()
require('lsp-setup').setup({
    servers = {
        lua_ls = {}
    }
})
require('lsp-setup').setup({
    servers = {
        rust_analyzer = function()
            require('rust-tools').setup({
                server = {
                    settings = {
                        ['rust-analyzer'] = {
                            cargo = {
                                loadOutDirsFromCheck = true,
                            },
                            procMacro = {
                                enable = true,
                            },
                        },
                    },
                },
            })
            -- no need to return anything
        end,
    }
})

Contributing

Bug reports and feature requests are welcome! PRs are doubly welcome!

lsp-setup.nvim's People

Contributors

anchorite avatar darwinsenior avatar guigui64 avatar junaire avatar junnplus avatar khuedoan avatar mandlm avatar thisduck avatar tisnku avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

lsp-setup.nvim's Issues

neodev instead of lua-dev

The config below:

local settings = {
    servers = {
        sumneko_lua = require('lua-dev').setup(),
    },
}
require('lsp-setup').setup(settings)

Then open .lua file, prompt message:

You're using the old way of setting up neodev (previously lua-dev). Please check the docs at https://github.com/folke/neodev.nvim#-setup

received `end` message with no corresponding `begin`

Hi, I'm having this issue with rust-analyzer where when I open a Rust file I get the error message LSP[rust_analyzer] received `end` message with no corresponding `begin` .
If I then run :LspStart it goes back to work normally.

I get a similar issue in Julia with julials where I need to explicitly start the LSP server, but I don't receive any error messages.

A minimal config that causes this is

require 'nvim-lsp-setup'.setup {
	servers = {
		julials = {}, -- FIX:
		rust_analyzer = {
			settings = {
				['rust_analyzer'] = {
					cargo = {
						loadOutDirsFromCheck = true
					},
					procMacro = {
						enable = true
					}
				}
			}
		}
	}
}

Mappings don't get applied for rust_analyzer

First off thanks for the great plugin! It really simplifies the LSP experience for neovim.

I'm having an issue where my mappings aren't getting set when rust_analyzer attaches to a buffer. They work fine for all the other language servers I have configured.

This is my config for lsp-setup:

require('lsp-setup').setup({
  default_mappings = false,
  mappings = {
    gd = 'Telescope lsp_definitions',
    gD = 'lua vim.lsp.buf.declaration()',
    gT = 'Telescope lsp_type_definitions',
    gr = 'Telescope lsp_references',
    gI = 'Telescope lsp_implementations',
    gR = 'lua vim.lsp.buf.rename()',
    ga = 'lua vim.lsp.buf.code_action()',
    gs = 'Telescope lsp_document_symbols',
    gS = 'Telescope lsp_dynamic_workspace_symbols',
    gx = 'LspRestart',
    go = 'SymbolsOutline',
    K = 'lua vim.lsp.buf.hover()',
  },
  on_attach = function(client)
    if client.name ~= 'null-ls' then
      client.server_capabilities.documentFormattingProvider = false
    end
  end,
  servers = {
    astro = {},
    emmet_ls = {},
    gopls = {
      flags = {
        debounce_text_changes = 300,
      },
    },
    rust_analyzer = {
      settings = {
        ['rust-analyzer'] = {
          cargo = {
            buildScripts = {
              enable = true,
            },
          },
        },
      },
    },
    sumneko_lua = {
      settings = {
        Lua = {
          runtime = {
            version = 'LuaJIT',
          },
          diagnostics = {
            globals = { 'vim', 's', 't', 'i', 'c', 'fmt', 'fmta' },
          },
          workspace = {
            library = vim.api.nvim_get_runtime_file('', true),
          },
        },
      },
    },
    tsserver = {
      flags = {
        debounce_text_changes = 300,
      },
    },
  },
})

LspInfo shows that rust_analyzer has successfully attached to the buffer:

 Language client log: ~/.local/state/nvim/lsp.log
 Detected filetype:   rust
 
 2 client(s) attached to this buffer: 
 
 Client: rust_analyzer (id: 1, pid: nil, bufnr: [1, 36, 18])
 	filetypes:       rust
 	autostart:       true
 	root directory:  ~/src/gallery
 	cmd:             rust-analyzer
 
 Client: null-ls (id: 2, pid: 5001, bufnr: [1, 47, 18, 36])
 	filetypes:       python, go, css, astro, rust, lua, luau, tf, terraform
 	autostart:       false
 	root directory:  ~/src/gallery
 	cmd:             <function>

Calling the functions manually works fine too:

image

warning and error on save

warning and error on save

[LSP] Format request failed, no matching language servers.
vim.lsp.buf.formatting_sync is deprecated. Use vim.lsp.buf.format instead
"/d/xxxxx/main.go" [noeol] 40L, 1072B written

LSP broken

Install on new machine, or run update plugin on old machine will make LSP malfunction. It seems the problem come from the last commit. If I checkout the the previous commit then reload editor, everything is good again

Accessing client.resolved_capabilities is deprecated

Please switch to client.server_capabilities

[LSP] Accessing client.resolved_capabilities is deprecated, update your plugins or configuration to access client.server_capabilities instead.The new key/value pairs in server_capabilities directly match those defined in the language server protocol

rust-analyzer not attached to buffer on windows

Hi there, thanks for the plugin. I found the bug that rust lsp cannot load. If I do a fresh reinstall using :MasonInstall rust-analyzer, it can be loaded immediately. If I quit nvim and reopen the project, it will not load.

Another workaround is to do a manual setup of rust-analyzer using require('lsp-config').rust_analyzer.setup() and remove rust from lsp-setup.nvim.

Open the main.rs in the project, rust lsp cannot load.

image
image

Reinstall rust-analyzer using mason, lsp can be loaded.

image

key mappings doesn't work?

Hi there, I tried different ways to configure keymaps, unfortunately, none of them works:

default_mappings = true,
mappings = {
        gl = 'lua vim.diagnostic.open_float()',
        gr = 'lua vim.lsp.buf.definition()',
        gd = 'lua require"telescope.builtin".lsp_definitions()',
}
default_mappings = false,
mappings = {
        gl = 'lua vim.diagnostic.open_float()',
        gr = 'lua vim.lsp.buf.definition()',
        gd = 'lua require"telescope.builtin".lsp_definitions()',
}

can you guys give me some hints on what could go wrong?

ps, even default keymappings don't work either, for instance, 'gi' just goes to insert mode instead of goto implementation.

Broken on windows

Hi, since you moved the module to nvim-lsp-setup, the package is broken on windows, because it cannot link to the lsp-setup directory, and the init.lua requires lsp-setup.utils

sumneko_lua is deprecated, use lua_ls instead. See :h deprecated

Started getting this error in Neovim 0.8.3, changing to lua_ls gives another error saying lua_ls is not known:

sumneko_lua is deprecated, use lua_ls instead. See :h deprecated
This function will be removed in lspconfig version 0.2.0
stack traceback:
        .../.local/share/nvim/lazy/nvim-lspconfig/lua/lspconfig.lua:41: in function '__index'
        ...al/share/nvim/lazy/lsp-setup.nvim/lua/lsp-setup/init.lua:67: in function <...al/share/nvim/lazy/lsp-setup.nvim/lua/lsp-setup/init.lua:61>
        [C]: in function 'pcall'
        ...m/lazy/mason-lspconfig.nvim/lua/mason-lspconfig/init.lua:59: in function 'fn'
        ...l/share/nvim/lazy/mason.nvim/lua/mason-core/optional.lua:91: in function 'if_present'
        ...m/lazy/mason-lspconfig.nvim/lua/mason-lspconfig/init.lua:57: in function 'fn'
        .../nvim/lazy/mason.nvim/lua/mason-core/functional/list.lua:98: in function 'each'
        ...m/lazy/mason-lspconfig.nvim/lua/mason-lspconfig/init.lua:67: in function 'setup_handlers'
        ...al/share/nvim/lazy/lsp-setup.nvim/lua/lsp-setup/init.lua:60: in function 'setup'
        /Users/pedro/.config/nvim/lua/plugins/lsp-setup.lua:168: in function 'config'
        ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:318: in function <...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:316>
        [C]: in function 'xpcall'
        .../.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/util.lua:110: in function 'try'
        ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:333: in function 'config'
        ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:301: in function '_load'
        ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:179: in function 'load'
        ...hare/nvim/lazy/lazy.nvim/lua/lazy/core/handler/event.lua:33: in function <...hare/nvim/lazy/lazy.nvim/lua/lazy/core/handler/event.lua:26>

pylsp will start even if it is not configured

local settings = {
    servers = {
        pyright = {},
    },
}
require('lsp-setup').setup(settings)

The config use pyright only, then open .py file, prompt warning: Spawning language server with cmd: pylsp failed. The language server is either not installed, missing from PATH, or not executable.

Why does pylsp start even without configuration?

format api变更导致报错

require('lsp-setup.utils').format_on_save(client) 这个函数的实现需要修改一下
formatting_sync api被更改了vim.lsp.buf.formatting_sync({}, 1000)

Issue with cmp

Hi, I recently wanted to switch from CoC to the native lsp and I figured I would use your plugin since I really like the philosophy it proposes.

I'm having issues setting up the completion.
As far as I understood, I need a plugin like cmp-nvim-lsp for that, so I added it to the requirements

use {
	'junnplus/nvim-lsp-setup',
	requires = {
		'neovim/nvim-lspconfig',
		'williamboman/nvim-lsp-installer',
		'hrsh7th/cmp-nvim-lsp'
	},
	config = function () require 'plugins.nvim-lsp-setup' end
}

then I run :PackerSync and added the capabilities to the plugin setup

local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require 'cmp_nvim_lsp'.update_capabilities(capabilities)

require 'nvim-lsp-setup'.setup {
	capabilities = capabilities,
	servers = {
		clojure_lsp = {}
	}
}

Now every time I enter Insert mode I get the following error messages

Error detected while processing InsertEnter Autocommands for "*":
E5108: Error executing lua ...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:165: Vim(echomsg):E114: Missing quote: "Error in packer_compiled: ...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:110: Vim(lua): E5108: Error executing lua ...pack/packer/start/cmp-nvim-lsp/lua/cmp_nvim_lsp/init.lua:48: module 'cmp' not found:
stack traceback:
        [C]: in function 'cmd'
        ...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:165: in function <...m/site/pack/packer/start/packer.nvim/packer/load.lua:161>
        [string ":lua"]:1: in main chunk
Error detected while processing InsertEnter Autocommands for "*":
E5108: Error executing lua ...pack/packer/start/cmp-nvim-lsp/lua/cmp_nvim_lsp/init.lua:48: module 'cmp' not found:
        no field package.preload['cmp']
        no file './cmp.lua'
        no file '/usr/share/luajit-2.1.0-beta3/cmp.lua'
        no file '/usr/local/share/lua/5.1/cmp.lua'
        no file '/usr/local/share/lua/5.1/cmp/init.lua'
        no file '/usr/share/lua/5.1/cmp.lua'
        no file '/usr/share/lua/5.1/cmp/init.lua'
        no file '/home/sicro/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/cmp.lua'
        no file '/home/sicro/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/cmp/init.lua'
        no file '/home/sicro/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/cmp.lua'
        no file '/home/sicro/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/cmp/init.lua'
        no file './cmp.so'
        no file '/usr/local/lib/lua/5.1/cmp.so'
        no file '/usr/lib64/lua/5.1/cmp.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file '/home/sicro/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/cmp.so'
stack traceback:
        [C]: in  function 'require'
        ...pack/packer/start/cmp-nvim-lsp/lua/cmp_nvim_lsp/init.lua:48: in function '_on_insert_enter'
        [string ":lua"]:1: in main chunk

From :PackerStatus I can see that cmp-nvim-lsp is indeed installed on ~/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp. If I uninstall cmp-nvim-lsp the error stops showing up.

What am I doing wrong?

Question: Add `desc` parameter to mappings

Hi, thanks for this plugin, it makes my init.lua much nicer.

I apologize in advance if this is a silly question, I'm new to neovim.

Inspired by kickstart.nvim, I set mappings like this:

vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { buffer = bufnr, desc = '[G]o to [D]efinition' })

which made integration with which-key really nice.

Is there a way to achieve this simply with this plugin? Or should I just set default_mappings = false and configure it manually?

Thanks!

Custom LSPs

Hi, I was trying to config a custom Prolog LSP as I was used to in CoC.
I added these lines to my config

require 'nvim-lsp-setup'.setup {
	servers = {
		swipl = {
			cmd = {
				'swipl',
				'-g',
				'use_module(library(lsp_server)).',
				'-g',
				'lsp_server:main',
				'-t',
				'halt',
				'--',
				'stdio'
			},
			filetypes = { 'prolog' },
			settings = {}
		}
}

After doing that I receive [lspconfig] Cannot access configuration for swipl. Ensure this server is listed in `server_configurations.md` or added as a custom server.

Do you know I should make custom servers work with nvim-lsp-setup?

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.