Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local util = require("util")
- -- It's worth investigating LazyVim more, to see how this works with Mason
- --https://github.com/LazyVim/LazyVim/blob/86ac9989ea15b7a69bb2bdf719a9a809db5ce526/lua/lazyvim/plugins/lsp/init.lua#L5
- ---@param useTelescopeForGoToDef boolean
- local on_attach = function(useTelescopeForGoToDef)
- return function(_, bufnr)
- local config = vim.diagnostic.config
- config({
- virtual_text = true,
- underline = true,
- signs = true,
- float = {
- source = true,
- style = "minimal",
- focusable = false,
- border = "single",
- header = "",
- prefix = "",
- },
- })
- util.nmap("<leader>rn", vim.lsp.buf.rename, "LSP: [R]e[n]ame", bufnr)
- util.nmap("<leader>ca", vim.lsp.buf.code_action, "LSP: [C]ode [A]ction", bufnr)
- if useTelescopeForGoToDef then
- util.nmap("gd", require("telescope.builtin").lsp_definitions, "LSP: [G]oto [D]efinitons", bufnr)
- else
- util.nmap("gd", vim.lsp.buf.definition, "LSP: [G]oto [D]efinitons", bufnr)
- end
- -- This maps the default C-] that jumps between ctags
- vim.api.nvim_set_keymap("n", "gd", "<C-]>", { noremap = true, silent = true })
- util.nmap("gr", require("telescope.builtin").lsp_references, "LSP: [G]oto [R]eferences", bufnr)
- util.nmap("gI", require("telescope.builtin").lsp_implementations, "LSP: [G]oto [I]mplementation", bufnr)
- util.nmap("<leader>D", require("telescope.builtin").lsp_type_definitions, "Type LSP: [D]efinition", bufnr)
- util.nmap(
- "<leader>ws",
- require("telescope.builtin").lsp_dynamic_workspace_symbols,
- "LSP: [W]orkspace [S]ymbols",
- bufnr
- )
- util.nmap("K", vim.lsp.buf.hover, "Hover Documentation")
- util.imap("<C-k>", vim.lsp.buf.signature_help, "Signature Documentation")
- util.nmap("<C-i>", vim.lsp.buf.signature_help, "Signature Documentation")
- -- Lesser used LSP functionality
- util.nmap("gD", vim.lsp.buf.declaration, "LSP: [G]oto [D]eclaration", bufnr)
- util.nmap("<leader>wa", vim.lsp.buf.add_workspace_folder, "LSP: [W]orkspace [A]dd Folder", bufnr)
- util.nmap("<leader>wr", vim.lsp.buf.remove_workspace_folder, "LSP: [W]orkspace [R]emove Folder", bufnr)
- util.nmap("<leader>wl", function()
- print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
- end, "LSP: [W]orkspace [L]ist Folders")
- vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_)
- vim.lsp.buf.format()
- end, { desc = "Format current buffer with LSP" })
- end
- end
- return {
- {
- "neovim/nvim-lspconfig",
- event = { "BufReadPre", "BufNewFile" },
- dependencies = {
- { "williamboman/mason.nvim", config = true },
- "williamboman/mason-lspconfig.nvim",
- { "j-hui/fidget.nvim", opts = {} },
- "folke/neodev.nvim",
- "p00f/clangd_extensions.nvim",
- "hrsh7th/nvim-cmp",
- "b0o/schemastore.nvim",
- },
- config = function()
- local capabilities = vim.tbl_deep_extend(
- "force",
- {},
- vim.lsp.protocol.make_client_capabilities(),
- require("cmp_nvim_lsp").default_capabilities()
- )
- -- local capabilities = require("cmp_nvim_lsp").default_capabilities()
- -- local capabilities = vim.lsp.protocol.make_client_capabilities()
- local servers = {
- lua_ls = {
- Lua = {
- format = { enable = false },
- workspace = { checkThirdParty = false },
- telemetry = { enable = false },
- diagnostics = { disable = { "missing-fields" } },
- },
- },
- rust_analyzer = {
- root_dir = vim.loop.cwd(),
- },
- html = {
- filetypes = { "html", "twig", "templ" },
- },
- yamlls = {
- filetypes = { "yaml", "yml" },
- yaml = {
- schemaStore = {
- -- You must disable built-in schemaStore support if you want to use
- -- this plugin and its advanced options like `ignore`.
- enable = false,
- -- Avoid TypeError: Cannot read properties of undefined (reading 'length')
- url = "",
- },
- schemas = require("schemastore").yaml.schemas(),
- },
- },
- jsonls = {
- filetypes = { "json" },
- json = {
- schemas = require("schemastore").json.schemas(),
- validate = { enable = true },
- },
- },
- gopls = {
- filetypes = { "go", "gomod", "gowork", "gotmpl", "template" },
- settings = {
- gopls = {
- templateExtensions = { "tmpl", "gotmpl" },
- experimentalPostfixCompletions = true,
- analyses = {
- unusedparams = true,
- shadow = true,
- },
- staticcheck = true,
- gofumpt = true,
- },
- },
- },
- -- intelephense = {
- -- cmd = { "intelephense", "--stdio" },
- -- stubs = {
- -- "apache", "bcmath", "bz2", "calendar", "com_dotnet", "Core", "ctype", "curl", "date",
- -- "dba", "dom", "enchant", "exif", "FFI", "fileinfo", "filter", "fpm", "ftp", "gd", "gettext",
- -- "gmp", "hash", "iconv", "imap", "intl", "json", "ldap", "libxml", "mbstring", "meta", "mysqli",
- -- "oci8", "odbc", "openssl", "pcntl", "pcre", "PDO", "pdo_ibm", "pdo_mysql", "pdo_pgsql", "pdo_sqlite", "pgsql",
- -- "Phar", "posix", "pspell", "readline", "Reflection", "session", "shmop", "SimpleXML", "snmp", "soap",
- -- "sockets", "sodium", "SPL", "sqlite3", "standard", "superglobals", "sysvmsg", "sysvsem", "sysvshm", "tidy",
- -- "tokenizer", "xml", "xmlreader", "xmlrpc", "xmlwriter", "xsl", "Zend OPcache", "zip", "zlib",
- -- "wordpress", "phpunit",
- -- },
- -- },
- }
- vim.lsp.set_log_level = "debug"
- -- TODO verify that nvim api is still available
- require("neodev").setup()
- -- TODO Check that java stuff is still working
- require("java").setup()
- -- TODO Verify the clangd_extensions stuff
- require("clangd_extensions").setup()
- require("mason").setup()
- local mason_lspconfig = require("mason-lspconfig")
- mason_lspconfig.setup({
- ensure_installed = vim.tbl_keys(servers),
- })
- -- We leave this here as commented if we ever need to debug issues again.
- -- Normally we will use mason for this.
- -- require 'lspconfig'.phpactor.setup {
- -- cmd = { 'phpactor', 'language-server', '-vvv' },
- -- capabilities = capabilities,
- -- on_attach = on_attach,
- -- filetypes = { 'php' },
- -- }
- --
- require("lspconfig").jdtls.setup({
- capabilities = capabilities,
- on_attach = on_attach(true),
- })
- require("lspconfig").pyright.setup({
- settings = {
- pyright = { autoImportCompletion = true },
- python = {
- analysis = { autoSearchPaths = true, diagnosticMode = "openFilesOnly", useLibraryCodeForTypes = true },
- },
- },
- capabilities = capabilities,
- on_attach = on_attach(true),
- root_dir = function(_)
- return vim.loop.cwd()
- end,
- })
- require("lspconfig").csharp_ls.setup({
- handlers = {
- ["textDocument/definition"] = require("csharpls_extended").handler,
- ["textDocument/typeDefinition"] = require("csharpls_extended").handler,
- },
- capabilities = capabilities,
- on_attach = on_attach(false),
- root_dir = function(_)
- return vim.loop.cwd()
- end,
- })
- vim.api.nvim_create_autocmd("LspAttach", {
- pattern = { "*.cs", "*.java", "*.tsx" },
- callback = function(args)
- local client = vim.lsp.get_client_by_id(args.data.client_id)
- client.server_capabilities.semanticTokensProvider = nil
- end,
- })
- require("lspconfig").tailwindcss.setup({
- capabilities = capabilities,
- on_attach = on_attach(true),
- filetypes = { "html", "templ" },
- })
- require("lspconfig").htmx.setup({
- capabilities = capabilities,
- on_attach = on_attach(true),
- filetypes = { "html", "templ" },
- })
- require("typescript-tools").setup({
- capabilities = capabilities,
- on_attach = on_attach(true),
- filetypes = {
- "javascript",
- "javascriptreact",
- "javascript.jsx",
- "typescript",
- "typescriptreact",
- "typescript.tsx",
- },
- })
- require("lspconfig").clangd.setup({
- name = "clangd",
- capabilities = capabilities,
- on_attach = on_attach(true),
- cmd = { "clangd", "--background-index", "--clang-tidy", "--log=verbose" },
- initialization_options = {
- fallback_flags = { "-std=c++17" },
- },
- })
- mason_lspconfig.setup_handlers({
- function(server_name)
- require("lspconfig")[server_name].setup({
- capabilities = capabilities,
- on_attach = on_attach(true),
- settings = servers[server_name],
- filetypes = (servers[server_name] or {}).filetypes,
- })
- end,
- ["sqlls"] = function()
- capabilities.textDocument.completion.completionItem.snippetSupport = true
- require("lspconfig").sqlls.setup({
- capabilities = capabilities,
- filetypes = { "sql" },
- root_dir = function(_)
- return vim.loop.cwd()
- end,
- })
- end,
- ["html"] = function()
- capabilities.textDocument.completion.completionItem.snippetSupport = true
- require("lspconfig").html.setup({
- capabilities = capabilities,
- on_attach = on_attach(true),
- settings = servers["html"],
- filetypes = (servers["html"] or {}).filetypes,
- })
- end,
- ["yamlls"] = function()
- capabilities.textDocument.completion.completionItem.snippetSupport = true
- require("lspconfig").yamlls.setup({
- capabilities = capabilities,
- on_attach = on_attach(true),
- settings = servers["yamlls"],
- filetypes = (servers["yamlls"] or {}).filetypes,
- })
- end,
- ["jsonls"] = function()
- capabilities.textDocument.completion.completionItem.snippetSupport = true
- require("lspconfig").jsonls.setup({
- capabilities = capabilities,
- on_attach = on_attach(true),
- settings = servers["jsonls"],
- filetypes = (servers["jsonls"] or {}).filetypes,
- })
- end,
- ["cssls"] = function()
- local capabilities = vim.lsp.protocol.make_client_capabilities()
- capabilities.textDocument.completion.completionItem.snippetSupport = true
- require("lspconfig").cssls.setup({
- capabilities = capabilities,
- on_attach = on_attach(true),
- settings = servers["cssls"],
- filetypes = { "css", "html", "svelte" },
- })
- end,
- })
- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
- -- Disable underline, it's very annoying
- underline = false,
- })
- -- [[ Configure nvim-cmp ]]
- -- See `:help cmp`
- --
- --
- local cmp = require("cmp")
- local luasnip = require("luasnip")
- luasnip.config.setup({})
- -- require("luasnip.loaders.from_vscode").lazy_load()
- -- require("luasnip.loaders.from_vscode").load {
- -- exclude = { "markdown", "c" },
- -- }
- local lspkind = require("lspkind")
- cmp.setup({
- formatting = {
- format = lspkind.cmp_format({
- mode = "symbol", -- show only symbol annotations
- maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
- -- can also be a function to dynamically calculate max width such as
- -- maxwidth = function() return math.floor(0.45 * vim.o.columns) end,
- ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
- show_labelDetails = true, -- show labelDetails in menu. Disabled by default
- -- The function below will be called before any actual modifications from lspkind
- -- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))
- before = function(entry, vim_item)
- return vim_item
- end,
- }),
- },
- snippet = {
- expand = function(args)
- luasnip.lsp_expand(args.body)
- end,
- },
- completion = {
- completeopt = "menu,menuone,noinsert",
- },
- window = {
- completion = cmp.config.window.bordered(),
- documentation = cmp.config.window.bordered(),
- },
- mapping = cmp.mapping.preset.insert({
- ["<C-n>"] = cmp.mapping.select_next_item(),
- ["<C-p>"] = cmp.mapping.select_prev_item(),
- ["<C-b>"] = cmp.mapping.scroll_docs(-4),
- ["<C-f>"] = cmp.mapping.scroll_docs(4),
- ["<C-Space>"] = cmp.mapping.complete({}),
- ["<CR>"] = cmp.mapping.confirm({
- behavior = cmp.ConfirmBehavior.Insert,
- select = true,
- }),
- ["<Tab>"] = cmp.mapping(function(fallback)
- if cmp.visible() then
- cmp.select_next_item()
- elseif luasnip.expand_or_locally_jumpable() then
- luasnip.expand_or_jump()
- else
- fallback()
- end
- end, { "i", "s" }),
- ["<S-Tab>"] = cmp.mapping(function(fallback)
- if cmp.visible() then
- cmp.select_prev_item()
- elseif luasnip.locally_jumpable(-1) then
- luasnip.jump(-1)
- else
- fallback()
- end
- end, { "i", "s" }),
- }),
- sources = {
- { name = "nvim_lsp" },
- { name = "luasnip" },
- { name = "path" },
- { name = "buffer" },
- -- { name = "dotenv" },
- },
- })
- -- This language server is still unstable so we have a more stable fork downloaded directly
- require("lspconfig").cucumber_language_server.setup({
- cmd = { "", "--stdio" },
- settings = {
- cucumber = {
- features = { "**/features/*.feature" },
- glue = { "**/step_definitions/*.ts" },
- },
- },
- on_attach = function()
- local config = vim.diagnostic.config
- config({
- virtual_text = false,
- underline = false,
- signs = false,
- })
- util.nmap("gd", vim.lsp.buf.definition, "Go to step definition", 0)
- util.nmap("gn", vim.diagnostic.goto_next, "Go to next diagnostic", 0)
- util.nmap("gb", vim.diagnostic.goto_prev, "Go to previous diagnostic", 0)
- end,
- })
- require("luasnip").filetype_extend("php", { "phpdoc" })
- require("luasnip").filetype_extend("lua", { "luadoc" })
- end,
- },
- {
- "pmizio/typescript-tools.nvim",
- lazy = true,
- dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" },
- opts = {},
- },
- {
- "hrsh7th/nvim-cmp",
- event = "InsertEnter",
- dependencies = {
- "onsails/lspkind.nvim",
- -- Snippet Engine & its associated nvim-cmp source
- "L3MON4D3/LuaSnip",
- "saadparwaiz1/cmp_luasnip",
- -- Adds LSP completion capabilities
- --
- "hrsh7th/cmp-nvim-lsp",
- "hrsh7th/cmp-path",
- "rafamadriz/friendly-snippets",
- "hrsh7th/cmp-nvim-lsp-signature-help",
- "SergioRibera/cmp-dotenv",
- },
- },
- {
- "Decodetalkers/csharpls-extended-lsp.nvim",
- },
- }
Advertisement
Add Comment
Please, Sign In to add comment