Skip to content

Commit

Permalink
Add treesitter
Browse files Browse the repository at this point in the history
  • Loading branch information
JafarAbdi committed Jan 14, 2025
1 parent 34ad1d3 commit f059489
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 5 deletions.
91 changes: 90 additions & 1 deletion neovim/.config/nvim/colors/onedark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ 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
Delimiter = {}, --character that needs attention
SpecialComment = { fg = colors.comment_grey }, --special things inside a comment
Debug = {}, --debugging statements
Expand Down Expand Up @@ -129,6 +128,96 @@ local highlights = {
CmpItemAbbrMatch = { link = "PmenuMatch" },
}

local ts_highlights = {
["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
8 changes: 8 additions & 0 deletions neovim/.config/nvim/lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,13 @@
"nvim-qwahl": {
"branch": "main",
"commit": "3cc5ef866bd62f3dc74644836d47790e5b455208"
},
"nvim-treesitter": {
"branch": "master",
"commit": "984214ef8e4ca18d77639663319aabdfba89632f"
},
"nvim-treesitter-textobjects": {
"branch": "master",
"commit": "ad8f0a472148c3e0ae9851e26a722ee4e29b1595"
}
}
26 changes: 22 additions & 4 deletions scripts/.local/bin/myinstall
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,6 @@ case "${1:-}" in
popd || exit 1
;;

--help)
list_options
;;

bun)
curl -fsSL https://bun.sh/install | bash
;;
Expand All @@ -617,6 +613,28 @@ case "${1:-}" in
chmod +x ~/.local/bin/mujoco_simulator
;;

freecad)
TMP_DIR=$(mktemp -d -p /tmp install-XXXXXX)
pushd "$TMP_DIR" || exit 1
install_from_github FreeCAD/FreeCAD "FreeCAD_.*-conda-Linux-x86_64-.*.AppImage"
mv FreeCAD_*.AppImage ~/.local/bin/freecad
chmod +x ~/.local/bin/freecad
popd || exit 1
;;

meshlab)
TMP_DIR=$(mktemp -d -p /tmp install-XXXXXX)
pushd "$TMP_DIR" || exit 1
install_from_github cnr-isti-vclab/meshlab "MeshLab.*linux.AppImage"
mv MeshLab*.AppImage ~/.local/bin/meshlab
chmod +x ~/.local/bin/meshlab
popd || exit 1
;;

--help)
list_options
;;

*)
info "Usage: $(basename "$0") <option>" >&2
info "Available options:"
Expand Down

0 comments on commit f059489

Please sign in to comment.