complete refactor with kickstart.nvim

This commit is contained in:
Rahsheen Porter 2023-02-04 18:11:52 -05:00
parent f3d84f90cd
commit 897d00ad32
16 changed files with 571 additions and 404 deletions

View file

@ -1,5 +0,0 @@
vim.g.tokyonight_transparent_sidebar = true
vim.g.tokyonight_transparent = true
vim.opt.background = "dark"
vim.cmd("colorscheme tokyonight")

View file

@ -0,0 +1,2 @@
require("rahcodes.remap")
require("rahcodes.sets")

View file

@ -1 +0,0 @@

View file

@ -1,131 +0,0 @@
local lsp = require("lsp-zero")
lsp.preset("recommended")
lsp.ensure_installed({
"tsserver",
"eslint",
"sumneko_lua",
"rust_analyzer",
})
local Remap = require("rahcodes.keymap")
local nnoremap = Remap.nnoremap
local inoremap = Remap.inoremap
-- Setup nvim-cmp.
local cmp = require("cmp")
local cmp_select = { behavior = cmp.SelectBehavior.Select }
local cmp_mappings = lsp.defaults.cmp_mappings({
["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4),
["<C-n>"] = cmp.mapping.select_next_item(cmp_select),
["<C-p>"] = cmp.mapping.select_prev_item(cmp_select),
["<C-y>"] = cmp.mapping.confirm({ select = true }),
["<C-Space>"] = cmp.mapping.complete(),
})
lsp.setup_nvim_cmp({
mapping = cmp_mappings,
})
lsp.configure("solargraph", {
settings = {
solargraph = {
diagnostics = false,
},
},
on_attach = function()
print("hello solargraph")
end,
})
lsp.configure("sumneko_lua", {
settings = {
Lua = {
diagnostics = { globals = { "vim" } },
},
},
})
lsp.on_attach = function(client, bufnr)
-- Disable LSP server formatting, to prevent formatting twice.
-- Once by the LSP server, second time by NULL-ls.
if client.name == "volar" or client.name == "tsserver" then
client.server_capabilities.documentFormattingProvider = false
client.server_capabilities.documentFormattingRangeProvider = false
end
local opts = { buffer = bufnr, remap = false }
nnoremap("gd", function()
vim.lsp.buf.definition()
end, opts)
nnoremap("gD", function()
vim.lsp.buf.definition()
end, opts)
nnoremap("K", function()
vim.lsp.buf.hover()
end, opts)
nnoremap("gi", function()
vim.lsp.buf.implementation()
end, opts)
nnoremap("<leader>wa", function()
vim.lsp.buf.add_workspace_folder()
end, opts)
nnoremap("<leader>wr", function()
vim.lsp.buf.remove_workspace_folder()
end, opts)
nnoremap("<leader>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
nnoremap("<leader>vws", function()
vim.lsp.buf.workspace_symbol()
end, opts)
nnoremap("<leader>vd", function()
vim.diagnostic.open_float()
end, opts)
nnoremap("[d", function()
vim.diagnostic.goto_next()
end, opts)
nnoremap("]d", function()
vim.diagnostic.goto_prev()
end, opts)
nnoremap("<leader>ca", function()
vim.lsp.buf.code_action()
end, opts)
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, opts)
nnoremap("<leader>gr", function()
vim.lsp.buf.references()
end, opts)
nnoremap("<leader>rn", function()
vim.lsp.buf.rename()
end, opts)
inoremap("<C-h>", function()
vim.lsp.buf.signature_help()
end, opts)
nnoremap("<leader>f", function()
vim.lsp.buf.format({ async = true })
end, opts)
end
lsp.setup()
local mason_nullls = require("mason-null-ls")
mason_nullls.setup({
automatic_installation = true,
automatic_setup = true,
})
mason_nullls.setup_handlers({})

View file

@ -1,7 +0,0 @@
require('lualine').setup({
options = {
icons_enabled = true,
}
})

View file

@ -9,9 +9,24 @@ local conditional = function(fn)
return fn(utils)
end
local lsp_formatting = function(bufnr)
vim.lsp.buf.format({
timeout_ms = 2000,
filter = function(client)
-- apply whatever logic you want (in this example, we'll only use null-ls)
return client.name ~= "tsserver"
end,
bufnr = bufnr,
})
end
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
-- local my_rubocop_formatter = require("rahcodes.null-ls.rubocop")
local rubocop = null_ls.builtins.formatting.rubocop
null_ls.setup({
debug = true,
sources = {
formatting.prettier,
formatting.stylua,
@ -19,20 +34,20 @@ null_ls.setup({
-- Here we set a conditional to call the rubocop formatter. If we have a Gemfile in the project, we call "bundle exec rubocop", if not we only call "rubocop".
conditional(function(utils)
return utils.root_has_file("Gemfile")
and null_ls.builtins.formatting.rubocop.with({
command = "bundle",
args = vim.list_extend({ "exec", "rubocop" }, null_ls.builtins.formatting.rubocop._opts.args),
})
or null_ls.builtins.formatting.rubocop
and rubocop.with({
command = "bundle",
args = vim.list_extend({ "exec", "rubocop" }, rubocop._opts.args),
})
or rubocop
end),
-- Same as above, but with diagnostics.rubocop to make sure we use the proper rubocop version for the project
conditional(function(utils)
return utils.root_has_file("Gemfile")
and null_ls.builtins.diagnostics.rubocop.with({
command = "bundle",
args = vim.list_extend({ "exec", "rubocop" }, null_ls.builtins.diagnostics.rubocop._opts.args),
})
and null_ls.builtins.diagnostics.rubocop.with({
command = "bundle",
args = vim.list_extend({ "exec", "rubocop" }, null_ls.builtins.diagnostics.rubocop._opts.args),
})
or null_ls.builtins.diagnostics.rubocop
end),
},
@ -44,7 +59,7 @@ null_ls.setup({
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({ bufnr = bufnr, timeout_ms = 10000 })
lsp_formatting(bufnr)
end,
})
end

View file

@ -1,30 +0,0 @@
local actions = require("telescope.actions")
local telescope = require("telescope")
telescope.setup({
extensions = {
fzf = {
fuzzy = true, -- false will only do exact matching
override_generic_sorter = true, -- override the generic sorter
override_file_sorter = true, -- override the file sorter
case_mode = "smart_case", -- or "ignore_case" or "respect_case"
-- the default case_mode is "smart_case"
},
},
})
local builtin = require("telescope.builtin")
vim.keymap.set("n", "<leader>ff", builtin.find_files, {})
vim.keymap.set("n", "<leader>/", builtin.live_grep, {})
vim.keymap.set("n", "<leader>*", builtin.grep_string, {})
vim.keymap.set("n", "<leader>fb", builtin.buffers, {})
vim.keymap.set("n", "<leader>fh", builtin.help_tags, {})
vim.keymap.set("n", "<leader>m", builtin.oldfiles, {})
vim.keymap.set("n", "<leader>gb", builtin.git_branches, {})
vim.keymap.set("n", "<leader><leader>", builtin.git_files, {})
vim.keymap.set("n", "<leader>ps", function()
builtin.grep_string({ search = vim.fn.input("Grep > ") })
end)
telescope.load_extension("fzf")

View file

@ -1,36 +0,0 @@
require("nvim-treesitter.configs").setup({
-- A list of parser names, or "all"
ensure_installed = { "ruby", "typescript", "javascript", "lua", "rust", "typescript" },
-- 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,
},
})