add lsp-zero plugin

pull/220/head
Luke Johnson 2 years ago
parent 3ed6191021
commit 51e8fea23e

@ -44,17 +44,16 @@ vim.g.maplocalleader = ' '
-- Set powershell as the terminal -- Set powershell as the terminal
local powershell_options = { local powershell_options = {
shell = vim.fn.executable "pwsh" == 1 and "pwsh" or "powershell", shell = vim.fn.executable "pwsh" == 1 and "pwsh" or "powershell",
shellcmdflag = "-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;", shellcmdflag =
"-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;",
shellredir = "-RedirectStandardOutput %s -NoNewWindow -Wait", shellredir = "-RedirectStandardOutput %s -NoNewWindow -Wait",
shellpipe = "2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode", shellpipe = "2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode",
shellquote = "", shellquote = "",
shellxquote = "", shellxquote = "",
} }
for option, value in pairs(powershell_options) do for option, value in pairs(powershell_options) do
vim.opt[option] = value vim.opt[option] = value
end end
-- Install package manager -- Install package manager
-- https://github.com/folke/lazy.nvim -- https://github.com/folke/lazy.nvim
-- `:help lazy.nvim.txt` for more info -- `:help lazy.nvim.txt` for more info
@ -88,30 +87,42 @@ require('lazy').setup({
-- NOTE: This is where your plugins related to LSP can be installed. -- NOTE: This is where your plugins related to LSP can be installed.
-- The configuration is done below. Search for lspconfig to find it below. -- The configuration is done below. Search for lspconfig to find it below.
{ -- LSP Configuration & Plugins {
'neovim/nvim-lspconfig', -- LSP Configuration & Plugins
dependencies = { {
-- Automatically install LSPs to stdpath for neovim 'VonHeikemen/lsp-zero.nvim',
'williamboman/mason.nvim', branch = 'v1.x',
'williamboman/mason-lspconfig.nvim', dependencies = {
-- LSP Support
-- Useful status updates for LSP { 'neovim/nvim-lspconfig' }, -- Required
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` { 'williamboman/mason.nvim' }, -- Optional
{ 'j-hui/fidget.nvim', opts = {} }, { 'williamboman/mason-lspconfig.nvim' }, -- Optional
-- Additional lua configuration, makes nvim stuff amazing! -- Autocompletion
'folke/neodev.nvim', { 'hrsh7th/nvim-cmp' }, -- Required
}, { 'hrsh7th/cmp-nvim-lsp' }, -- Required
{ 'hrsh7th/cmp-buffer' }, -- Optional
{ 'hrsh7th/cmp-path' }, -- Optional
{ 'saadparwaiz1/cmp_luasnip' }, -- Optional
{ 'hrsh7th/cmp-nvim-lua' }, -- Optional
-- Snippets
{ 'L3MON4D3/LuaSnip' }, -- Required
{ 'rafamadriz/friendly-snippets' }, -- Optional
}
}
}, },
{ -- Autocompletion {
-- Autocompletion
'hrsh7th/nvim-cmp', 'hrsh7th/nvim-cmp',
dependencies = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' }, dependencies = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' },
}, },
-- Useful plugin to show you pending keybinds. -- Useful plugin to show you pending keybinds.
{ 'folke/which-key.nvim', opts = {} }, { 'folke/which-key.nvim', opts = {} },
{ -- Adds git releated signs to the gutter, as well as utilities for managing changes {
-- Adds git releated signs to the gutter, as well as utilities for managing changes
'lewis6991/gitsigns.nvim', 'lewis6991/gitsigns.nvim',
opts = { opts = {
-- See `:help gitsigns.txt` -- See `:help gitsigns.txt`
@ -158,7 +169,8 @@ require('lazy').setup({
end, end,
}, },
{ -- Set lualine as statusline {
-- Set lualine as statusline
'nvim-lualine/lualine.nvim', 'nvim-lualine/lualine.nvim',
-- See `:help lualine.txt` -- See `:help lualine.txt`
opts = { opts = {
@ -171,7 +183,8 @@ require('lazy').setup({
}, },
}, },
{ -- Add indentation guides even on blank lines {
-- Add indentation guides even on blank lines
'lukas-reineke/indent-blankline.nvim', 'lukas-reineke/indent-blankline.nvim',
-- Enable `lukas-reineke/indent-blankline.nvim` -- Enable `lukas-reineke/indent-blankline.nvim`
-- See `:help indent_blankline.txt` -- See `:help indent_blankline.txt`
@ -200,7 +213,8 @@ require('lazy').setup({
end, end,
}, },
{ -- Highlight, edit, and navigate code {
-- Highlight, edit, and navigate code
'nvim-treesitter/nvim-treesitter', 'nvim-treesitter/nvim-treesitter',
dependencies = { dependencies = {
'nvim-treesitter/nvim-treesitter-textobjects', 'nvim-treesitter/nvim-treesitter-textobjects',
@ -268,9 +282,19 @@ vim.o.completeopt = 'menuone,noselect'
-- NOTE: You should make sure your terminal supports this -- NOTE: You should make sure your terminal supports this
vim.o.termguicolors = true vim.o.termguicolors = true
vim.o.tabstop = 2 vim.o.tabstop = 4
vim.o.shiftwidth = 2 vim.o.softtabstop = 4
vim.o.shiftwidth = 4
vim.o.shiftround = true vim.o.shiftround = true
vim.opt.relativenumber = true
vim.opt.scrolloff = 8
vim.opt.signcolumn = "yes"
vim.opt.colorcolumn = "80"
vim.opt.smartindent = true
-- [[ Basic Keymaps ]] -- [[ Basic Keymaps ]]
-- Keymaps for better default experience -- Keymaps for better default experience
@ -302,8 +326,8 @@ require('telescope').setup {
defaults = { defaults = {
mappings = { mappings = {
i = { i = {
['<C-u>'] = false, ['<C-u>'] = false,
['<C-d>'] = false, ['<C-d>'] = false,
}, },
}, },
}, },
@ -355,41 +379,41 @@ require('nvim-treesitter.configs').setup {
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
keymaps = { keymaps = {
-- You can use the capture groups defined in textobjects.scm -- You can use the capture groups defined in textobjects.scm
['aa'] = '@parameter.outer', ['aa'] = '@parameter.outer',
['ia'] = '@parameter.inner', ['ia'] = '@parameter.inner',
['af'] = '@function.outer', ['af'] = '@function.outer',
['if'] = '@function.inner', ['if'] = '@function.inner',
['ac'] = '@class.outer', ['ac'] = '@class.outer',
['ic'] = '@class.inner', ['ic'] = '@class.inner',
}, },
}, },
move = { move = {
enable = true, enable = true,
set_jumps = true, -- whether to set jumps in the jumplist set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = { goto_next_start = {
[']m'] = '@function.outer', [']m'] = '@function.outer',
[']]'] = '@class.outer', [']]'] = '@class.outer',
}, },
goto_next_end = { goto_next_end = {
[']M'] = '@function.outer', [']M'] = '@function.outer',
[']['] = '@class.outer', [']['] = '@class.outer',
}, },
goto_previous_start = { goto_previous_start = {
['[m'] = '@function.outer', ['[m'] = '@function.outer',
['[['] = '@class.outer', ['[['] = '@class.outer',
}, },
goto_previous_end = { goto_previous_end = {
['[M'] = '@function.outer', ['[M'] = '@function.outer',
['[]'] = '@class.outer', ['[]'] = '@class.outer',
}, },
}, },
swap = { swap = {
enable = true, enable = true,
swap_next = { swap_next = {
['<leader>a'] = '@parameter.inner', ['<leader>a'] = '@parameter.inner',
}, },
swap_previous = { swap_previous = {
['<leader>A'] = '@parameter.inner', ['<leader>A'] = '@parameter.inner',
}, },
}, },
}, },
@ -401,8 +425,20 @@ vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = "Go to next diagnos
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = "Open floating diagnostic message" }) vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = "Open floating diagnostic message" })
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = "Open diagnostics list" }) vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = "Open diagnostics list" })
-- LSP settings. -- LSP Settings
-- This function gets run when an LSP connects to a particular buffer. local lsp = require('lsp-zero').preset({
name = 'minimal',
set_lsp_keymaps = false,
manage_nvim_cmp = true,
suggest_lsp_servers = false,
})
lsp.ensure_installed({
'tsserver',
'rust_analyzer',
})
-- Create a callback function that will be called in lsp-zero's ".on_attach" function
-- It is used to
local on_attach = function(_, bufnr) local on_attach = function(_, bufnr)
-- NOTE: Remember that lua is a real programming language, and as such it is possible -- NOTE: Remember that lua is a real programming language, and as such it is possible
-- to define small helper and utility functions so you don't have to repeat yourself -- to define small helper and utility functions so you don't have to repeat yourself
@ -415,7 +451,7 @@ local on_attach = function(_, bufnr)
desc = 'LSP: ' .. desc desc = 'LSP: ' .. desc
end end
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc, remap = false })
end end
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
@ -446,97 +482,8 @@ local on_attach = function(_, bufnr)
end, { desc = 'Format current buffer with LSP' }) end, { desc = 'Format current buffer with LSP' })
end end
-- Enable the following language servers lsp.on_attach(on_attach)
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed. -- (Optional) Configure lua language server for neovim
-- lsp.nvim_workspace()
-- Add any additional override configuration in the following tables. They will be passed to
-- the `settings` field of the server config. You must look up that documentation yourself.
local servers = {
-- clangd = {},
-- gopls = {},
-- pyright = {},
-- rust_analyzer = {},
-- tsserver = {},
lua_ls = {
Lua = {
workspace = { checkThirdParty = false },
telemetry = { enable = false },
},
},
}
-- Setup neovim lua configuration
require('neodev').setup()
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
-- Setup mason so it can manage external tooling
require('mason').setup()
-- Ensure the servers above are installed
local mason_lspconfig = require 'mason-lspconfig'
mason_lspconfig.setup {
ensure_installed = vim.tbl_keys(servers),
}
mason_lspconfig.setup_handlers {
function(server_name)
require('lspconfig')[server_name].setup {
capabilities = capabilities,
on_attach = on_attach,
settings = servers[server_name],
}
end,
}
-- nvim-cmp setup
local cmp = require 'cmp'
local luasnip = require 'luasnip'
luasnip.config.setup {}
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert {
['<C-d>'] = cmp.mapping.scroll_docs( -4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete {},
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable( -1) then
luasnip.jump( -1)
else
fallback()
end
end, { 'i', 's' }),
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
}
-- The line beneath this is called `modeline`. See `:help modeline` lsp.setup()
-- vim: ts=2 sts=2 sw=2 et

Loading…
Cancel
Save