treesitter config

This commit is contained in:
Barak Michener 2022-04-12 10:08:57 -07:00
parent 1b9408c46e
commit d8a623b5b8
16 changed files with 214 additions and 92 deletions

View file

@ -26,6 +26,35 @@ nvim_lsp.gopls.setup({ on_attach=on_attach })
nvim_lsp.pyright.setup({ on_attach=on_attach })
nvim_lsp.clangd.setup({ on_attach=on_attach })
local runtime_path = vim.split(package.path, ';')
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")
require'lspconfig'.sumneko_lua.setup {
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 = runtime_path,
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = {'vim'},
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
},
},
}
function org_imports(wait_ms)
local params = vim.lsp.util.make_range_params()
@ -298,7 +327,7 @@ require'nvim-treesitter.configs'.setup {
enable = true,
-- list of language that will be disabled
disable = { "c", "rust" },
-- disable = { "c", "rust" },
-- 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).
@ -331,6 +360,13 @@ require'nvim-treesitter.configs'.setup {
}
}
require"nvim-treesitter.highlight".set_custom_captures {
-- Highlight the @foo.bar capture group with the "Identifier" highlight group.
-- ["foo.bar"] = "Identifier",
["generic_type_param"] = "TSCGenericTypeParam",
}
require"neogen".setup {}
--
-- Helper functions for my own grepping commands.
@ -408,3 +444,30 @@ function rust_where_at_line()
vim.api.nvim_buf_set_lines(0, lineNum-1, lineNum, false, replacements)
vim.api.nvim_win_set_cursor(0, {lineNum + 2, 4})
end
function neogen_dwim()
local table = {
["function_declaration"] = "func",
["function_definition"] = "func",
["function_item"] = "func",
["function_signature_item"] = "func",
["struct_item"] = "class",
["trait_item"] = "class",
["package_clause"] = "type",
["const_declaration"] = "type",
["var_declaration"] = "type",
["class_definition"] = "class",
}
local ts_utils = require'nvim-treesitter.ts_utils'
local current_node = ts_utils.get_node_at_cursor()
while (current_node) do
local v = table[current_node:type()]
if v then
require('neogen').generate({ type = v })
break
else
current_node = current_node:parent()
end
end
end