From 12b89714dcd563e16f32941f4a41fdb507313541 Mon Sep 17 00:00:00 2001 From: nigel barink Date: Mon, 23 Sep 2024 10:38:23 +0200 Subject: [PATCH] Moved lsp configurations per language to ftplugins folder --- lua/barink/after/ftplugin/asm.lua | 3 ++ lua/barink/after/ftplugin/bash.lua | 3 ++ lua/barink/after/ftplugin/cpp.lua | 20 ++++++++ lua/barink/after/ftplugin/go.lua | 5 +- lua/barink/after/ftplugin/java.lua | 6 +++ lua/barink/after/ftplugin/javascript.lua | 3 ++ lua/barink/after/ftplugin/lua.lua | 15 +++++- lua/barink/after/ftplugin/python.lua | 6 +++ lua/barink/after/ftplugin/rust.lua | 6 +++ lua/barink/after/ftplugin/zig.lua | 6 +++ lua/barink/plugins/lsp.lua | 60 +----------------------- 11 files changed, 72 insertions(+), 61 deletions(-) create mode 100644 lua/barink/after/ftplugin/asm.lua create mode 100644 lua/barink/after/ftplugin/bash.lua create mode 100644 lua/barink/after/ftplugin/cpp.lua create mode 100644 lua/barink/after/ftplugin/javascript.lua create mode 100644 lua/barink/after/ftplugin/python.lua create mode 100644 lua/barink/after/ftplugin/rust.lua create mode 100644 lua/barink/after/ftplugin/zig.lua diff --git a/lua/barink/after/ftplugin/asm.lua b/lua/barink/after/ftplugin/asm.lua new file mode 100644 index 0000000..47b5fa9 --- /dev/null +++ b/lua/barink/after/ftplugin/asm.lua @@ -0,0 +1,3 @@ +require('lspconfig')['asm_lsp'].setup({ + capabilities = capabilities +}) diff --git a/lua/barink/after/ftplugin/bash.lua b/lua/barink/after/ftplugin/bash.lua new file mode 100644 index 0000000..3f180eb --- /dev/null +++ b/lua/barink/after/ftplugin/bash.lua @@ -0,0 +1,3 @@ +require('lspconfig')['bashls'].setup({ + capabilities = capabilities +}) diff --git a/lua/barink/after/ftplugin/cpp.lua b/lua/barink/after/ftplugin/cpp.lua new file mode 100644 index 0000000..89f95d7 --- /dev/null +++ b/lua/barink/after/ftplugin/cpp.lua @@ -0,0 +1,20 @@ +local root_files = { + 'premake5.lua', + '.clang-tidy', + '.clang-format', + 'compile_commands', + 'compile_commands.json', + 'compile_flags.txt', + 'configure.ac', + '.git' +} +local util = require('lspconfig.util') +require('lspconfig')['clangd'].setup({ + capabilities = capabilities, + filetypes= { 'c', 'cpp', 'objc', 'objcpp', 'cuda', 'proto' }, + cmd = { 'clangd' }, + single_file_support = true, + root_dir = function (fname) + return util.root_pattern(unpack(root_files))(fname) + end +}) diff --git a/lua/barink/after/ftplugin/go.lua b/lua/barink/after/ftplugin/go.lua index 39d684f..f2b9ec0 100644 --- a/lua/barink/after/ftplugin/go.lua +++ b/lua/barink/after/ftplugin/go.lua @@ -1,5 +1,8 @@ +require('lspconfig')['gopls'].setup({ + capabilities = capabilities +}) + local dap = require("dap") -print("You opened a Golang file") dap.adapters.delve = { type = 'server', diff --git a/lua/barink/after/ftplugin/java.lua b/lua/barink/after/ftplugin/java.lua index 4b73cc1..7d9fd91 100644 --- a/lua/barink/after/ftplugin/java.lua +++ b/lua/barink/after/ftplugin/java.lua @@ -12,3 +12,9 @@ local config = { require('jdtls').start_or_attach(config) require('jdtls').setup_dap({hotcodreplace='auto'}) require('jdtls.dap').setup_dap_main_class_configs() + +-- Set up lspconfig. +local capabilities = require('cmp_nvim_lsp').default_capabilities() +require('lspconfig')['jdtls'].setup({ + capabilities = capabilities +}) diff --git a/lua/barink/after/ftplugin/javascript.lua b/lua/barink/after/ftplugin/javascript.lua new file mode 100644 index 0000000..42a249f --- /dev/null +++ b/lua/barink/after/ftplugin/javascript.lua @@ -0,0 +1,3 @@ +require('lspconfig')['tsserver'].setup({ + capabilities = capabilities +}) diff --git a/lua/barink/after/ftplugin/lua.lua b/lua/barink/after/ftplugin/lua.lua index fef868a..a6bf0bc 100644 --- a/lua/barink/after/ftplugin/lua.lua +++ b/lua/barink/after/ftplugin/lua.lua @@ -1 +1,14 @@ -print("You opened a LUA file..") + + +local lsp = require("lspconfig") +lsp.lua_ls.setup({ + capabilities = require('cmp_nvim_lsp').default_capabilities(), + settings = { + Lua = { + diagnostics = { + globals = { 'vim' } + } + } + } +}) + diff --git a/lua/barink/after/ftplugin/python.lua b/lua/barink/after/ftplugin/python.lua new file mode 100644 index 0000000..d29246c --- /dev/null +++ b/lua/barink/after/ftplugin/python.lua @@ -0,0 +1,6 @@ +-- Set up lspconfig. +local capabilities = require('cmp_nvim_lsp').default_capabilities() + +require('lspconfig')['pyright'].setup({ + capabilities = capabilities +}) diff --git a/lua/barink/after/ftplugin/rust.lua b/lua/barink/after/ftplugin/rust.lua new file mode 100644 index 0000000..ef610b1 --- /dev/null +++ b/lua/barink/after/ftplugin/rust.lua @@ -0,0 +1,6 @@ +-- Set up lspconfig. +local capabilities = require('cmp_nvim_lsp').default_capabilities() + +require('lspconfig')['rust_analyzer'].setup({ + capabilities = capabilities +}) diff --git a/lua/barink/after/ftplugin/zig.lua b/lua/barink/after/ftplugin/zig.lua new file mode 100644 index 0000000..d4150fe --- /dev/null +++ b/lua/barink/after/ftplugin/zig.lua @@ -0,0 +1,6 @@ +-- Set up lspconfig. +local capabilities = require('cmp_nvim_lsp').default_capabilities() + +require('lspconfig')['zls'].setup({ + capabilities = capabilities +}) diff --git a/lua/barink/plugins/lsp.lua b/lua/barink/plugins/lsp.lua index 6fcdfe0..93e738f 100644 --- a/lua/barink/plugins/lsp.lua +++ b/lua/barink/plugins/lsp.lua @@ -40,9 +40,9 @@ return [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }), sources = cmp.config.sources({ - { name = 'path' }, { name = 'nvim_lsp', keyword_length = 1 }, { name = 'luasnip', option = { show_autosnippets = true}}, + { name = 'path' }, }, { { name = 'buffer', keyword_length = 2 }, }), @@ -80,17 +80,6 @@ return matching = { disallow_symbol_nonprefix_matching = false } }) - local lsp = require("lspconfig") - lsp.lua_ls.setup({ - capabilities = require('cmp_nvim_lsp').default_capabilities(), - settings = { - Lua = { - diagnostics = { - globals = { 'vim' } - } - } - } - }) local ls = require("luasnip") ls.config.set_config({ history = true, @@ -112,53 +101,6 @@ return -- Set up lspconfig. local capabilities = require('cmp_nvim_lsp').default_capabilities() - require('lspconfig')['asm_lsp'].setup({ - capabilities = capabilities - }) - local root_files = { - 'premake5.lua', - '.clang-tidy', - '.clang-format', - 'compile_commands', - 'compile_commands.json', - 'compile_flags.txt', - 'configure.ac', - '.git' - } - local util = require('lspconfig.util') - require('lspconfig')['clangd'].setup({ - capabilities = capabilities, - filetypes= { 'c', 'cpp', 'objc', 'objcpp', 'cuda', 'proto' }, - cmd = { 'clangd' }, - single_file_support = true, - root_dir = function (fname) - return util.root_pattern(unpack(root_files))(fname) - end - }) - - require('lspconfig')['zls'].setup({ - capabilities = capabilities - }) - - require('lspconfig')['rust_analyzer'].setup({ - capabilities = capabilities - }) - - require('lspconfig')['jdtls'].setup({ - capabilities = capabilities - }) - - require('lspconfig')['bashls'].setup({ - capabilities = capabilities - }) - - require('lspconfig')['gopls'].setup({ - capabilities = capabilities - }) - - require('lspconfig')['tsserver'].setup({ - capabilities = capabilities - }) end }