From 83e601cf584e8c53f0a774f95c1b6bc09b406eba Mon Sep 17 00:00:00 2001 From: Wynd Date: Sat, 12 Oct 2024 21:17:29 +0300 Subject: [PATCH] Nvim deps update, C3 setup and taplo config --- .config/nvim/lazy-lock.json | 58 ++-- .../nvim/lua/nvwynd/plugins/formatting.lua | 1 + .config/nvim/lua/nvwynd/plugins/lsp.lua | 5 + .../nvim/lua/nvwynd/plugins/treesitter.lua | 14 + .config/nvim/queries/c3/highlights.scm | 323 ++++++++++++++++++ .taplo.toml | 5 + dot.toml | 3 + 7 files changed, 380 insertions(+), 29 deletions(-) create mode 100644 .config/nvim/queries/c3/highlights.scm create mode 100644 .taplo.toml diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index 047650f..6b34956 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -1,38 +1,38 @@ { "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, - "LuaSnip": { "branch": "master", "commit": "ce0a05ab4e2839e1c48d072c5236cce846a387bc" }, - "catppuccin": { "branch": "main", "commit": "2d3419c2aead379b7d1854d32458f20ffaa58562" }, + "LuaSnip": { "branch": "master", "commit": "e808bee352d1a6fcf902ca1a71cee76e60e24071" }, + "catppuccin": { "branch": "main", "commit": "7be452ee067978cdc8b2c5f3411f0c71ffa612b9" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, - "conform.nvim": { "branch": "master", "commit": "cd75be867f2331b22905f47d28c0c270a69466aa" }, - "dressing.nvim": { "branch": "master", "commit": "6741f1062d3dc6e4755367a7e9b347b553623f04" }, - "fidget.nvim": { "branch": "main", "commit": "c12f8a58ee472ce5983c3a3f3aad0ff6c49a6a83" }, - "image.nvim": { "branch": "master", "commit": "61c76515cfc3cdac8123ece9e9761b20c3dc1315" }, - "lazy.nvim": { "branch": "main", "commit": "1870238cf9c579c5d7eb8ea8b296f10b81978d34" }, - "lazydev.nvim": { "branch": "main", "commit": "cea5d0fb556cdc35122d9cae772e7e0ed65b4505" }, - "lsp-zero.nvim": { "branch": "v3.x", "commit": "87701af045b3032515776abeb47eb8c2ddb5e679" }, - "lspkind.nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" }, - "lualine.nvim": { "branch": "master", "commit": "6a40b530539d2209f7dc0492f3681c8c126647ad" }, + "conform.nvim": { "branch": "master", "commit": "40d4e98fcc3e6f485f0e8924c63734bc7e305967" }, + "dressing.nvim": { "branch": "master", "commit": "1b7921eecc65af1baf8ac1dc06f0794934cbcfb2" }, + "fidget.nvim": { "branch": "main", "commit": "d855eed8a06531a7e8fd0684889b2943f373c469" }, + "image.nvim": { "branch": "master", "commit": "88e9693e188b8464b1c426aebb4389fd9db2fcbf" }, + "lazy.nvim": { "branch": "main", "commit": "1159bdccd8910a0fd0914b24d6c3d186689023d9" }, + "lazydev.nvim": { "branch": "main", "commit": "491452cf1ca6f029e90ad0d0368848fac717c6d2" }, + "lsp-zero.nvim": { "branch": "v3.x", "commit": "56db3d5ce5476b183783160e6045f7337ba12b83" }, + "lspkind.nvim": { "branch": "master", "commit": "59c3f419af48a2ffb2320cea85e44e5a95f71664" }, + "lualine.nvim": { "branch": "master", "commit": "b431d228b7bbcdaea818bdc3e25b8cdbe861f056" }, "luvit-meta": { "branch": "main", "commit": "ce76f6f6cdc9201523a5875a4471dcfe0186eb60" }, - "mini.map": { "branch": "main", "commit": "290c3da965196d64f87050a076de9787a136e57a" }, - "mini.pairs": { "branch": "main", "commit": "927d19cbdd0e752ab1c7eed87072e71d2cd6ff51" }, - "mini.surround": { "branch": "main", "commit": "d8913ed23be0a1a4585ae34414821cc343a46174" }, - "neo-tree.nvim": { "branch": "v3.x", "commit": "29f7c215332ba95e470811c380ddbce2cebe2af4" }, - "nui.nvim": { "branch": "main", "commit": "61574ce6e60c815b0a0c4b5655b8486ba58089a1" }, - "nvim-cmp": { "branch": "main", "commit": "a110e12d0b58eefcf5b771f533fc2cf3050680ac" }, - "nvim-lspconfig": { "branch": "master", "commit": "cf97d2485fc3f6d4df1b79a3ea183e24c272215e" }, - "nvim-notify": { "branch": "master", "commit": "d333b6f167900f6d9d42a59005d82919830626bf" }, - "nvim-treesitter": { "branch": "master", "commit": "c1ad655b6a0c83ab48e55240f367e2bc0c15af31" }, - "nvim-ts-autotag": { "branch": "main", "commit": "323a3e16ed603e2e17b26b1c836d1e86c279f726" }, - "nvim-web-devicons": { "branch": "master", "commit": "c0cfc1738361b5da1cd0a962dd6f774cc444f856" }, - "plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" }, - "telescope.nvim": { "branch": "master", "commit": "bfcc7d5c6f12209139f175e6123a7b7de6d9c18a" }, - "todo-comments.nvim": { "branch": "main", "commit": "313b04e5b02d29ab9275c9295ff5e2b73921b0eb" }, - "trouble.nvim": { "branch": "main", "commit": "4453fea6bb597830fbd58d2c484612f37b97bd8c" }, - "twilight.nvim": { "branch": "main", "commit": "da4fe0a9e1397ecd9b012c52fb34313fbd3b862f" }, + "mini.map": { "branch": "main", "commit": "4c58e755d75f9999abcd3b3c6e934734b6a8b098" }, + "mini.pairs": { "branch": "main", "commit": "694d9beb488ff1afaf3d1977b067e53c827d9af5" }, + "neo-tree.nvim": { "branch": "v3.x", "commit": "a77af2e764c5ed4038d27d1c463fa49cd4794e07" }, + "nui.nvim": { "branch": "main", "commit": "b58e2bfda5cea347c9d58b7f11cf3012c7b3953f" }, + "nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" }, + "nvim-lspconfig": { "branch": "master", "commit": "d3f169f436e1b44538bfe7e13b4721eec48dbc59" }, + "nvim-notify": { "branch": "master", "commit": "fbef5d32be8466dd76544a257d3f3dce20082a07" }, + "nvim-surround": { "branch": "main", "commit": "ec2dc7671067e0086cdf29c2f5df2dd909d5f71f" }, + "nvim-treesitter": { "branch": "master", "commit": "9d2acd49976e2a9da72949008df03436f781fd23" }, + "nvim-ts-autotag": { "branch": "main", "commit": "e239a560f338be31337e7abc3ee42515daf23f5e" }, + "nvim-web-devicons": { "branch": "master", "commit": "56f17def81478e406e3a8ec4aa727558e79786f3" }, + "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" }, + "telescope.nvim": { "branch": "master", "commit": "dc6fc321a5ba076697cca89c9d7ea43153276d81" }, + "todo-comments.nvim": { "branch": "main", "commit": "ae0a2afb47cf7395dc400e5dc4e05274bf4fb9e0" }, + "trouble.nvim": { "branch": "main", "commit": "254145ffd528b98eb20be894338e2d5c93fa02c2" }, + "twilight.nvim": { "branch": "main", "commit": "1584c0b0a979b71fd86b18d302ba84e9aba85b1b" }, "vim-cool": { "branch": "master", "commit": "662e7b11064cbeedad17c45d2fe926e78d3cd0b6" }, - "which-key.nvim": { "branch": "main", "commit": "af4ded85542d40e190014c732fa051bdbf88be3d" }, - "zen-mode.nvim": { "branch": "main", "commit": "21976479c7a0146b05a42707cf91c86b1e510945" } + "which-key.nvim": { "branch": "main", "commit": "8badb359f7ab8711e2575ef75dfe6fbbd87e4821" }, + "zen-mode.nvim": { "branch": "main", "commit": "29b292bdc58b76a6c8f294c961a8bf92c5a6ebd6" } } \ No newline at end of file diff --git a/.config/nvim/lua/nvwynd/plugins/formatting.lua b/.config/nvim/lua/nvwynd/plugins/formatting.lua index 0271d51..c48caea 100644 --- a/.config/nvim/lua/nvwynd/plugins/formatting.lua +++ b/.config/nvim/lua/nvwynd/plugins/formatting.lua @@ -27,6 +27,7 @@ return { markdown = { "dprint" }, zig = { "zigfmt" }, toml = { "taplo" }, + c = { "clang-format" }, }, format_on_save = { timeout_ms = 500, diff --git a/.config/nvim/lua/nvwynd/plugins/lsp.lua b/.config/nvim/lua/nvwynd/plugins/lsp.lua index eb6a5ce..c3bcc9b 100644 --- a/.config/nvim/lua/nvwynd/plugins/lsp.lua +++ b/.config/nvim/lua/nvwynd/plugins/lsp.lua @@ -92,6 +92,11 @@ return { capabilities = capabilities, }) + -- C3 + lspconfig.c3_lsp.setup({ + capabilities = capabilities, + }) + -- Bash lspconfig.bashls.setup({ capabilities = capabilities, diff --git a/.config/nvim/lua/nvwynd/plugins/treesitter.lua b/.config/nvim/lua/nvwynd/plugins/treesitter.lua index ec2aac0..30e208a 100644 --- a/.config/nvim/lua/nvwynd/plugins/treesitter.lua +++ b/.config/nvim/lua/nvwynd/plugins/treesitter.lua @@ -2,6 +2,16 @@ return { { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate", + init = function() + local parser_config = require("nvim-treesitter.parsers").get_parser_configs() + parser_config.c3 = { + install_info = { + url = "https://github.com/c3lang/tree-sitter-c3", + files = { "src/parser.c", "src/scanner.c" }, + branch = "main", + }, + } + end, config = function() local configs = require("nvim-treesitter.configs") @@ -11,6 +21,10 @@ return { vsh = "glsl", hbs = "html", + + c3 = "c3", + c3i = "c3", + c3t = "c3", }, }) diff --git a/.config/nvim/queries/c3/highlights.scm b/.config/nvim/queries/c3/highlights.scm new file mode 100644 index 0000000..4589f13 --- /dev/null +++ b/.config/nvim/queries/c3/highlights.scm @@ -0,0 +1,323 @@ +;; NOTE In this file later patterns are assumed to have priority! + +;; Punctuation +["(" ")" "[" "]" "{" "}" "(<" ">)" "[<" ">]" "{|" "|}"] @punctuation.bracket +[";" "," ":" "::"] @punctuation.delimiter + +;; Constant +(const_ident) @constant +["true" "false"] @boolean +["null"] @constant.builtin + +;; Variable +[(ident) (ct_ident)] @variable +;; 1) Member +(field_expr field: (access_ident (ident) @variable.member)) +(struct_member_declaration (ident) @variable.member) +(struct_member_declaration (identifier_list (ident) @variable.member)) +(bitstruct_member_declaration (ident) @variable.member) +(initializer_list (arg (param_path (param_path_element (ident) @variable.member)))) +;; 2) Parameter +(parameter name: (_) @variable.parameter) +(call_invocation (arg (param_path (param_path_element [(ident) (ct_ident)] @variable.parameter)))) +(enum_param_declaration (ident) @variable.parameter) +;; 3) Declaration +(global_declaration (ident) @variable.declaration) +(local_decl_after_type name: [(ident) (ct_ident)] @variable.declaration) +(var_decl name: [(ident) (ct_ident)] @variable.declaration) +(try_unwrap (ident) @variable.declaration) +(catch_unwrap (ident) @variable.declaration) + +;; Keyword (from `c3c --list-keywords`) +[ + "assert" + "asm" + "catch" + "defer" + "try" + "var" +] @keyword + +[ + "$alignof" + "$and" + "$append" + "$assert" + "$assignable" + "$case" + "$concat" + "$default" + "$defined" + "$echo" + "$else" + "$embed" + "$endfor" + "$endforeach" + "$endif" + "$endswitch" + "$eval" + "$evaltype" + "$error" + "$exec" + "$extnameof" + "$feature" + "$for" + "$foreach" + "$if" + "$include" + "$is_const" + "$nameof" + "$offsetof" + "$or" + "$qnameof" + "$sizeof" + "$stringify" + "$switch" + "$typefrom" + "$typeof" + "$vacount" + "$vatype" + "$vaconst" + "$varef" + "$vaarg" + "$vaexpr" + "$vasplat" +] @keyword.directive + +"fn" @keyword.function +"macro" @keyword.function +"return" @keyword.return +"import" @keyword.import +"module" @keyword.module + +[ + "bitstruct" + "def" + "distinct" + "enum" + "fault" + "interface" + "struct" + "union" +] @keyword.type + +[ + "case" + "default" + "else" + "if" + "nextcase" + "switch" +] @keyword.conditional + +[ + "break" + "continue" + "do" + "for" + "foreach" + "foreach_r" + "while" +] @keyword.repeat + +[ + "const" + "extern" + "inline" + "static" + "tlocal" +] @keyword.modifier + +;; Operator (from `c3c --list-operators`) +[ + "&" + "!" + "~" + "|" + "^" + ;; ":" + ;; "," + ;; ";" + "=" + ">" + "/" + "." + ;; "#" + "<" + ;; "{" + ;; "[" + ;; "(" + "-" + "%" + "+" + "?" + ;; "}" + ;; "]" + ;; ")" + "*" + ;; "_" + "&&" + ;; "->" + "!!" + "&=" + "|=" + "^=" + "/=" + ".." + "?:" + "==" + ">=" + "=>" + "<=" + ;; "{|" + ;; "(<" + ;; "[<" + "-=" + "--" + "%=" + "*=" + "!=" + "||" + "+=" + "++" + ;; "|}" + ;; ">)" + ;; ">]" + "??" + ;; "::" + "<<" + ">>" + "..." + "<<=" + ">>=" +] @operator + +(range_expr ":" @operator) +(foreach_cond ":" @operator) + +(ternary_expr + [ + "?" + ":" + ] @keyword.conditional.ternary) + +(elvis_orelse_expr + [ + "?:" + "??" + ] @keyword.conditional.ternary) + +;; Literal +(integer_literal) @number +(real_literal) @number.float +(char_literal) @character +(bytes_literal) @number + +;; String +(string_literal) @string +(raw_string_literal) @string + +;; Escape Sequence +(escape_sequence) @string.escape + +;; Builtin (constants) +((builtin) @constant.builtin (#match? @constant.builtin "_*[A-Z][_A-Z0-9]*")) + +;; Type Property (from `c3c --list-type-properties`) +(type_access_expr (access_ident [(ident) "typeid"] @variable.builtin + (#any-of? @variable.builtin + "alignof" + "associated" + "elements" + "extnameof" + "inf" + "is_eq" + "is_ordered" + "is_substruct" + "len" + "max" + "membersof" + "min" + "nan" + "inner" + "kindof" + "names" + "nameof" + "params" + "parentof" + "qnameof" + "returns" + "sizeof" + "values" + ;; Extra token + "typeid"))) + +;; Label +[ + (label) + (label_target) +] @label + +;; Module +(module_resolution (ident) @module) +(module (path_ident (ident) @module)) +(import_declaration (path_ident (ident) @module)) + +;; Attribute +(attribute name: (_) @attribute) +(define_attribute name: (_) @attribute) +(call_inline_attributes (at_ident) @attribute) +(asm_block_stmt (at_ident) @attribute) + +;; Type +[ + (type_ident) + (ct_type_ident) +] @type +(base_type_name) @type.builtin + +;; Function Definition +(func_header name: (_) @function) +(func_header method_type: (_) name: (_) @function.method) +;; NOTE macro_declaration can also have a func_header +(macro_header name: (_) @function) +(macro_header method_type: (_) name: (_) @function.method) + +;; Function Call +(call_expr function: [(ident) (at_ident)] @function.call) +(call_expr function: [(builtin)] @function.builtin.call) +(call_expr function: (module_ident_expr ident: (_) @function.call)) +(call_expr function: (trailing_generic_expr argument: (module_ident_expr ident: (_) @function.call))) +(call_expr function: (field_expr field: (access_ident [(ident) (at_ident)] @function.method.call))) ; NOTE Ambiguous, could be calling a method or function pointer +;; Method on type +(call_expr function: (type_access_expr field: (access_ident [(ident) (at_ident)] @function.method.call))) + +;; Assignment +;; (assignment_expr left: (ident) @variable.member) +;; (assignment_expr left: (module_ident_expr (ident) @variable.member)) +;; (assignment_expr left: (field_expr field: (_) @variable.member)) +;; (assignment_expr left: (unary_expr operator: "*" @variable.member)) +;; (assignment_expr left: (subscript_expr ["[" "]"] @variable.member)) + +;; (update_expr argument: (ident) @variable.member) +;; (update_expr argument: (module_ident_expr ident: (ident) @variable.member)) +;; (update_expr argument: (field_expr field: (_) @variable.member)) +;; (update_expr argument: (unary_expr operator: "*" @variable.member)) +;; (update_expr argument: (subscript_expr ["[" "]"] @variable.member)) + +;; (unary_expr operator: ["--" "++"] argument: (ident) @variable.member) +;; (unary_expr operator: ["--" "++"] argument: (module_ident_expr (ident) @variable.member)) +;; (unary_expr operator: ["--" "++"] argument: (field_expr field: (access_ident (ident)) @variable.member)) +;; (unary_expr operator: ["--" "++"] argument: (subscript_expr ["[" "]"] @variable.member)) + +;; Asm +(asm_instr [(ident) "int"] @function.builtin) +(asm_expr [(ct_ident) (ct_const_ident)] @variable.builtin) + +;; Comment +[ + (line_comment) + (block_comment) +] @comment @spell + +(doc_comment) @comment.documentation @spell diff --git a/.taplo.toml b/.taplo.toml new file mode 100644 index 0000000..3901eb5 --- /dev/null +++ b/.taplo.toml @@ -0,0 +1,5 @@ +exclude = ["Cargo.toml"] + +[formatting] +indent_tables = true +indent_string = "\t" diff --git a/dot.toml b/dot.toml index d964d6f..b319f4d 100644 --- a/dot.toml +++ b/dot.toml @@ -4,6 +4,9 @@ path = "~/.zshrc" [[dots]] path = "~/.gitconfig" +[[dots]] +path = "~/.taplo.toml" + [[dots]] path = "~/.config/starship.toml"