feat: nvim with lsp

This commit is contained in:
Philipp Hochkamp 2023-04-21 21:53:36 +02:00
parent 7b690a7714
commit 380be27b0a
19 changed files with 627 additions and 569 deletions

View file

@ -0,0 +1,52 @@
local cmp = require 'cmp'
local lspkind = require 'lspkind'
local luasnip = require 'luasnip'
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
end
end, { "i", "s" }),
},
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
}, { name = "buffer" }),
formatting = {
format = lspkind.cmp_format({
mode = "symbol_text",
menu = ({
buffer = "[Buffer]",
nvim_lsp = "[LSP]",
luasnip = "[LuaSnip]",
nvim_lua = "[Lua]",
latex_symbols = "[Latex]",
})
}),
},
})

View file

@ -0,0 +1 @@
require('gitsigns').setup {}

View file

@ -0,0 +1,101 @@
local lspconfig = require 'lspconfig'
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- lsp keymaps
local lsp_attach_keymappings = {
['gD'] = 'vim.lsp.buf.declaration()',
['gd'] = 'vim.lsp.buf.definition()',
['K'] = 'vim.lsp.buf.hover()',
['gi'] = 'vim.lsp.buf.implementation()',
['<C-k>'] = 'vim.lsp.buf.signature_help()',
['<leader>wa'] = 'vim.lsp.buf.add_workspace_folder()',
['<leader>wr'] = 'vim.lsp.buf.remove_workspace_folder()',
['<leader>ws'] = 'vim.lsp.buf.workspace_symbol()',
['<leader>wl'] = 'print(vim.inspect(vim.lsp.buf.list_workspace_folders()))',
['<leader>D'] = 'vim.lsp.buf.type_definition()',
['<leader>rn'] = 'vim.lsp.buf.rename()',
['<leader>ca'] = 'vim.lsp.buf.code_action()',
['gr'] = 'vim.lsp.buf.references()',
['<leader>f'] = 'vim.lsp.buf.format()'
}
local buf_nnoremap_lua = function(bufnr, keys, command)
vim.api.nvim_buf_set_keymap(bufnr, 'n', keys, '<cmd>lua ' .. command .. '<CR>', { noremap = true, silent = true })
end
local on_lsp_attach = function(_, bufnr)
-- Enable completion triggered by <c-x><c-o>:
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
for key, cmd in pairs(lsp_attach_keymappings) do buf_nnoremap_lua(bufnr, key, cmd) end
end
lspconfig.gopls.setup { capabilities = capabilities, on_attach = on_lsp_attach }
lspconfig.pyright.setup { capabilities = capabilities, on_attach = on_lsp_attach }
lspconfig.nil_ls.setup { capabilities = capabilities, on_attach = on_lsp_attach } -- nix
-- lspconfig.rnix.setup { capabilities = capabilities, on_attach = on_lsp_attach } -- nix
lspconfig.terraformls.setup { capabilities = capabilities, on_attach = on_lsp_attach }
lspconfig.tsserver.setup { capabilities = capabilities, on_attach = on_lsp_attach }
lspconfig.vimls.setup {
capabilities = capabilities,
on_attach = on_lsp_attach,
isNeovim = true,
}
lspconfig.csharp_ls.setup {
capabilities = capabilities,
on_attach = on_lsp_attach,
cmd = {vim.env.HOME .. "/.dotnet/tools/csharp-ls"},
}
lspconfig.ltex.setup { capabilities = capabilities, on_attach = on_lsp_attach }
-- start vscode included language servers
lspconfig.eslint.setup { capabilities = capabilities, on_attach = on_lsp_attach }
lspconfig.html.setup { capabilities = capabilities, on_attach = on_lsp_attach }
lspconfig.cssls.setup { capabilities = capabilities, on_attach = on_lsp_attach }
lspconfig.jsonls.setup { capabilities = capabilities, on_attach = on_lsp_attach }
-- end vscode included language servers
lspconfig.texlab.setup { capabilities = capabilities, on_attach = on_lsp_attach, settings = { texlab = {
build = {
executable = "tectonic",
args = { "%f", "--keep-logs", "--synctex"},
onSave = true,
forwardSearchAfter = true,
},
chktex = { onOpenAndSave = true, },
forwardSearch = {
executable = "/Applications/Skim.app/Contents/SharedSupport/displayline",
args = {"-r", "-d", "%l","%p","%f"},
},
}} }
lspconfig.sumneko_lua.setup {
capabilities = capabilities, on_attach = on_lsp_attach,
settings = {
Lua = {
runtime = {
version = 'LuaJIT'
},
diagnostics = { globals = { 'vim' } },
workspace = {
-- Make the LSP aware of Neovim runtime files:
library = vim.api.nvim_get_runtime_file('', true)
},
format = {
enable = true,
defaultConfig = {
indent_style = 'space',
indent_size = '2',
}
},
}
}
}
local rt = require("rust-tools")
rt.setup({
tools = {
inlay_hints = {
auto = true,
},
},
server = {
capabilities = capabilities, on_attach = on_lsp_attach,
},
})

