rearranging and add some lsp config
This commit is contained in:
parent
98ea26485b
commit
11da71e073
7 changed files with 347 additions and 197 deletions
201
init.lua
201
init.lua
|
|
@ -201,110 +201,9 @@ require('lazy').setup({
|
|||
{ import = 'custom.plugins' },
|
||||
}, {})
|
||||
|
||||
-- [[ Setting options ]]
|
||||
-- See `:help vim.o`
|
||||
-- NOTE: You can change these options as you wish!
|
||||
|
||||
-- Set highlight on search
|
||||
vim.o.hlsearch = true
|
||||
|
||||
-- Make line numbers default
|
||||
vim.wo.number = true
|
||||
-- Enable relative line numbers
|
||||
vim.wo.relativenumber = true
|
||||
|
||||
-- Enable mouse mode
|
||||
vim.o.mouse = 'a'
|
||||
|
||||
-- Sync clipboard between OS and Neovim.
|
||||
-- Remove this option if you want your OS clipboard to remain independent.
|
||||
-- See `:help 'clipboard'`
|
||||
vim.o.clipboard = 'unnamedplus'
|
||||
|
||||
-- Enable break indent
|
||||
vim.o.breakindent = true
|
||||
|
||||
-- Save undo history
|
||||
vim.o.undofile = true
|
||||
|
||||
-- Case-insensitive searching UNLESS \C or capital in search
|
||||
vim.o.ignorecase = true
|
||||
vim.o.smartcase = true
|
||||
|
||||
-- Keep signcolumn on by default
|
||||
vim.wo.signcolumn = 'yes'
|
||||
|
||||
-- Decrease update time
|
||||
vim.o.updatetime = 250
|
||||
vim.o.timeoutlen = 300
|
||||
|
||||
-- Set completeopt to have a better completion experience
|
||||
vim.o.completeopt = 'menuone,noselect'
|
||||
|
||||
-- appearance
|
||||
-- NOTE: You should make sure your terminal supports this
|
||||
vim.o.termguicolors = true
|
||||
vim.o.background = "dark"
|
||||
vim.o.signcolumn = "yes"
|
||||
|
||||
-- tabs and indentation
|
||||
vim.opt.tabstop = 4
|
||||
vim.opt.shiftwidth = 4
|
||||
vim.opt.expandtab = true
|
||||
vim.opt.autoindent = true
|
||||
|
||||
-- split windows
|
||||
vim.o.splitright = true
|
||||
vim.o.splitbelow = true
|
||||
|
||||
vim.opt.iskeyword:append("-")
|
||||
|
||||
-- set color scheme
|
||||
vim.cmd.colorscheme "catppuccin"
|
||||
|
||||
-- [[ Basic Keymaps ]]
|
||||
|
||||
-- Keymaps for better default experience
|
||||
-- See `:help vim.keymap.set()`
|
||||
local keymap = vim.keymap
|
||||
keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
|
||||
|
||||
-- Remap for dealing with word wrap
|
||||
keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
|
||||
keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
|
||||
|
||||
-- Remap ESC key in different modes
|
||||
keymap.set("i", "jk", "<ESC>")
|
||||
keymap.set("v", "jk", "<ESC>")
|
||||
keymap.set("c", "jk", "<ESC>")
|
||||
|
||||
-- clear highlights
|
||||
keymap.set("n", "<leader>nh", ":nohl<CR>")
|
||||
|
||||
-- delete character but don't copy into register
|
||||
keymap.set("n", "x", '"_x')
|
||||
|
||||
-- increment/decrement numbers
|
||||
keymap.set("n", "<leader>+", "<C-a>")
|
||||
keymap.set("n", "<leader>-", "C-x")
|
||||
|
||||
-- split window
|
||||
keymap.set("n", "<leader>sv", "<C-w>v")
|
||||
keymap.set("n", "<leader>sh", "<C-w>s")
|
||||
keymap.set("n", "<leader>se", "<C-w>=")
|
||||
keymap.set("n", "<leader>sx", ":close<CR>")
|
||||
|
||||
-- tabs
|
||||
keymap.set("n", "<leader>to", ":tabnew<CR>")
|
||||
keymap.set("n", "<leader>tx", ":tabclose<CR>")
|
||||
keymap.set("n", "<leader>tn", ":tabn<CR>")
|
||||
keymap.set("n", "<leader>tp", ":tabp<CR>")
|
||||
|
||||
--maximize window toggle
|
||||
keymap.set("n", "<leader>max", ":MaximizerToggle<CR>")
|
||||
|
||||
-- nvim-tree
|
||||
keymap.set("n", "<leader>tt", ":NvimTreeToggle<CR>")
|
||||
require('custom.keymaps')
|
||||
require('custom.config')
|
||||
require('custom.lsp')
|
||||
|
||||
-- [[ Highlight on yank ]]
|
||||
-- See `:help vim.highlight.on_yank()`
|
||||
|
|
@ -333,6 +232,7 @@ require('telescope').setup {
|
|||
-- Enable telescope fzf native, if installed
|
||||
pcall(require('telescope').load_extension, 'fzf')
|
||||
|
||||
local keymap = vim.keymap
|
||||
-- See `:help telescope.builtin`
|
||||
keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' })
|
||||
keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' })
|
||||
|
|
@ -423,100 +323,7 @@ keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic
|
|||
keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
|
||||
keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
|
||||
|
||||
-- [[ Configure LSP ]]
|
||||
-- This function gets run when an LSP connects to a particular buffer.
|
||||
local on_attach = function(_, bufnr)
|
||||
-- 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
|
||||
-- many times.
|
||||
--
|
||||
-- In this case, we create a function that lets us more easily define mappings specific
|
||||
-- for LSP related items. It sets the mode, buffer and description for us each time.
|
||||
local nmap = function(keys, func, desc)
|
||||
if desc then
|
||||
desc = 'LSP: ' .. desc
|
||||
end
|
||||
|
||||
keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
|
||||
end
|
||||
|
||||
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
|
||||
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
|
||||
|
||||
nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
|
||||
nmap('ref', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
|
||||
nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
|
||||
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
|
||||
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
|
||||
nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
|
||||
|
||||
-- See `:help K` for why this keymap
|
||||
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
|
||||
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
|
||||
|
||||
-- Lesser used LSP functionality
|
||||
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
|
||||
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
|
||||
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
|
||||
nmap('<leader>wl', function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end, '[W]orkspace [L]ist Folders')
|
||||
|
||||
-- Create a command `:Format` local to the LSP buffer
|
||||
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
|
||||
vim.lsp.buf.format()
|
||||
end, { desc = 'Format current buffer with LSP' })
|
||||
end
|
||||
|
||||
-- Enable the following language servers
|
||||
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
|
||||
--
|
||||
-- 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.
|
||||
--
|
||||
-- If you want to override the default filetypes that your language server will attach to you can
|
||||
-- define the property 'filetypes' to the map in question.
|
||||
local servers = {
|
||||
-- clangd = {},
|
||||
gopls = {},
|
||||
-- pyright = {},
|
||||
-- rust_analyzer = {},
|
||||
tsserver = {},
|
||||
-- html = { filetypes = { 'html', 'twig', 'hbs'} },
|
||||
|
||||
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)
|
||||
|
||||
-- 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],
|
||||
-- commented below as currently not overriding file types
|
||||
-- filetypes = servers[server_name].filetypes,
|
||||
}
|
||||
end
|
||||
}
|
||||
|
||||
-- [[ Configure nvim-cmp ]]
|
||||
-- See `:help cmp`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue