lua stuff

This commit is contained in:
Christian Nieves
2022-10-18 16:45:09 +00:00
parent 450dd13e5b
commit 21837e0336
43 changed files with 503 additions and 239 deletions

View File

@ -0,0 +1,87 @@
require("catppuccin").setup({
compile_path = vim.fn.stdpath("cache") .. "/catppuccin",
transparent_background = false,
term_colors = false,
dim_inactive = {
enabled = false,
shade = "dark",
percentage = 0.15,
},
styles = {
comments = { "italic" },
conditionals = { "italic" },
loops = {},
functions = {},
keywords = {},
strings = {},
variables = {},
numbers = {},
booleans = {},
properties = {},
types = {},
operators = {},
},
integrations = {
cmp = true,
-- coc_nvim = false,
dashboard = true,
-- fern = false,
fidget = true,
gitgutter = true,
gitsigns = true,
-- hop = false,
-- illuminate = false,
-- leap = false,
-- lightspeed = false,
-- lsp_saga = false,
lsp_trouble = true,
-- mason = true,
-- markdown = true,
-- neogit = false,
-- neotest = false,
-- neotree = false,
notify = true,
-- nvimtree = true,
-- overseer = false,
-- pounce = false,
symbols_outline = true,
telescope = true,
treesitter = true,
-- treesitter_context = false,
-- ts_rainbow = false,
-- vim_sneak = false,
-- vimwiki = false,
-- which_key = false,
-- Special integrations, see https://github.com/catppuccin/nvim#special-integrations
dap = {
enabled = false,
enable_ui = false,
},
indent_blankline = {
enabled = true,
colored_indent_levels = false,
},
native_lsp = {
enabled = true,
virtual_text = {
errors = { "italic" },
hints = { "italic" },
warnings = { "italic" },
information = { "italic" },
},
underlines = {
errors = { "underline" },
hints = { "underline" },
warnings = { "underline" },
information = { "underline" },
},
},
navic = {
enabled = false,
custom_bg = "NONE",
},
},
color_overrides = {},
custom_highlights = {},
})

View File

@ -0,0 +1,14 @@
local M = {}
local lsp_util = vim.lsp.util
function M.code_action_listener()
local context = { diagnostics = vim.lsp.diagnostic.get_line_diagnostics() }
local params = lsp_util.make_range_params()
params.context = context
vim.lsp.buf_request(0, 'textDocument/codeAction', params, function(err, _, result)
-- do something with result - e.g. check if empty and show some indication such as a sign
end)
end
return M

View File

@ -0,0 +1,59 @@
-- Diagnostics
require("trouble").setup({
position = "bottom", -- position of the list can be: bottom, top, left, right
height = 10, -- height of the trouble list when position is top or bottom
width = 50, -- width of the list when position is left or right
icons = true, -- use devicons for filenames
mode = "workspace_diagnostics", -- "workspace_diagnostics", "document_diagnostics", "quickfix", "lsp_references", "loclist"
fold_open = "", -- icon used for open folds
fold_closed = "", -- icon used for closed folds
group = true, -- group results by file
padding = true, -- add an extra new line on top of the list
action_keys = { -- key mappings for actions in the trouble list
-- map to {} to remove a mapping, for example:
-- close = {},
close = "q", -- close the list
cancel = "<esc>", -- cancel the preview and get back to your last window / buffer / cursor
refresh = "r", -- manually refresh
jump = { "<cr>", "<tab>" }, -- jump to the diagnostic or open / close folds
open_split = { "<c-x>" }, -- open buffer in new split
open_vsplit = { "<c-v>" }, -- open buffer in new vsplit
open_tab = { "<c-t>" }, -- open buffer in new tab
jump_close = { "o" }, -- jump to the diagnostic and close the list
toggle_mode = "m", -- toggle between "workspace" and "document" diagnostics mode
toggle_preview = "P", -- toggle auto_preview
hover = "L", -- opens a small popup with the full multiline message
preview = "p", -- preview the diagnostic location
close_folds = { "zM", "zm" }, -- close all folds
open_folds = { "zR", "zr" }, -- open all folds
toggle_fold = { "zA", "za" }, -- toggle fold of current file
previous = "k", -- preview item
next = "j", -- next item
},
indent_lines = true, -- add an indent guide below the fold icons
auto_open = false, -- automatically open the list when you have diagnostics
auto_close = true, -- automatically close the list when you have no diagnostics
auto_preview = true, -- automatically preview the location of the diagnostic. <esc> to close preview and go back to last window
auto_fold = false, -- automatically fold a file trouble list at creation
auto_jump = { "lsp_definitions" }, -- for the given modes, automatically jump if there is only a single result
signs = {
-- icons / text used for a diagnostic
error = '',
warning = '',
hint = '',
information = '',
other = "",
},
use_diagnostic_signs = false, -- enabling this will use the signs defined in your lsp client
})
-- Mappings
local opts = { noremap = true, silent = true }
vim.api.nvim_set_keymap("n", "gr", "<Cmd>Trouble lsp_references<CR>", opts)
vim.api.nvim_set_keymap("n", "<Leader>xx", "<Cmd>Trouble<CR>", opts)
vim.api.nvim_set_keymap("n", "<Leader>xw", "<Cmd>Trouble workspace_diagnostics<CR>", opts)
vim.api.nvim_set_keymap("n", "<Leader>xd", "<Cmd>Trouble document_diagnostics<CR>", opts)
vim.api.nvim_set_keymap("n", "<Leader>xl", "<Cmd>Trouble loclist<CR>", opts)
vim.api.nvim_set_keymap("n", "<Leader>xq", "<Cmd>Trouble quickfix<CR>", opts)
vim.api.nvim_set_keymap("n", "[g", "<cmd>lua vim.diagnostic.goto_prev()<CR>", opts)
vim.api.nvim_set_keymap("n", "]g", "<cmd>lua vim.diagnostic.goto_next()<CR>", opts)