View file

@ -1,28 +1,215 @@
require('lualine').setup {
-- Eviline config for lualine
-- Author: shadmansaleh
-- Credit: glepnir
local lualine = require('lualine')
-- Color table for highlights
-- stylua: ignore
local colors = {
bg = '#202328',
fg = '#bbc2cf',
yellow = '#ECBE7B',
cyan = '#008080',
darkblue = '#081633',
green = '#98be65',
orange = '#FF8800',
violet = '#a9a1e1',
magenta = '#c678dd',
blue = '#51afef',
red = '#ec5f67',
}
local conditions = {
buffer_not_empty = function()
return vim.fn.empty(vim.fn.expand('%:t')) ~= 1
end,
hide_in_width = function()
return vim.fn.winwidth(0) > 80
end,
check_git_workspace = function()
local filepath = vim.fn.expand('%:p:h')
local gitdir = vim.fn.finddir('.git', filepath .. ';')
return gitdir and #gitdir > 0 and #gitdir < #filepath
end,
}
-- Config
local config = {
options = {
icons_enabled = true,
-- Disable sections and component separators
component_separators = '',
section_separators = '',
theme = 'gruvbox',
--component_separators = { left = '', right = ''},
--section_separators = { left = '', right = ''},
disabled_filetypes = {},
always_divide_middle = true,
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {'filename'},
lualine_x = {'encoding', 'fileformat', 'filetype'},
lualine_y = {'progress'},
lualine_z = {'location'}
},
inactive_sections = {
-- these are to remove the defaults
lualine_a = {},
lualine_b = {},
lualine_c = {'filename'},
lualine_x = {'location'},
lualine_y = {},
lualine_z = {}
lualine_z = {},
-- These will be filled later
lualine_c = {},
lualine_x = {},
},
inactive_sections = {
-- these are to remove the defaults
lualine_a = {},
lualine_b = {},
lualine_y = {},
lualine_z = {},
lualine_c = {},
lualine_x = {},
},
tabline = {},
extensions = {}
}
-- Inserts a component in lualine_c at left section
local function ins_left(component)
table.insert(config.sections.lualine_c, component)
end
-- Inserts a component in lualine_x at right section
local function ins_right(component)
table.insert(config.sections.lualine_x, component)
end
ins_left {
function()
return ''
end,
color = { fg = colors.blue }, -- Sets highlighting of component
padding = { left = 0, right = 1 }, -- We don't need space before this
}
ins_left {
-- mode component
function()
return ''
end,
color = function()
-- auto change color according to neovims mode
local mode_color = {
n = colors.red,
i = colors.green,
v = colors.blue,
[''] = colors.blue,
V = colors.blue,
c = colors.magenta,
no = colors.red,
s = colors.orange,
S = colors.orange,
[''] = colors.orange,
ic = colors.yellow,
R = colors.violet,
Rv = colors.violet,
cv = colors.red,
ce = colors.red,
r = colors.cyan,
rm = colors.cyan,
['r?'] = colors.cyan,
['!'] = colors.red,
t = colors.red,
}
return { fg = mode_color[vim.fn.mode()] }
end,
padding = { right = 1 },
}
ins_left {
-- filesize component
'filesize',
cond = conditions.buffer_not_empty,
}
ins_left {
'filename',
cond = conditions.buffer_not_empty,
color = { fg = colors.magenta, gui = 'bold' },
}
ins_left { 'location' }
ins_left { 'progress', color = { fg = colors.fg, gui = 'bold' } }
ins_left {
'diagnostics',
sources = { 'nvim_diagnostic' },
symbols = { error = '', warn = '', info = '' },
diagnostics_color = {
color_error = { fg = colors.red },
color_warn = { fg = colors.yellow },
color_info = { fg = colors.cyan },
},
}
-- Insert mid section. You can make any number of sections in neovim :)
-- for lualine it's any number greater then 2
ins_left {
function()
return '%='
end,
}
ins_left {
-- Lsp server name .
function()
local msg = 'No Active Lsp'
local buf_ft = vim.api.nvim_buf_get_option(0, 'filetype')
local clients = vim.lsp.get_active_clients()
if next(clients) == nil then
return msg
end
for _, client in ipairs(clients) do
local filetypes = client.config.filetypes
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
return client.name
end
end
return msg
end,
icon = ' LSP:',
color = { fg = '#ffffff', gui = 'bold' },
}
-- Add components to right sections
ins_right {
'o:encoding', -- option component same as &encoding in viml
fmt = string.upper, -- I'm not sure why it's upper case either ;)
cond = conditions.hide_in_width,
color = { fg = colors.green, gui = 'bold' },
}
ins_right {
'fileformat',
fmt = string.upper,
icons_enabled = false, -- I think icons are cool but Eviline doesn't have them. sigh
color = { fg = colors.green, gui = 'bold' },
}
ins_right {
'branch',
icon = '',
color = { fg = colors.violet, gui = 'bold' },
}
ins_right {
'diff',
-- Is it me or the symbol for modified us really weird
symbols = { added = '', modified = '', removed = '' },
diff_color = {
added = { fg = colors.green },
modified = { fg = colors.orange },
removed = { fg = colors.red },
},
cond = conditions.hide_in_width,
}
ins_right {
function()
return ''
end,
color = { fg = colors.blue },
padding = { left = 1 },
}
-- Now don't forget to initialize lualine
lualine.setup(config)

