move to nvim lua and lsp
This commit is contained in:
parent
fc16a5466b
commit
b63772bd4d
18 changed files with 692 additions and 323 deletions
5
.config/nvim/after/plugin/colors.lua
Normal file
5
.config/nvim/after/plugin/colors.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
vim.g.tokyonight_transparent_sidebar = true
|
||||
vim.g.tokyonight_transparent = true
|
||||
vim.opt.background = "dark"
|
||||
|
||||
vim.cmd("colorscheme tokyonight")
|
||||
1
.config/nvim/after/plugin/init.lua
Normal file
1
.config/nvim/after/plugin/init.lua
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
219
.config/nvim/after/plugin/lsp.lua
Normal file
219
.config/nvim/after/plugin/lsp.lua
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
local Remap = require("rahcodes.keymap")
|
||||
local nnoremap = Remap.nnoremap
|
||||
local inoremap = Remap.inoremap
|
||||
|
||||
local sumneko_root_path = "/usr/lib/lua-language-server"
|
||||
local sumneko_binary = "/usr/bin/lua-language-server"
|
||||
|
||||
-- Setup nvim-cmp.
|
||||
local cmp = require("cmp")
|
||||
local source_mapping = {
|
||||
youtube = "[Suck it YT]",
|
||||
buffer = "[Buffer]",
|
||||
nvim_lsp = "[LSP]",
|
||||
nvim_lua = "[Lua]",
|
||||
-- cmp_tabnine = "[TN]",
|
||||
path = "[Path]",
|
||||
}
|
||||
local lspkind = require("lspkind")
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
-- For `vsnip` user.
|
||||
-- vim.fn["vsnip#anonymous"](args.body)
|
||||
|
||||
-- For `luasnip` user.
|
||||
require("luasnip").lsp_expand(args.body)
|
||||
|
||||
-- For `ultisnips` user.
|
||||
-- vim.fn["UltiSnips#Anon"](args.body)
|
||||
end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-u>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<C-d>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-Space>"] = cmp.mapping.complete(),
|
||||
['<C-y>'] = cmp.mapping.confirm({ select = true }),
|
||||
}),
|
||||
|
||||
formatting = {
|
||||
format = function(entry, vim_item)
|
||||
vim_item.kind = lspkind.presets.default[vim_item.kind]
|
||||
local menu = source_mapping[entry.source.name]
|
||||
-- if entry.source.name == "cmp_tabnine" then
|
||||
-- if entry.completion_item.data ~= nil and entry.completion_item.data.detail ~= nil then
|
||||
-- menu = entry.completion_item.data.detail .. " " .. menu
|
||||
-- end
|
||||
-- vim_item.kind = ""
|
||||
-- end
|
||||
vim_item.menu = menu
|
||||
return vim_item
|
||||
end,
|
||||
},
|
||||
|
||||
sources = {
|
||||
-- tabnine completion? yayaya
|
||||
-- { name = "cmp_tabnine" },
|
||||
|
||||
{ name = "nvim_lsp" },
|
||||
|
||||
-- For vsnip user.
|
||||
-- { name = 'vsnip' },
|
||||
|
||||
-- For luasnip user.
|
||||
{ name = "luasnip" },
|
||||
|
||||
-- For ultisnips user.
|
||||
-- { name = 'ultisnips' },
|
||||
|
||||
{ name = "buffer" },
|
||||
|
||||
{ name = "youtube" },
|
||||
},
|
||||
})
|
||||
|
||||
--[[
|
||||
local tabnine = require("cmp_tabnine.config")
|
||||
tabnine:setup({
|
||||
max_lines = 1000,
|
||||
max_num_results = 20,
|
||||
sort = true,
|
||||
run_on_every_keystroke = true,
|
||||
snippet_placeholder = "..",
|
||||
})
|
||||
]]--
|
||||
|
||||
local function config(_config)
|
||||
return vim.tbl_deep_extend("force", {
|
||||
on_attach = function()
|
||||
nnoremap("gD", function() vim.lsp.buf.definition() end)
|
||||
nnoremap("gd", function() vim.lsp.buf.definition() end)
|
||||
nnoremap("K", function() vim.lsp.buf.hover() end)
|
||||
nnoremap("gi", function() vim.lsp.buf.implementation() end)
|
||||
nnoremap("<leader>wa", function() vim.lsp.buf.add_workspace_folder() end)
|
||||
nnoremap("<leader>wr", function() vim.lsp.buf.remove_workspace_folder() end)
|
||||
nnoremap("<leader>wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end)
|
||||
nnoremap("<leader>vws", function() vim.lsp.buf.workspace_symbol() end)
|
||||
nnoremap("<leader>vd", function() vim.diagnostic.open_float() end)
|
||||
nnoremap("[d", function() vim.diagnostic.goto_next() end)
|
||||
nnoremap("]d", function() vim.diagnostic.goto_prev() end)
|
||||
nnoremap("<leader>ca", function() vim.lsp.buf.code_action() end)
|
||||
nnoremap("<leader>vco", function() vim.lsp.buf.code_action({
|
||||
filter = function(code_action)
|
||||
if not code_action or not code_action.data then
|
||||
return false
|
||||
end
|
||||
|
||||
local data = code_action.data.id
|
||||
return string.sub(data, #data - 1, #data) == ":0"
|
||||
end,
|
||||
apply = true
|
||||
}) end)
|
||||
nnoremap("<leader>gr", function() vim.lsp.buf.references() end)
|
||||
nnoremap("<leader>rn", function() vim.lsp.buf.rename() end)
|
||||
inoremap("<C-h>", function() vim.lsp.buf.signature_help() end)
|
||||
nnoremap("<leader>f", function() vim.lsp.buf.format({ async = true }) end)
|
||||
end,
|
||||
}, _config or {})
|
||||
end
|
||||
|
||||
require("lspconfig").zls.setup(config())
|
||||
|
||||
require("lspconfig").tsserver.setup(config())
|
||||
|
||||
require("lspconfig").ccls.setup(config())
|
||||
|
||||
require("lspconfig").jedi_language_server.setup(config())
|
||||
|
||||
require("lspconfig").svelte.setup(config())
|
||||
|
||||
require("lspconfig").solang.setup(config())
|
||||
|
||||
require("lspconfig").cssls.setup(config())
|
||||
|
||||
require("lspconfig").gopls.setup(config({
|
||||
cmd = { "gopls", "serve" },
|
||||
settings = {
|
||||
gopls = {
|
||||
analyses = {
|
||||
unusedparams = true,
|
||||
},
|
||||
staticcheck = true,
|
||||
},
|
||||
},
|
||||
}))
|
||||
|
||||
-- who even uses this?
|
||||
require("lspconfig").rust_analyzer.setup(config({
|
||||
cmd = { "rustup", "run", "nightly", "rust-analyzer" },
|
||||
--[[
|
||||
settings = {
|
||||
rust = {
|
||||
unstable_features = true,
|
||||
build_on_save = false,
|
||||
all_features = true,
|
||||
},
|
||||
}
|
||||
--]]
|
||||
}))
|
||||
|
||||
require("lspconfig").sumneko_lua.setup(config({
|
||||
cmd = { sumneko_binary, "-E", sumneko_root_path .. "/main.lua" },
|
||||
settings = {
|
||||
Lua = {
|
||||
runtime = {
|
||||
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
||||
version = "LuaJIT",
|
||||
-- Setup your lua path
|
||||
path = vim.split(package.path, ";"),
|
||||
},
|
||||
diagnostics = {
|
||||
-- Get the language server to recognize the `vim` global
|
||||
globals = { "vim" },
|
||||
},
|
||||
workspace = {
|
||||
-- Make the server aware of Neovim runtime files
|
||||
library = {
|
||||
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
|
||||
[vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}))
|
||||
|
||||
local opts = {
|
||||
-- whether to highlight the currently hovered symbol
|
||||
-- disable if your cpu usage is higher than you want it
|
||||
-- or you just hate the highlight
|
||||
-- default: true
|
||||
highlight_hovered_item = true,
|
||||
|
||||
-- whether to show outline guides
|
||||
-- default: true
|
||||
show_guides = true,
|
||||
}
|
||||
|
||||
require("symbols-outline").setup(opts)
|
||||
|
||||
local snippets_paths = function()
|
||||
local plugins = { "friendly-snippets" }
|
||||
local paths = {}
|
||||
local path
|
||||
local root_path = vim.env.HOME .. "/.vim/plugged/"
|
||||
for _, plug in ipairs(plugins) do
|
||||
path = root_path .. plug
|
||||
if vim.fn.isdirectory(path) ~= 0 then
|
||||
table.insert(paths, path)
|
||||
end
|
||||
end
|
||||
return paths
|
||||
end
|
||||
|
||||
require("luasnip.loaders.from_vscode").lazy_load({
|
||||
paths = snippets_paths(),
|
||||
include = nil, -- Load all languages
|
||||
exclude = {},
|
||||
})
|
||||
|
||||
7
.config/nvim/after/plugin/lualine.lua
Normal file
7
.config/nvim/after/plugin/lualine.lua
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require('lualine').setup({
|
||||
options = {
|
||||
icons_enabled = true,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
33
.config/nvim/after/plugin/mason.lua
Normal file
33
.config/nvim/after/plugin/mason.lua
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
local mason_status, mason = pcall(require, "mason")
|
||||
if not mason_status then
|
||||
return
|
||||
end
|
||||
|
||||
local mason_lspconfig_status, mason_lspconfig = pcall(require, "mason-lspconfig")
|
||||
if not mason_lspconfig_status then
|
||||
return
|
||||
end
|
||||
|
||||
local mason_null_ls_status, mason_null_ls = pcall(require, "mason-null-ls")
|
||||
if not mason_null_ls_status then
|
||||
return
|
||||
end
|
||||
|
||||
mason.setup()
|
||||
|
||||
mason_lspconfig.setup({
|
||||
ensure_installed = {
|
||||
"tsserver",
|
||||
"html",
|
||||
"cssls",
|
||||
"sumneko_lua",
|
||||
}
|
||||
})
|
||||
|
||||
mason_null_ls.setup({
|
||||
ensure_installed = {
|
||||
"prettier",
|
||||
"stylua",
|
||||
"eslint_d",
|
||||
}
|
||||
})
|
||||
31
.config/nvim/after/plugin/null-ls.lua
Normal file
31
.config/nvim/after/plugin/null-ls.lua
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
local setup, null_ls = pcall(require, "null-ls")
|
||||
if not setup then
|
||||
return
|
||||
end
|
||||
|
||||
local formatting = null_ls.builtins.formatting
|
||||
local diagnostics = null_ls.builtins.diagnostics
|
||||
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
||||
|
||||
null_ls.setup({
|
||||
sources = {
|
||||
formatting.prettier,
|
||||
formatting.stylua,
|
||||
diagnostics.eslint_d
|
||||
},
|
||||
-- format on save
|
||||
on_attach = function(client, bufnr)
|
||||
if client.supports_method("textDocument/formatting") then
|
||||
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = augroup,
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
-- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead
|
||||
vim.lsp.buf.format({ bufnr = bufnr })
|
||||
end,
|
||||
})
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
36
.config/nvim/after/plugin/treesitter.lua
Normal file
36
.config/nvim/after/plugin/treesitter.lua
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
require("nvim-treesitter.configs").setup({
|
||||
-- A list of parser names, or "all"
|
||||
ensure_installed = { "ruby", "typescript", "javascript", "lua", "rust" },
|
||||
|
||||
-- Install parsers synchronously (only applied to `ensure_installed`)
|
||||
sync_install = false,
|
||||
|
||||
-- Automatically install missing parsers when entering buffer
|
||||
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
|
||||
auto_install = true,
|
||||
|
||||
---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
|
||||
-- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!
|
||||
|
||||
indent = { enable = true },
|
||||
|
||||
highlight = {
|
||||
-- `false` will disable the whole extension
|
||||
enable = true,
|
||||
|
||||
-- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files
|
||||
disable = function(_, buf)
|
||||
local max_filesize = 100 * 1024 -- 100 KB
|
||||
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
|
||||
if ok and stats and stats.size > max_filesize then
|
||||
return true
|
||||
end
|
||||
end,
|
||||
|
||||
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
|
||||
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
|
||||
-- Using this option may slow down your editor, and you may see some duplicate highlights.
|
||||
-- Instead of true it can also be a list of languages
|
||||
additional_vim_regex_highlighting = false,
|
||||
},
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue