From ec3135a937887a1014d49b268d1b54c1313872b7 Mon Sep 17 00:00:00 2001 From: Andre Schaf Date: Fri, 31 Oct 2025 15:17:39 +0100 Subject: [PATCH] applied lsp config --- lua/lsp.lua | 54 ++++++++++++---------- lua/lspconf/angular.lua | 69 ---------------------------- lua/lspconf/angularls.lua | 71 +++++++++++++++++++++++++++++ lua/lspconf/csharp.lua | 16 ------- lua/lspconf/intelephense.lua | 25 ++++++++++ lua/lspconf/{lua.lua => lua_ls.lua} | 6 +-- lua/lspconf/php.lua | 33 -------------- lua/lspconf/roslyn.lua | 16 +++++++ lua/plugins.lua | 1 - 9 files changed, 145 insertions(+), 146 deletions(-) delete mode 100644 lua/lspconf/angular.lua create mode 100644 lua/lspconf/angularls.lua delete mode 100644 lua/lspconf/csharp.lua create mode 100644 lua/lspconf/intelephense.lua rename lua/lspconf/{lua.lua => lua_ls.lua} (90%) delete mode 100644 lua/lspconf/php.lua create mode 100644 lua/lspconf/roslyn.lua diff --git a/lua/lsp.lua b/lua/lsp.lua index 9c4850e..d2db37f 100644 --- a/lua/lsp.lua +++ b/lua/lsp.lua @@ -1,32 +1,38 @@ -local loaded_configs = require('lspconfig.configs') -local lspconfig = require('lspconfig') -local my_config = require('lspconf') +local my_config = require("lspconf") -local function load_custom_configs() - local config_files = vim.split(vim.fn.globpath(vim.fn.stdpath('config') .. '/lua/lspconf', '*.lua', true), '\n') +local function get_custom_server_names() + local config_files = vim.split(vim.fn.globpath(vim.fn.stdpath("config") .. "/lua/lspconf", "*.lua", true), "\n") + local custom_servers = {} - for _, f in ipairs(config_files) do - local name = vim.fn.fnamemodify(f, ':t:r') - require('lspconf.' .. name) - end + for _, f in ipairs(config_files) do + local name = vim.fn.fnamemodify(f, ":t:r") + custom_servers[name] = true + end + + return custom_servers end -local function setup_default_configs() - local available_servers = require('mason-lspconfig').get_installed_servers() - local config = my_config - local excluded = { angularls = true, roslyn = true } +local function load_custom_configs() + local config_files = vim.split(vim.fn.globpath(vim.fn.stdpath("config") .. "/lua/lspconf", "*.lua", true), "\n") - for _, server in pairs(available_servers) do - if loaded_configs[server] or excluded[server] then - goto continue - end - - lspconfig[server].setup(config) - vim.lsp.config(server, config) - - ::continue:: - end + for _, f in ipairs(config_files) do + local name = vim.fn.fnamemodify(f, ":t:r") + require("lspconf." .. name) + end end load_custom_configs() -setup_default_configs() + +local available_servers = require("mason-lspconfig").get_installed_servers() +local config = my_config +local custom_servers = get_custom_server_names() +-- Always exclude these special cases +-- custom_servers.stylua = true + +for _, server in pairs(available_servers) do + if not custom_servers[server] then + vim.lsp.config(server, config) + end + + vim.lsp.enable(server) +end diff --git a/lua/lspconf/angular.lua b/lua/lspconf/angular.lua deleted file mode 100644 index 1015999..0000000 --- a/lua/lspconf/angular.lua +++ /dev/null @@ -1,69 +0,0 @@ -local lspconfig = require 'lspconfig' - --- Angular requires a node_modules directory to probe for @angular/language-service and typescript --- in order to use your projects configured versions. --- This defaults to the vim cwd, but will get overwritten by the resolved root of the file. -local function get_probe_dir(root_dir) - local project_root = vim.fs.dirname(vim.fs.find('node_modules', { path = root_dir, upward = true })[1]) - - return project_root and (project_root .. '/node_modules') or '' -end - -local function get_angular_core_version(root_dir) - local project_root = vim.fs.dirname(vim.fs.find('node_modules', { path = root_dir, upward = true })[1]) - - if not project_root then - return '' - end - - local package_json = project_root .. '/package.json' - if not vim.uv.fs_stat(package_json) then - return '' - end - - local contents = io.open(package_json):read '*a' - local json = vim.json.decode(contents) - if not json.dependencies then - return '' - end - - local angular_core_version = json.dependencies['@angular/core'] - - angular_core_version = angular_core_version and angular_core_version:match('%d+%.%d+%.%d+') - - return angular_core_version -end - -local default_probe_dir = get_probe_dir(vim.fn.getcwd()) -local default_angular_core_version = get_angular_core_version(vim.fn.getcwd()) - -local cmd = { - 'node', - '--max-old-space-size=8192', - vim.fn.exepath('ngserver'), - '--stdio', - '--tsProbeLocations', - default_probe_dir, - '--ngProbeLocations', - default_probe_dir, - '--angularCoreVersion', - default_angular_core_version, -} - -local config = { - cmd = cmd, - on_new_config = function(new_config,new_root_dir) - new_config.cmd = cmd - end, - on_attach = function() - for _, server in ipairs(vim.lsp.get_clients()) do - if server.name == "ts_ls" then - local tsserver = vim.lsp.get_client_by_id(server.id) - tsserver.server_capabilities.renameProvider = false - end - end - end -} - -lspconfig.angularls.setup(config) - diff --git a/lua/lspconf/angularls.lua b/lua/lspconf/angularls.lua new file mode 100644 index 0000000..89104db --- /dev/null +++ b/lua/lspconf/angularls.lua @@ -0,0 +1,71 @@ +-- Angular requires a node_modules directory to probe for @angular/language-service and typescript +-- in order to use your projects configured versions. +-- This defaults to the vim cwd, but will get overwritten by the resolved root of the file. +local function get_probe_dir(root_dir) + local project_root = vim.fs.dirname(vim.fs.find("node_modules", { path = root_dir, upward = true })[1]) + + return project_root and (project_root .. "/node_modules") or "" +end + +local function get_angular_core_version(root_dir) + local project_root = vim.fs.dirname(vim.fs.find("node_modules", { path = root_dir, upward = true })[1]) + + if not project_root then + return "" + end + + local package_json = project_root .. "/package.json" + if not vim.uv.fs_stat(package_json) then + return "" + end + + local contents = io.open(package_json):read("*a") + local json = vim.json.decode(contents) + if not json.dependencies then + return "" + end + + local angular_core_version = json.dependencies["@angular/core"] + + angular_core_version = angular_core_version and angular_core_version:match("%d+%.%d+%.%d+") + + return angular_core_version +end + +local default_probe_dir = get_probe_dir(vim.fn.getcwd()) +local default_angular_core_version = get_angular_core_version(vim.fn.getcwd()) + +local cmd = { + 'node', + '--max-old-space-size=8192', + vim.fn.exepath('ngserver'), + '--stdio', + '--tsProbeLocations', + default_probe_dir, + '--ngProbeLocations', + default_probe_dir, + '--angularCoreVersion', + default_angular_core_version, +} + +local my_config = require("lspconf") + +local config = { + cmd = cmd, + on_new_config = function(new_config, new_root_dir) + new_config.cmd = cmd + end, + on_attach = function(client, bufnr) + my_config.on_attach(client, bufnr) + for _, server in ipairs(vim.lsp.get_clients()) do + if server.name == "ts_ls" then + local tsserver = vim.lsp.get_client_by_id(server.id) + tsserver.server_capabilities.renameProvider = false + end + end + end, + capabilities = my_config.capabilities, +} + +vim.lsp.config("angularls", config) + diff --git a/lua/lspconf/csharp.lua b/lua/lspconf/csharp.lua deleted file mode 100644 index 92183d9..0000000 --- a/lua/lspconf/csharp.lua +++ /dev/null @@ -1,16 +0,0 @@ -local my_config = require('lspconf') - -vim.lsp.config("roslyn", { - on_attach = my_config.on_attach, - capabilities = my_config.capabilities, - settings = { - ["csharp|inlay_hints"] = { - csharp_enable_inlay_hints_for_implicit_object_creation = true, - csharp_enable_inlay_hints_for_implicit_variable_types = true, - }, - ["csharp|code_lens"] = { - - dotnet_enable_references_code_lens = true, - }, - }, -}) diff --git a/lua/lspconf/intelephense.lua b/lua/lspconf/intelephense.lua new file mode 100644 index 0000000..96ec7f7 --- /dev/null +++ b/lua/lspconf/intelephense.lua @@ -0,0 +1,25 @@ + local my_config = require('lspconf') + + vim.lsp.config('intelephense', { + cmd = { 'intelephense', '--stdio' }, + filetypes = { 'php' }, + root_dir = function(fname) + return vim.loop.cwd() + end, + on_attach = my_config.on_attach, + capabilities = my_config.capabilities, + settings = { + intelephense = { + files = { + maxSize = 1000000, + }, + environment = { + includePaths = { + "/home/serii/Sites/wordpress", + "/home/serii/Sites/advanced-custom-fields-pro", + "/home/serii/Sites/woocommerce" + } + } + } + } + }) \ No newline at end of file diff --git a/lua/lspconf/lua.lua b/lua/lspconf/lua_ls.lua similarity index 90% rename from lua/lspconf/lua.lua rename to lua/lspconf/lua_ls.lua index 51a883e..bb7c3bc 100644 --- a/lua/lspconf/lua.lua +++ b/lua/lspconf/lua_ls.lua @@ -1,8 +1,8 @@ -local lspconfig = require("lspconfig") local my_conf = require("lspconf") -lspconfig.lua_ls.setup({ + vim.lsp.config('lua_ls', { on_attach = my_conf.on_attach, + capabilities = my_conf.capabilities, settings = { Lua = { runtime = { @@ -28,4 +28,4 @@ lspconfig.lua_ls.setup({ }, }, }, -}) +}) \ No newline at end of file diff --git a/lua/lspconf/php.lua b/lua/lspconf/php.lua deleted file mode 100644 index cc67e03..0000000 --- a/lua/lspconf/php.lua +++ /dev/null @@ -1,33 +0,0 @@ -local lspconfig = require 'lspconfig' -local configs = require 'lspconfig.configs' - -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities.textDocument.completion.completionItem.snippetSupport = true - -if not configs.intelephense then - configs.intelephense = { - default_config = { - cmd = { 'intelephense', '--stdio' }, - filetypes = { 'php' }, - root_dir = function(fname) - return vim.loop.cwd() - end, - settings = { - intelephense = { - files = { - maxSize = 1000000, - }, - environment = { - includePaths = { - "/home/serii/Sites/wordpress", - "/home/serii/Sites/advanced-custom-fields-pro", - "/home/serii/Sites/woocommerce" - } - } - } - } - } - } -end - -lspconfig.intelephense.setup { capabilities = capabilities } diff --git a/lua/lspconf/roslyn.lua b/lua/lspconf/roslyn.lua new file mode 100644 index 0000000..1845f26 --- /dev/null +++ b/lua/lspconf/roslyn.lua @@ -0,0 +1,16 @@ +local my_config = require("lspconf") + +vim.lsp.config("roslyn", { + on_attach = my_config.on_attach, + capabilities = my_config.capabilities, + settings = { + ["csharp|inlay_hints"] = { + csharp_enable_inlay_hints_for_implicit_object_creation = true, + csharp_enable_inlay_hints_for_implicit_variable_types = true, + }, + ["csharp|code_lens"] = { + + dotnet_enable_references_code_lens = true, + }, + }, +}) \ No newline at end of file diff --git a/lua/plugins.lua b/lua/plugins.lua index 68be979..6afce57 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -123,4 +123,3 @@ for _, f in ipairs(files) do local name = vim.fn.fnamemodify(f, ":t:r") require("plugin." .. name) end -