Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treesitter support #145

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 93 additions & 1 deletion neovim/.config/nvim/colors/onedark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ local highlights = {
Typedef = { fg = colors.yellow }, --A typedef
Special = { fg = colors.blue }, --any special symbol
SpecialChar = { fg = colors.dark_yellow }, --special character in a constant
Tag = {}, --you can use CTRL-] on this
-- Tag = {}, --you can use CTRL-] on this
Delimiter = {}, --character that needs attention
SpecialComment = { fg = colors.comment_grey }, --special things inside a comment
Debug = {}, --debugging statements
Expand Down Expand Up @@ -129,6 +129,98 @@ local highlights = {
CmpItemAbbrMatch = { link = "PmenuMatch" },
}

local ts_highlights = {
-- ["error"] = "TSError",
-- ["variable"] = "TSVariable",
["none"] = { default = true },
["punctuation.delimiter"] = { link = "Delimiter", default = true },
["punctuation.bracket"] = { link = "Delimiter", default = true },
["punctuation.special"] = { link = "Delimiter", default = true },

["constant"] = { link = "Constant", default = true },
["constant.builtin"] = { link = "Special", default = true },
["constant.macro"] = { link = "Define", default = true },
["string"] = { link = "String", default = true },
["string.regex"] = { link = "String", default = true },
["string.escape"] = { link = "SpecialChar", default = true },
["string.special"] = { link = "SpecialChar", default = true },
["character"] = { link = "Character", default = true },
["character.special"] = { link = "SpecialChar", default = true },
["number"] = { link = "Number", default = true },
["boolean"] = { link = "Boolean", default = true },
["float"] = { link = "Float", default = true },

["function"] = { link = "Function", default = true },
["function.call"] = { link = "@function", default = true },
["function.builtin"] = { link = "Special", default = true },
["function.macro"] = { link = "Macro", default = true },
["parameter"] = { link = "Identifier", default = true },
["parameter.reference"] = { link = "@parameter", default = true },
["method"] = { link = "Function", default = true },
["method.call"] = { link = "@method", default = true },
["field"] = { link = "Identifier", default = true },
["property"] = { link = "Identifier", default = true },
["constructor"] = { link = "Special", default = true },
["annotation"] = { link = "PreProc", default = true },
["attribute"] = { link = "PreProc", default = true },
["namespace"] = { link = "Include", default = true },
["symbol"] = { link = "Identifier", default = true },
["conditional"] = { link = "Conditional", default = true },
["repeat"] = { link = "Repeat", default = true },
["label"] = { link = "Label", default = true },
["operator"] = { link = "Operator", default = true },
["keyword"] = { link = "Keyword", default = true },
["keyword.function"] = { link = "Keyword", default = true },
["keyword.operator"] = { link = "@operator", default = true },
["keyword.return"] = { link = "@keyword", default = true },
["exception"] = { link = "Exception", default = true },
["debug"] = { link = "Debug", default = true },
["define"] = { link = "Define", default = true },
["preproc"] = { link = "PreProc", default = true },
["storageclass"] = { link = "StorageClass", default = true },

["todo"] = { link = "Todo", default = true },

["type"] = { link = "Type", default = true },
["type.builtin"] = { link = "Type", default = true },
["type.qualifier"] = { link = "Type", default = true },
["type.definition"] = { link = "Typedef", default = true },

["include"] = { link = "Include", default = true },

["variable.builtin"] = { link = "Special", default = true },

["text"] = { link = "@none", default = true },
["text.strong"] = { bold = true, default = true },
["text.emphasis"] = { italic = true, default = true },
["text.underline"] = { underline = true },
["text.strike"] = { strikethrough = true },
["text.math"] = { link = "Special", default = true },
["text.reference"] = { link = "Constant", default = true },
["text.environment"] = { link = "Macro", default = true },
["text.environment.name"] = { link = "Type", default = true },
["text.title"] = { link = "Title", default = true },
["text.literal"] = { link = "String", default = true },
["text.uri"] = { link = "Underlined", default = true },
["text.note"] = { fg = colors.cyan },
["text.warning"] = { link = "Todo", default = true },
["text.danger"] = { link = "WarningMsg", default = true },

["comment"] = { link = "Comment", default = true },

["tag"] = { link = "Label", default = true },
["tag.delimiter"] = { link = "Delimiter", default = true },
["tag.attribute"] = { link = "@property", default = true },
}

--- Hide all semantic highlights
for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
vim.api.nvim_set_hl(0, group, {})
end
for capture, hlgroup in pairs(ts_highlights) do
vim.api.nvim_set_hl(0, "@" .. capture, hlgroup)
end

vim.api.nvim_set_hl(0, "@lsp.type.comment.cpp", { link = "Comment", default = true })
for group, keys in pairs(highlights) do
vim.api.nvim_set_hl(0, group, keys)
Expand Down
108 changes: 108 additions & 0 deletions neovim/.config/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,113 @@ require("lazy").setup({
})
end,
},
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
event = { "VeryLazy" },
dependencies = {
"nvim-treesitter/nvim-treesitter-textobjects",
},
opts = {
ensure_installed = {
"bash",
"c",
"c_sharp",
"cmake",
"cpp",
"dockerfile",
"fish",
"html",
"xml",
"http",
"javascript",
"json",
"lua",
"comment",
"make",
"markdown",
"ninja",
"proto",
"python",
"query",
"rst",
"rust",
"toml",
"typescript",
"vim",
"vimdoc",
"yaml",
"zig",
},
highlight = {
enable = true,
disable = function(lang, buf)
return (lang == "html")
-- Disable highlighting for files without a filetype
or (vim.api.nvim_buf_get_option(buf, "filetype") == "")
end,
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<A-w>",
node_incremental = "<A-w>",
scope_incremental = "<A-e>",
node_decremental = "<A-S-w>",
},
},
textobjects = {
select = {
enable = true,
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
keymaps = {
["af"] = "@function.outer",
["if"] = "@function.inner",
["ac"] = "@class.outer",
["ic"] = "@class.inner",
["ap"] = "@parameter.outer",
["ip"] = "@parameter.inner",
["ao"] = "@conditional.outer",
["io"] = "@conditional.inner",
["al"] = "@loop.outer",
["il"] = "@loop.inner",
},
},
swap = {
enable = true,
swap_next = {
["<leader>a"] = "@parameter.inner",
},
swap_previous = {
["<leader>A"] = "@parameter.inner",
},
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
["]f"] = "@function.outer",
["]c"] = "@class.outer",
},
goto_next_end = {
["]F"] = "@function.outer",
["]C"] = "@class.outer",
},
goto_previous_start = {
["[f"] = "@function.outer",
["[c"] = "@class.outer",
},
goto_previous_end = {
["[F"] = "@function.outer",
["[C"] = "@class.outer",
},
},
},
},
config = function(_, opts)
require("nvim-treesitter.configs").setup(opts)
end,
},
}, {
defaults = {
lazy = true, -- every plugin is lazy-loaded by default
Expand Down Expand Up @@ -1591,6 +1698,7 @@ end
vim.g.mapleader = " "
vim.g.maplocalleader = " "

vim.treesitter.language.register("xml", { "xacro", "urdf" })
vim.filetype.add({
extension = {
launch = "xml",
Expand Down