235
vim/.vim/lua/lsp.lua Normal file
View File

@ -0,0 +1,235 @@
-- 1. Configure CiderLSP
local nvim_lsp = require("lspconfig")
local configs = require("lspconfig.configs")
configs.ciderlsp = {
default_config = {
cmd = { "/google/bin/releases/cider/ciderlsp/ciderlsp", "--tooltag=nvim-lsp", "--forward_sync_responses", "--enable_semantic_tokens", "--relay_mode=true", "--hub_addr=blade:languageservices-staging" ,"--enable_document_highlight"},
-- cmd = {'/google/bin/releases/cider/ciderlsp/ciderlsp', '--forward_sync_responses', '--enable_document_highlight'};
filetypes = { "c", "cpp", "java", "kotlin", "proto", "textproto", "go", "python", "bzl" },
root_dir = nvim_lsp.util.root_pattern("BUILD"),
settings = {},
},
}
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
-- 2. Configure CMP
vim.opt.completeopt = { "menu", "menuone", "noselect" }
-- Don't show the dumb matching stuff
vim.opt.shortmess:append("c")
local lspkind = require("lspkind")
lspkind.init()
local cmp = require("cmp")
cmp.setup({
mapping = {
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-u>"] = cmp.mapping.scroll_docs(4),
["<C-e>"] = cmp.mapping.close(),
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
["<C-m>"] = cmp.mapping.confirm({ select = true }),
["<CR>"] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn["vsnip#available"](1) == 1 then
feedkey("<Plug>(vsnip-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 vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
end
end, { "i", "s" }),
["<Up>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn["vsnip#available"](1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
end
end),
["<Down>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn["vsnip#available"](1) == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
end
end),
},
sources = {
{ name = "nvim_lua" },
{ name = "nvim_lsp" },
{ name = "path" },
{ name = "vim_vsnip" },
{ name = 'nvim_ciderlsp', priority = 9 },
{ name = "buffer", keyword_length = 5 },
},
sorting = {
comparators = {
cmp.config.compare.offset,
cmp.config.compare.exact,
cmp.config.compare.score,
function(entry1, entry2)
local _, entry1_under = entry1.completion_item.label:find("^_+")
local _, entry2_under = entry2.completion_item.label:find("^_+")
entry1_under = entry1_under or 0
entry2_under = entry2_under or 0
if entry1_under > entry2_under then
return false
elseif entry1_under < entry2_under then
return true
end
end,
cmp.config.compare.kind,
cmp.config.compare.sort_text,
cmp.config.compare.length,
cmp.config.compare.order,
},
},
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
formatting = {
format = lspkind.cmp_format({
with_text = true,
maxwidth = 40, -- half max width
menu = {
nvim_ciderlsp = "[🤖]",
buffer = "[buffer]",
nvim_lsp = "[CiderLSP]",
nvim_lua = "[API]",
path = "[path]",
vim_vsnip = "[snip]",
},
}),
},
experimental = {
native_menu = false,
ghost_text = true,
},
})
vim.cmd([[
augroup CmpZsh
au!
autocmd Filetype zsh lua require'cmp'.setup.buffer { sources = { { name = "zsh" }, } }
augroup END
]])
local cider_lsp_handlers = {
["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
underline = true,
})
}
cider_lsp_handlers["$/syncResponse"] = function(_, result, ctx)
-- is_cider_lsp_attached has been setup via on_init, but hasn't received
-- sync response yet.
local first_fire = vim.b['is_cider_lsp_attached'] == 'no'
vim.b['is_cider_lsp_attached'] = 'yes'
if first_fire then
require('notify')('CiderLSP attached', 'info', {timeout=150})
require('lualine').refresh()
end
end
cider_lsp_handlers["workspace/diagnostic/refresh"] = function(_, result, ctx)
VPrint('result:')
VPrint(result)
VPrint('ctx:')
VPrint(ctx)
end
-- 3. Set up CiderLSP
local on_attach = function(client, bufnr)
vim.b['is_cider_lsp_attached'] = 'no'
require('lualine').refresh()
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
if vim.lsp.formatexpr then -- Neovim v0.6.0+ only.
vim.api.nvim_buf_set_option(bufnr, "formatexpr", "v:lua.vim.lsp.formatexpr")
end
if vim.lsp.tagfunc then
vim.api.nvim_buf_set_option(bufnr, "tagfunc", "v:lua.vim.lsp.tagfunc")
end
local opts = { noremap = true, silent = true }
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "L", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "g0", "<cmd>lua vim.lsp.buf.document_symbol()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "gW", "<cmd>lua vim.lsp.buf.workspace_symbol()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<cmd>tab split | lua vim.lsp.buf.definition()<CR>", opts)
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "grf", "<cmd>lua vim.lsp.buf.references()<CR>", opts) -- diagnostics controls references
vim.api.nvim_buf_set_keymap(bufnr, "n", "<C-g>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "i", "<C-g>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "gt", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
vim.api.nvim_command("augroup LSP")
vim.api.nvim_command("autocmd!")
if client.resolved_capabilities.document_highlight then
vim.api.nvim_command("autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()")
vim.api.nvim_command("autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()")
vim.api.nvim_command("autocmd CursorMoved <buffer> lua vim.lsp.util.buf_clear_references()")
end
vim.api.nvim_command("augroup END")
end
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
capabilities = require('cmp_nvim_ciderlsp').update_capabilities(capabilities)
capabilities['codeLens'] = {dynamicRegistration=false}
-- capabilities.workspace.codeLens = {refreshSupport=true}
-- capabilities.workspace.diagnostics = {refreshSupport=true}
capabilities.textDocument.publishDiagnostics={
relatedInformation=true,
versionSupport=false,
tagSupport={
valueSet={
1,
2
}
},
codeDescriptionSupport=true,
dataSupport=true,
--layeredDiagnostics=true
}
nvim_lsp.ciderlsp.setup({
capabilities = capabilities,
on_attach = on_attach,
handlers = cider_lsp_handlers,
})

View File

@ -0,0 +1,77 @@
local split = function (inputstr, sep)
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
local function getWords()
return tostring(vim.fn.wordcount().words)
end
local function getCitc()
local fname = vim.api.nvim_buf_get_name(0)
if string.find(fname, '/google/src/cloud/', 1, true) then
local parts = split(fname, '/')
return parts[5]
end
end
function isCiderLspAttached()
if vim.b['is_cider_lsp_attached'] then
if vim.b['is_cider_lsp_attached'] == 'yes' then
return ''
else
return 'CiderLSP loading..'
end
else
return ''
end
end
local function getLightbulb()
return require('nvim-lightbulb').get_status_text()
end
require('lualine').setup {
options = {
theme = 'auto',
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
}
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', getCitc, isCiderLspAttached},
lualine_c = {'filename', {"aerial", depth=-1}, getLightbulb},
lualine_x = {'filetype'},
lualine_x = {
{ 'diagnostics', sources = {"nvim_lsp"}, symbols = {error = '', warn = '', info = '', hint = ''} },
'encoding',
'filetype'
},
lualine_y = {},
lualine_z = {'location'}
},
-- default
-- 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 = {
lualine_a = {},
lualine_b = {},
-- lualine_c = {'filename'},
lualine_x = {'location'},
lualine_y = {},
lualine_z = {}
},
-- tabline = {},
-- winbar = {},
-- inactive_winbar = {},
-- extensions = {}
}

