diff --git a/doc/tags b/doc/tags deleted file mode 100644 index 687ae772..00000000 --- a/doc/tags +++ /dev/null @@ -1,3 +0,0 @@ -kickstart-is kickstart.txt /*kickstart-is* -kickstart-is-not kickstart.txt /*kickstart-is-not* -kickstart.nvim kickstart.txt /*kickstart.nvim* diff --git a/init.lua b/init.lua index 65f5ab78..8557b3ce 100644 --- a/init.lua +++ b/init.lua @@ -226,7 +226,19 @@ local function DockerFileTypeDetectionAutoCommand() }) end -DockerFileTypeDetectionAutoCommand() +local function AddDockerFilesToFiletype() + vim.filetype.add { + filename = { + ['docker-compose.yml'] = 'yaml.docker-compose', + ['docker-compose.yaml'] = 'yaml.docker-compose', + ['compose.yml'] = 'yaml.docker-compose', + ['compose.yaml'] = 'yaml.docker-compose', + }, + } +end + +-- DockerFileTypeDetectionAutoCommand() +AddDockerFilesToFiletype() -- [[ Install `lazy.nvim` plugin manager ]] -- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info diff --git a/lua/kickstart/plugins/lsp.lua b/lua/kickstart/plugins/lsp.lua index 8b7ca56d..0a653249 100644 --- a/lua/kickstart/plugins/lsp.lua +++ b/lua/kickstart/plugins/lsp.lua @@ -17,8 +17,8 @@ return { 'neovim/nvim-lspconfig', dependencies = { -- Automatically install LSPs and related tools to stdpath for Neovim - { 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants - 'williamboman/mason-lspconfig.nvim', + { 'mason-org/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants + 'mason-org/mason-lspconfig.nvim', 'WhoIsSethDaniel/mason-tool-installer.nvim', -- Useful status updates for LSP. @@ -61,52 +61,6 @@ return { -- That is to say, every time a new file is opened that is associated with -- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this -- function will be executed to configure the current buffer - local on_attach = function(_, buffr) - local kset = function(key, func, buffer, desc) - vim.keymap.set('n', key, func, { buffer = buffer, desc = 'LSP: ' .. desc }) - end - - -- Jump to the definition of the word under your cursor. - -- This is where a variable was first declared, or where a function is defined, etc. - -- To jump back, press . - kset('gd', require('telescope.builtin').lsp_definitions, buffr, '[G]oto [D]efinition') - - -- Find references for the word under your cursor. - kset('gr', require('telescope.builtin').lsp_references, buffr, '[G]oto [R]eferences') - - -- Jump to the implementation of the word under your cursor. - -- Useful when your language has ways of declaring types without an actual implementation. - kset('gI', require('telescope.builtin').lsp_implementations, buffr, '[G]oto [I]mplementation') - - -- Jump to the type of the word under your cursor. - -- Useful when you're not sure what type a variable is and you want to see - -- the definition of its *type*, not where it was *defined*. - kset('D', require('telescope.builtin').lsp_type_definitions, buffr, 'Type [D]efinition') - - -- Fuzzy find all the symbols in your current document. - -- Symbols are things like variables, functions, types, etc. - kset('ds', require('telescope.builtin').lsp_document_symbols, buffr, '[D]ocument [S]ymbols') - - -- Fuzzy find all the symbols in your current workspace. - -- Similar to document symbols, except searches over your entire project. - kset('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, buffr, '[W]orkspace [S]ymbols') - - -- Rename the variable under your cursor. - -- Most Language Servers support renaming across files, etc. - kset('rn', vim.lsp.buf.rename, buffr, '[R]e[n]ame') - - -- Execute a code action, usually your cursor needs to be on top of an error - -- or a suggestion from your LSP for this to activate. - kset('ca', vim.lsp.buf.code_action, buffr, '[C]ode [A]ction') - - -- Opens a popup that displays documentation about the word under your cursor - -- See `:help K` for why this keymap. - kset('K', vim.lsp.buf.hover, buffr, 'Hover Documentation') - - -- WARN: This is not Goto Definition, this is Goto Declaration. - -- For example, in C this would take you to the header. - kset('gD', vim.lsp.buf.declaration, buffr, '[G]oto [D]eclaration') - end vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), @@ -222,14 +176,16 @@ return { severity_sort = true, float = { border = 'rounded', source = 'if_many' }, underline = { severity = vim.diagnostic.severity.ERROR }, - signs = vim.g.have_nerd_font and { - text = { - [vim.diagnostic.severity.ERROR] = '󰅚 ', - [vim.diagnostic.severity.WARN] = '󰀪 ', - [vim.diagnostic.severity.INFO] = '󰋽 ', - [vim.diagnostic.severity.HINT] = '󰌶 ', - }, - } or {}, + signs = vim.g.have_nerd_font + and { + text = { + [vim.diagnostic.severity.ERROR] = '󰅚 ', -- circle with cross + [vim.diagnostic.severity.WARN] = '󰀪 ', -- triangle warning + [vim.diagnostic.severity.INFO] = '󰋽 ', -- circle with i + [vim.diagnostic.severity.HINT] = '󰌶 ', -- lightbulb + }, + } + or {}, virtual_text = { source = 'if_many', spacing = 2, @@ -268,40 +224,28 @@ return { -- You can add other tools here that you want Mason to install -- for you, so that they are available from within Neovim. -- require('mason-tool-installer').setup { ensure_installed = ensure_installed } + -- INFO: Using my own utils function instead of mason-lspconfig as it checks if the stuff is already installed -- outside of mason. This is useful for NixOS setup where mason version just doesn't work sometimes due to libc issues. - -- We take the languages configured for a given profile -- Given the profile we take the LSPs configured for the languages -- Then we guarantee use or install the LSPs - local languages = require('utils.profile').Languages() - local languageServers = require 'utils.languages' - local tmpTable = {} - for _, lang in ipairs(languages) do - for lsp, config in pairs(languageServers[lang]) do - tmpTable[lsp] = config - end - end - require('utils.mason').install(tmpTable, true) - local lsp = require 'lspconfig' - for server, config in pairs(tmpTable) do + local lsps = require('utils.profile').LanguageServers() + -- print(vim.inspect(lsps)) + local missing_lsps = require('utils.mason').missing(lsps) -- find missing lsps + -- print(vim.inspect(missing_lsps)) + missing_lsps = {} -- TODO: this is only for NixOS to prefer installing via nixpkgs instead of mason + + -- install the executables of the language servers that we don't already have installed locally outside of mason + require('utils.mason').install(missing_lsps) + + -- configure nvim lsp via lspconfig package for our list of lsps + local lspconfig = require 'lspconfig' + for server, config in pairs(lsps) do config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, config.capabilities or {}) - config.on_attach = on_attach - lsp[server].setup(config) + -- config.on_attach = on_attach -- we don't need this because of the events + lspconfig[server].setup(config) end - - -- require('mason-lspconfig').setup { - -- handlers = { - -- function(server_name) - -- local server = servers[server_name] or {} - -- -- This handles overriding only values explicitly passed - -- -- by the server configuration above. Useful when disabling - -- -- certain features of an LSP (for example, turning off formatting for tsserver) - -- server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) - -- require('lspconfig')[server_name].setup(server) - -- end, - -- }, - -- } end, }, -- Show LSP explorer of functions and classes etc. diff --git a/lua/utils/languages.lua b/lua/utils/languages.lua index 1cf829e7..68d503f6 100644 --- a/lua/utils/languages.lua +++ b/lua/utils/languages.lua @@ -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 = {...}, diff --git a/lua/utils/mappings/lsp_to_cmd.lua b/lua/utils/mappings/lsp_to_cmd.lua new file mode 100644 index 00000000..285db917 --- /dev/null +++ b/lua/utils/mappings/lsp_to_cmd.lua @@ -0,0 +1 @@ +-- TODO: move lsp_config_name -> executable mapping here instead of being part of languages.lua file diff --git a/lua/utils/mason.lua b/lua/utils/mason.lua index 4ad6c2a8..321f62be 100644 --- a/lua/utils/mason.lua +++ b/lua/utils/mason.lua @@ -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 + 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 - -- 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 + -- 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 : {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) diff --git a/lua/utils/profile.lua b/lua/utils/profile.lua index a92ffcf7..edaad0fc 100644 --- a/lua/utils/profile.lua +++ b/lua/utils/profile.lua @@ -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 = {} -- -> {} + 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