Compare commits

...

6 Commits

Author SHA1 Message Date
89bca77ef4 Improve completion comments 2024-04-01 19:05:03 +01:00
0bfd392b20 Add rounded borders to LSP/Diagnostics float windows 2024-04-01 19:04:26 +01:00
890fe6f928 Reorder cmp sources so LSP results are first 2024-04-01 19:03:58 +01:00
1d1d922282 Add more language servers
* Ansible
* Bash
* Dockerfile/Docker Compose
* Sphinx
* HTML
* OpenCL
* Powershell
2024-04-01 19:02:36 +01:00
2f6b0ba33c Add more cmp preset mappigns
* `<C-Space>` to trigger the complteion menu without a substring prefix
* `<C-d>`/`<C-u`> to scroll down/up in a completion item's documentation
2024-04-01 19:00:40 +01:00
7b17b794f6 Make column/line chunk match 2024-04-01 18:59:52 +01:00
2 changed files with 64 additions and 20 deletions

View File

@ -35,18 +35,27 @@ return {
config = function()
require('mason').setup()
require('mason-lspconfig').setup({
ensure_installed = {
'clangd',
'cmake',
'jsonls',
'lemminx',
'lua_ls',
'pyright',
'ruff_lsp',
'vimls',
'yamlls',
},
automatic_installation = false,
ensure_installed = {
'ansiblels', -- Ansible
'bashls', -- Bash
'clangd', -- C/C++
'cmake', -- Cmake
'docker_compose_language_service', -- Docker Compose
'dockerls', -- Dockerfile
'esbonio', -- Sphinx
'html', -- HTML
'jsonls', -- JSON
'lemminx', -- XML
'lua_ls', -- Lua
'opencl_ls', -- OpenCL
'powershell_es', -- Powershell
'pyright', -- Python
'ruff_lsp', -- Python
'vimls', -- VimScript
'yamlls', -- YAML
},
handlers = {
-- Default handler, sets up everything unless a custom language server
-- setup handler is defined below
@ -89,30 +98,62 @@ return {
require('luasnip').lsp_expand(args.body)
end
},
mapping = cmp.mapping.preset.insert({
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
-- Open completion menu/confirm completion
['<C-Space>'] = cmp.mapping.complete(),
['<C-l>'] = cmp.mapping.confirm({ select = true }),
-- Select completion from menu
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-p>'] = cmp.mapping.select_prev_item(),
-- Scroll documentation of selected completion item
['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-u>'] = cmp.mapping.scroll_docs(-4),
}),
sources = {
{ name = 'luasnip' },
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
-- { name = 'buffer' },
{ name = 'path' },
-- { name = 'cmdline' },
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
})
-- Disable displaying diagnostics as virtual text
vim.diagnostic.config({ virtual_text = false })
-- Customise LSP UI
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(
vim.lsp.handlers.hover, {
border = 'rounded',
title = 'Hover',
}
)
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
vim.lsp.handlers.signature_help, {
border = 'rounded',
title = 'Signature Help'
}
)
-- Diagnostic mappings
-- Customise diagnostics UI
vim.diagnostic.config({
float = {
border = 'rounded', -- Enable rounded border on floats
},
virtual_text = false, -- Disable trailing virtual text
})
-- Diagnostics mappings
-- TODO: trouble.nvim mappings instead? https://youtu.be/MuUrCcvE-Yw?t=631
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { remap = false })
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { remap = false })
vim.keymap.set('n', '<leader>sd', vim.diagnostic.open_float, { remap = false })
-- LSP mappings created when attached to a buffer
-- Mappings created when LSP is attached to a buffer
local augroup = vim.api.nvim_create_augroup('lsp', { clear = true })
vim.api.nvim_create_autocmd('LspAttach', {
pattern = '*',

View File

@ -60,6 +60,9 @@ local function get_mode()
return current_mode.name
end
-- Display cusor line/total and column
local position = '# ☰ %l/%L 󰠷 %2c '
-- Construct a statusline for special buffer types.
local function special(group, name, title)
-- Display current mode with dynamic highlights.
@ -67,7 +70,7 @@ local function special(group, name, title)
-- Display filename with dark highlights.
line = line .. '%#StatusLineDark# ' .. title
-- Display current/total lines and column with dynamic highlights.
line = line .. '%=' .. '%#' .. group .. '# ☰%l/%L ·%2c '
line = line .. '%=' .. '%#' .. group .. position
-- Combine the elements into a single string to be evaluated.
return line
end
@ -100,7 +103,7 @@ local function generic(group, name, show_lsp)
'%{&fileencoding ==# "utf-8" ? "" : &fileencoding}' ..
'%{&fileformat ==# "unix" ? "" : "[".&fileformat."]"}' .. ' %)'
-- Display current/total lines and column with dynamic highlights.
line = line .. '%#' .. group .. '# ☰ %l/%L 󰠷 %2c '
line = line .. '%#' .. group .. position
-- Combine the elements into a single string to be evaluated.
return line
end