* remove doc/tags

* use cmd instead of alias for clarity

* use alias and proper checking of existing command installation

* mason pkg name override

* we still want to enforce local by default

* remove unused on_attach since we have event to control it

* fallback to using existing docker language servers

* add yaml language server + remove table setup logging

* write comment what symbol we expect

* more notes

* use mason-lspconfig for getting lsp->mason map and better utilities

* use very lazy
This commit is contained in:
peturparkur 2025-08-03 18:23:21 +02:00 committed by GitHub
parent 115243d395
commit 2985d98684
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 115 additions and 109 deletions

View file

@ -105,6 +105,31 @@ local Languages = {
alias = 'docker-compose-langserver',
},
},
['yaml'] = {
yamlls = {
alias = 'yaml-language-server',
settings = {
yaml = {
schemas = {
extra = {
-- kubernetes = 'k8s-*.yaml', -- TODO: consider using *.k8s.yaml for kubernetes schemas
['http://json.schemastore.org/github-workflow'] = '.github/workflows/*',
['http://json.schemastore.org/github-action'] = '.github/action.{yml,yaml}',
['http://json.schemastore.org/ansible-stable-2.9'] = 'roles/tasks/**/*.{yml,yaml}',
['http://json.schemastore.org/prettierrc'] = '.prettierrc.{yml,yaml}',
['http://json.schemastore.org/kustomization'] = 'kustomization.{yml,yaml}',
['http://json.schemastore.org/chart'] = 'Chart.{yml,yaml}',
['http://json.schemastore.org/circleciconfig'] = '.circleci/**/*.{yml,yaml}',
},
},
format = {
enable = true,
},
redhat = { telemetry = { enabled = false } },
},
},
},
},
['lua'] = {
lua_ls = {
-- cmd = {...},

View file

@ -0,0 +1 @@
-- TODO: move lsp_config_name -> executable mapping here instead of being part of languages.lua file

View file

@ -7,33 +7,43 @@ local name_to_bin = {
-- ['docker-compose-language-service'] = 'docker-compose-langserver',
}
-- We guarantee 'ensure_installed' package is installed locally
-- If enforce_local is false then we install it via mason-registry
-- By default we install LSPs via mason
M.install = function(ensure_installed, enforce_local)
-- Allow for passing in a single string
M.missing = function(ensure_installed)
if type(ensure_installed) == 'string' then
ensure_installed = { ensure_installed }
end
enforce_local = enforce_local == nil and false or enforce_local
-- Function to check if the executable exists in the PATH
local function executable_exists(name)
if name_to_bin[name] then
return vim.fn.executable(name_to_bin[name]) == 1
local result = {}
for lsp_name, config in pairs(ensure_installed) do
local executable_name = lsp_name
if config['alias'] then
executable_name = config['alias']
end
-- check if executable exists
if vim.fn.executable(executable_name) ~= 1 then
result[lsp_name] = config
end
return vim.fn.executable(name) == 1
end
return result
end
-- We guarantee 'ensure_installed' package is installed locally
-- If enforce_local is false then we install it via mason-registry
-- By default we install LSPs via mason
M.install = function(ensure_installed)
-- ensure installed is expected of the form <lspname>: {cmd: "", settings: {...}}
-- ensure_installed = M.missing(ensure_installed, enforce_local)
local lspconfig_to_pkg = require('mason-lspconfig').get_mappings().lspconfig_to_package
local registry = require 'mason-registry'
-- local mason_lspconfig = require 'mason-lspconfig'
registry.refresh(function()
for _, pkg_name in ipairs(ensure_installed) do
if (not executable_exists(pkg_name)) and not enforce_local then
local pkg = registry.get_package(pkg_name)
if not pkg:is_installed() then
pkg:install()
end
for lsp_cfg, _ in pairs(ensure_installed) do
local pkg_name = lspconfig_to_pkg[lsp_cfg] -- get mason package name based on lspconfig name
local pkg = registry.get_package(pkg_name)
if not pkg:is_installed() then
pkg:install()
end
end
end)

View file

@ -8,6 +8,7 @@ local PROFILES = {
'bash',
'docker',
'lua',
'yaml',
},
['DEFAULT'] = {
'python',
@ -15,13 +16,29 @@ local PROFILES = {
'bash',
'docker',
'lua',
'yaml',
},
}
local Profile = {}
Profile.Languages = function()
local profile = PROFILES[os.getenv 'NVIM_PROFILE' or 'DEFAULT']
return profile
Profile.Languages = function(profile)
if profile == nil then
profile = os.getenv 'NVIM_PROFILE' or 'DEFAULT'
end
return PROFILES[profile]
end
Profile.LanguageServers = function(profile)
local languages = Profile.Languages(profile)
local language_config = require 'utils.languages'
local result = {} -- <nvim_ls_name> -> {<configuration>}
for _, lang in ipairs(languages) do
for lsp, config in pairs(language_config[lang]) do
result[lsp] = config
end
end
return result
end
return Profile