View file

@ -4,6 +4,13 @@ require("noice").setup({
merge = true,
}
},
lsp = {
override = {
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
["vim.lsp.util.stylize_markdown"] = true,
["cmp.entry.get_documentation"] = true,
},
},
-- you can enable a preset for easier configuration
presets = {
bottom_search = true, -- use a classic bottom cmdline for search
@ -14,6 +21,6 @@ require("noice").setup({
},
})
require("notify").setup({
stages = "static",
max_width = 70,
-- stages = "static",
-- max_width = 70,
})

View file

@ -1,3 +0,0 @@
require('project_nvim').setup {
detection_methods = { "pattern" },
}

View file

@ -1 +0,0 @@
vim.g.rainbow_active = 1

View file

@ -1,2 +1,11 @@
require('telescope').setup {}
require('telescope').load_extension('projects')
local telescope = require('telescope')
telescope.setup {
extensions = {
["ui-select"] = {
require("telescope.themes").get_dropdown {
-- even more opts
}
}
}
}
telescope.load_extension('ui-select')

View file

@ -1,20 +1,22 @@
local treesitter_parser_install_dir = '/var/tmp/nvim-treesitter/parser'
require'nvim-treesitter.configs'.setup {
highlight = {
enable = true,
use_languagetree = true,
},
indent = {
enable = true,
},
autotag = {
enable = true,
},
context_commentstring = {
enable = true,
enable_autocmd = false,
},
refactor = {
highlight_definitions = { enable = true },
highlight_current_scope = { enable = false },
-- use_languagetree = true,
},
parser_install_dir = treesitter_parser_install_dir,
-- indent = {
-- enable = true,
-- },
-- autotag = {
-- enable = true,
-- },
-- context_commentstring = {
-- enable = true,
-- enable_autocmd = false,
-- },
-- refactor = {
-- highlight_definitions = { enable = true },
-- highlight_current_scope = { enable = false },
-- },
}