View File

@ -0,0 +1,4 @@
local colors = require("catppuccin.palettes").get_palette()
require("notify").setup({
background_colour = colors.base,
})

18
vim/.vim/lua/plugins.lua Normal file
View File

@ -0,0 +1,18 @@
-- Require CiderLSP and Diagnostics modules
-- IMPORTANT: Must come after plugins are loaded
-- CiderLSP
vim.opt.completeopt = { "menu", "menuone", "noselect" }
require 'lspconfig'
require("lsp")
require("diagnostics")
require("treesitter")
require("telescope_config")
require("lualine_config")
require("notify_config")
require("catppuccin-config")
require("symbols-outline-config")
require "fidget".setup{}

View File

@ -0,0 +1,4 @@
require("symbols-outline").setup()
local map = require("utils").map
map('n', '<leader>so', ':SymbolsOutline<cr>')

View File

@ -0,0 +1,99 @@
require('telescope').setup {
defaults = {
-- The vertical layout strategy is good to handle long paths like those in
-- google3 repos because you have nearly the full screen to display a file path.
-- The caveat is that the preview area is smaller.
layout_strategy = 'vertical',
-- Common paths in google3 repos are collapsed following the example of Cider
-- It is nice to keep this as a user config rather than part of
-- telescope-codesearch because it can be reused by other telescope pickers.
path_display = function(opts, path)
-- Do common substitutions
path = path:gsub("^/google/src/cloud/[^/]+/[^/]+/google3/", "google3/", 1)
path = path:gsub("^google3/java/com/google/", "g3/j/c/g/", 1)
path = path:gsub("^google3/javatests/com/google/", "g3/jt/c/g/", 1)
path = path:gsub("^google3/third_party/", "g3/3rdp/", 1)
path = path:gsub("^google3/", "g3/", 1)
-- Do truncation. This allows us to combine our custom display formatter
-- with the built-in truncation.
-- `truncate` handler in transform_path memoizes computed truncation length in opts.__length.
-- Here we are manually propagating this value between new_opts and opts.
-- We can make this cleaner and more complicated using metatables :)
local new_opts = {
path_display = {
truncate = true,
},
__length = opts.__length,
}
path = require('telescope.utils').transform_path(new_opts, path)
opts.__length = new_opts.__length
return path
end,
},
extensions = { -- this block is optional, and if omitted, defaults will be used
codesearch = {
experimental = true -- enable results from google3/experimental
}
}
}
local map = require("utils").map
-- These custom mappings let you open telescope-codesearch quickly:
map('n', '<C-P>',
[[<cmd>lua require('telescope').extensions.codesearch.find_files{}<CR>]],
{ noremap = true, silent=true }
)
-- Search using codesearch queries.
map(
"n",
"<leader>cs",
[[<cmd>lua require('telescope').extensions.codesearch.find_query{}<CR>]],
{ noremap = true, silent = true }
)
--
-- Search for files using codesearch queries.
map(
"n",
"<leader>cf",
[[<cmd>lua require('telescope').extensions.codesearch.find_files{}<CR>]],
{ noremap = true, silent = true }
)
-- Search for the word under cursor.
map(
"n",
"<leader>CS",
[[<cmd>lua require('telescope').extensions.codesearch.find_query{default_text_expand='<cword>'}<CR>]],
{ noremap = true, silent = true }
)
-- Search for a file having word under cursor in its name.
map(
"n",
"<leader>CF",
[[<cmd>lua require('telescope').extensions.codesearch.find_files{default_text_expand='<cword>'}<CR>]],
{ noremap = true, silent = true }
)
-- Search for text selected in Visual mode.
map(
"v",
"<leader>cs",
[[<cmd>lua require('telescope').extensions.codesearch.find_query{}<CR>]],
{ noremap = true, silent = true }
)
-- Search for file having text selected in Visual mode.
map(
"v",
"<leader>cf",
[[<cmd>lua require('telescope').extensions.codesearch.find_files{}<CR>]],
{ noremap = true, silent = true }
)
map("n",
"<leader>ps",
[[:Telescope find_files find_command=hg,pstatus,-ma,-n,--template=<CR>]])

View File

@ -0,0 +1,21 @@
require('nvim-treesitter.configs').setup {
-- A list of parser names, or "all"
-- ensure_installed = { "c", "lua", "vim", "java", "kotlin"},
ensure_installed = "all",
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
highlight = {
-- `false` will disable the whole extension
enable = true,
disable = {"java"},
-- 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,
},
}

11
vim/.vim/lua/utils.lua Normal file
View File

@ -0,0 +1,11 @@
local M = {}
function M.map(mode, lhs, rhs, opts)
local options = { noremap = true }
if opts then
options = vim.tbl_extend("force", options, opts)
end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
return M