Beta (#4)
* 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:
parent
115243d395
commit
2985d98684
3
doc/tags
3
doc/tags
|
@ -1,3 +0,0 @@
|
||||||
kickstart-is kickstart.txt /*kickstart-is*
|
|
||||||
kickstart-is-not kickstart.txt /*kickstart-is-not*
|
|
||||||
kickstart.nvim kickstart.txt /*kickstart.nvim*
|
|
14
init.lua
14
init.lua
|
@ -226,7 +226,19 @@ local function DockerFileTypeDetectionAutoCommand()
|
||||||
})
|
})
|
||||||
end
|
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 ]]
|
-- [[ Install `lazy.nvim` plugin manager ]]
|
||||||
-- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
|
-- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
|
||||||
|
|
|
@ -17,8 +17,8 @@ return {
|
||||||
'neovim/nvim-lspconfig',
|
'neovim/nvim-lspconfig',
|
||||||
dependencies = {
|
dependencies = {
|
||||||
-- Automatically install LSPs and related tools to stdpath for Neovim
|
-- Automatically install LSPs and related tools to stdpath for Neovim
|
||||||
{ 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants
|
{ 'mason-org/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants
|
||||||
'williamboman/mason-lspconfig.nvim',
|
'mason-org/mason-lspconfig.nvim',
|
||||||
'WhoIsSethDaniel/mason-tool-installer.nvim',
|
'WhoIsSethDaniel/mason-tool-installer.nvim',
|
||||||
|
|
||||||
-- Useful status updates for LSP.
|
-- 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
|
-- 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
|
-- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this
|
||||||
-- function will be executed to configure the current buffer
|
-- 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 <C-t>.
|
|
||||||
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('<leader>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('<leader>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('<leader>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('<leader>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('<leader>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', {
|
vim.api.nvim_create_autocmd('LspAttach', {
|
||||||
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
|
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
|
||||||
|
@ -222,14 +176,16 @@ return {
|
||||||
severity_sort = true,
|
severity_sort = true,
|
||||||
float = { border = 'rounded', source = 'if_many' },
|
float = { border = 'rounded', source = 'if_many' },
|
||||||
underline = { severity = vim.diagnostic.severity.ERROR },
|
underline = { severity = vim.diagnostic.severity.ERROR },
|
||||||
signs = vim.g.have_nerd_font and {
|
signs = vim.g.have_nerd_font
|
||||||
|
and {
|
||||||
text = {
|
text = {
|
||||||
[vim.diagnostic.severity.ERROR] = ' ',
|
[vim.diagnostic.severity.ERROR] = ' ', -- circle with cross
|
||||||
[vim.diagnostic.severity.WARN] = ' ',
|
[vim.diagnostic.severity.WARN] = ' ', -- triangle warning
|
||||||
[vim.diagnostic.severity.INFO] = ' ',
|
[vim.diagnostic.severity.INFO] = ' ', -- circle with i
|
||||||
[vim.diagnostic.severity.HINT] = ' ',
|
[vim.diagnostic.severity.HINT] = ' ', -- lightbulb
|
||||||
},
|
},
|
||||||
} or {},
|
}
|
||||||
|
or {},
|
||||||
virtual_text = {
|
virtual_text = {
|
||||||
source = 'if_many',
|
source = 'if_many',
|
||||||
spacing = 2,
|
spacing = 2,
|
||||||
|
@ -268,40 +224,28 @@ return {
|
||||||
-- You can add other tools here that you want Mason to install
|
-- You can add other tools here that you want Mason to install
|
||||||
-- for you, so that they are available from within Neovim.
|
-- for you, so that they are available from within Neovim.
|
||||||
-- require('mason-tool-installer').setup { ensure_installed = ensure_installed }
|
-- 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
|
-- 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.
|
-- 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
|
-- We take the languages configured for a given profile
|
||||||
-- Given the profile we take the LSPs configured for the languages
|
-- Given the profile we take the LSPs configured for the languages
|
||||||
-- Then we guarantee use or install the LSPs
|
-- Then we guarantee use or install the LSPs
|
||||||
local languages = require('utils.profile').Languages()
|
local lsps = require('utils.profile').LanguageServers()
|
||||||
local languageServers = require 'utils.languages'
|
-- print(vim.inspect(lsps))
|
||||||
local tmpTable = {}
|
local missing_lsps = require('utils.mason').missing(lsps) -- find missing lsps
|
||||||
for _, lang in ipairs(languages) do
|
-- print(vim.inspect(missing_lsps))
|
||||||
for lsp, config in pairs(languageServers[lang]) do
|
missing_lsps = {} -- TODO: this is only for NixOS to prefer installing via nixpkgs instead of mason
|
||||||
tmpTable[lsp] = config
|
|
||||||
end
|
|
||||||
end
|
|
||||||
require('utils.mason').install(tmpTable, true)
|
|
||||||
local lsp = require 'lspconfig'
|
|
||||||
for server, config in pairs(tmpTable) do
|
|
||||||
config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, config.capabilities or {})
|
|
||||||
config.on_attach = on_attach
|
|
||||||
lsp[server].setup(config)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- require('mason-lspconfig').setup {
|
-- install the executables of the language servers that we don't already have installed locally outside of mason
|
||||||
-- handlers = {
|
require('utils.mason').install(missing_lsps)
|
||||||
-- function(server_name)
|
|
||||||
-- local server = servers[server_name] or {}
|
-- configure nvim lsp via lspconfig package for our list of lsps
|
||||||
-- -- This handles overriding only values explicitly passed
|
local lspconfig = require 'lspconfig'
|
||||||
-- -- by the server configuration above. Useful when disabling
|
for server, config in pairs(lsps) do
|
||||||
-- -- certain features of an LSP (for example, turning off formatting for tsserver)
|
config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, config.capabilities or {})
|
||||||
-- server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
|
-- config.on_attach = on_attach -- we don't need this because of the events
|
||||||
-- require('lspconfig')[server_name].setup(server)
|
lspconfig[server].setup(config)
|
||||||
-- end,
|
end
|
||||||
-- },
|
|
||||||
-- }
|
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
-- Show LSP explorer of functions and classes etc.
|
-- Show LSP explorer of functions and classes etc.
|
||||||
|
|
|
@ -105,6 +105,31 @@ local Languages = {
|
||||||
alias = 'docker-compose-langserver',
|
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'] = {
|
||||||
lua_ls = {
|
lua_ls = {
|
||||||
-- cmd = {...},
|
-- cmd = {...},
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
-- TODO: move lsp_config_name -> executable mapping here instead of being part of languages.lua file
|
|
@ -7,35 +7,45 @@ local name_to_bin = {
|
||||||
-- ['docker-compose-language-service'] = 'docker-compose-langserver',
|
-- ['docker-compose-language-service'] = 'docker-compose-langserver',
|
||||||
}
|
}
|
||||||
|
|
||||||
-- We guarantee 'ensure_installed' package is installed locally
|
M.missing = function(ensure_installed)
|
||||||
-- 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
|
|
||||||
if type(ensure_installed) == 'string' then
|
if type(ensure_installed) == 'string' then
|
||||||
ensure_installed = { ensure_installed }
|
ensure_installed = { ensure_installed }
|
||||||
end
|
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
|
-- check if executable exists
|
||||||
local function executable_exists(name)
|
if vim.fn.executable(executable_name) ~= 1 then
|
||||||
if name_to_bin[name] then
|
result[lsp_name] = config
|
||||||
return vim.fn.executable(name_to_bin[name]) == 1
|
|
||||||
end
|
end
|
||||||
return vim.fn.executable(name) == 1
|
|
||||||
end
|
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 registry = require 'mason-registry'
|
||||||
|
-- local mason_lspconfig = require 'mason-lspconfig'
|
||||||
registry.refresh(function()
|
registry.refresh(function()
|
||||||
for _, pkg_name in ipairs(ensure_installed) do
|
for lsp_cfg, _ in pairs(ensure_installed) do
|
||||||
if (not executable_exists(pkg_name)) and not enforce_local then
|
local pkg_name = lspconfig_to_pkg[lsp_cfg] -- get mason package name based on lspconfig name
|
||||||
local pkg = registry.get_package(pkg_name)
|
local pkg = registry.get_package(pkg_name)
|
||||||
if not pkg:is_installed() then
|
if not pkg:is_installed() then
|
||||||
pkg:install()
|
pkg:install()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ local PROFILES = {
|
||||||
'bash',
|
'bash',
|
||||||
'docker',
|
'docker',
|
||||||
'lua',
|
'lua',
|
||||||
|
'yaml',
|
||||||
},
|
},
|
||||||
['DEFAULT'] = {
|
['DEFAULT'] = {
|
||||||
'python',
|
'python',
|
||||||
|
@ -15,13 +16,29 @@ local PROFILES = {
|
||||||
'bash',
|
'bash',
|
||||||
'docker',
|
'docker',
|
||||||
'lua',
|
'lua',
|
||||||
|
'yaml',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local Profile = {}
|
local Profile = {}
|
||||||
Profile.Languages = function()
|
Profile.Languages = function(profile)
|
||||||
local profile = PROFILES[os.getenv 'NVIM_PROFILE' or 'DEFAULT']
|
if profile == nil then
|
||||||
return profile
|
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
|
end
|
||||||
|
|
||||||
return Profile
|
return Profile
|
||||||
|
|
Loading…
Reference in New Issue