applied lsp config
This commit is contained in:
parent
ad2f7805d1
commit
ec3135a937
9 changed files with 145 additions and 146 deletions
48
lua/lsp.lua
48
lua/lsp.lua
|
|
@ -1,32 +1,38 @@
|
||||||
local loaded_configs = require('lspconfig.configs')
|
local my_config = require("lspconf")
|
||||||
local lspconfig = require('lspconfig')
|
|
||||||
local my_config = require('lspconf')
|
|
||||||
|
|
||||||
local function load_custom_configs()
|
local function get_custom_server_names()
|
||||||
local config_files = vim.split(vim.fn.globpath(vim.fn.stdpath('config') .. '/lua/lspconf', '*.lua', true), '\n')
|
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
|
for _, f in ipairs(config_files) do
|
||||||
local name = vim.fn.fnamemodify(f, ':t:r')
|
local name = vim.fn.fnamemodify(f, ":t:r")
|
||||||
require('lspconf.' .. name)
|
custom_servers[name] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return custom_servers
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setup_default_configs()
|
local function load_custom_configs()
|
||||||
local available_servers = require('mason-lspconfig').get_installed_servers()
|
local config_files = vim.split(vim.fn.globpath(vim.fn.stdpath("config") .. "/lua/lspconf", "*.lua", true), "\n")
|
||||||
local config = my_config
|
|
||||||
local excluded = { angularls = true, roslyn = true }
|
|
||||||
|
|
||||||
for _, server in pairs(available_servers) do
|
for _, f in ipairs(config_files) do
|
||||||
if loaded_configs[server] or excluded[server] then
|
local name = vim.fn.fnamemodify(f, ":t:r")
|
||||||
goto continue
|
require("lspconf." .. name)
|
||||||
end
|
|
||||||
|
|
||||||
lspconfig[server].setup(config)
|
|
||||||
vim.lsp.config(server, config)
|
|
||||||
|
|
||||||
::continue::
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
load_custom_configs()
|
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
|
||||||
|
|
|
||||||
|
|
@ -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)
|
|
||||||
|
|
||||||
71
lua/lspconf/angularls.lua
Normal file
71
lua/lspconf/angularls.lua
Normal file
|
|
@ -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)
|
||||||
|
|
||||||
|
|
@ -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,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
25
lua/lspconf/intelephense.lua
Normal file
25
lua/lspconf/intelephense.lua
Normal file
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
local lspconfig = require("lspconfig")
|
|
||||||
local my_conf = require("lspconf")
|
local my_conf = require("lspconf")
|
||||||
|
|
||||||
lspconfig.lua_ls.setup({
|
vim.lsp.config('lua_ls', {
|
||||||
on_attach = my_conf.on_attach,
|
on_attach = my_conf.on_attach,
|
||||||
|
capabilities = my_conf.capabilities,
|
||||||
settings = {
|
settings = {
|
||||||
Lua = {
|
Lua = {
|
||||||
runtime = {
|
runtime = {
|
||||||
|
|
@ -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 }
|
|
||||||
16
lua/lspconf/roslyn.lua
Normal file
16
lua/lspconf/roslyn.lua
Normal file
|
|
@ -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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
@ -123,4 +123,3 @@ for _, f in ipairs(files) do
|
||||||
local name = vim.fn.fnamemodify(f, ":t:r")
|
local name = vim.fn.fnamemodify(f, ":t:r")
|
||||||
require("plugin." .. name)
|
require("plugin." .. name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue