Squashed 'src/syntax/' changes from d5b5da5..ba10d89
ba10d89 Merge remote-tracking branch 'origin/master' 0b0cb14 feat: add mail file type support eda5f22 feat: add descriptive names for file types 5be7cbf feat: add xml formatter 2dd75f9 feat: add pyi to python file extensions cba2de6 Merge remote-tracking branch 'origin/master' 017c727 feat: add odin support 78f312e feat: add cmake support be71fff feat: add cmake support 40e4f73 feat: add expand/shrink_selection and select_next/prev_sibling commands 3e42e08 refactor: run zig fmt 9eb5c4c fix: add --stdin to gleam format 2345f2f feat: add gleam formatter 76c493d feat: add gleam to file types 66a5663 feat: update tree-sitter to add gleam support 3673787 feat: add julia support d91691c fix: remove obsolete and broken syntax.refresh function e7401e0 feat: add syntax.refresh_from_string utility function 812b66f fix: add swiftinterface as a swift file extension b0b6e46 feat: add support for the swift language dcfa5cd feat: add hare to syntax file types b5c309f build: update tree-sitter for new zig parser and hare support dbdc9a8 feat: add go formatter to file types d5fcdb1 feat: add ruby lsp to file type config b2a2981 fix: typo in first line match for file type python 71fdb49 fix: prefer to treat .h files as c++ 0498ae3 refactor: zig fmt all source files 57dfa2e feat: add command to toggle syntax highlighting (S-F10) b31fb25 feat: make --no-syntax just disable syntax highlighting and not language server support git-subtree-dir: src/syntax git-subtree-split: ba10d89670e19004bd3b958a407afc087c33ca9f
This commit is contained in:
parent
fc44208892
commit
bdfae74f94
5 changed files with 199 additions and 18 deletions
11
build.zig
11
build.zig
|
@ -17,6 +17,7 @@ pub fn build(b: *std.Build) void {
|
||||||
const imports: []const std.Build.Module.Import = if (use_tree_sitter) &.{
|
const imports: []const std.Build.Module.Import = if (use_tree_sitter) &.{
|
||||||
.{ .name = "build_options", .module = options_mod },
|
.{ .name = "build_options", .module = options_mod },
|
||||||
.{ .name = "treez", .module = tree_sitter_dep.module("treez") },
|
.{ .name = "treez", .module = tree_sitter_dep.module("treez") },
|
||||||
|
ts_queryfile(b, tree_sitter_dep, "queries/cmake/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-agda/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-agda/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-bash/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-bash/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-c-sharp/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-c-sharp/queries/highlights.scm"),
|
||||||
|
@ -28,16 +29,20 @@ pub fn build(b: *std.Build) void {
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-elixir/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-elixir/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-git-rebase/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-git-rebase/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-gitcommit/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-gitcommit/queries/highlights.scm"),
|
||||||
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-gleam/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-go/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-go/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-fish/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-fish/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-haskell/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-haskell/queries/highlights.scm"),
|
||||||
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-hare/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-html/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-html/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-java/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-java/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-javascript/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-javascript/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-jsdoc/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-jsdoc/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-json/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-json/queries/highlights.scm"),
|
||||||
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-julia/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-kdl/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-kdl/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-lua/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-lua/queries/highlights.scm"),
|
||||||
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-mail/queries/mail/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-make/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-make/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-markdown/tree-sitter-markdown/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-markdown/tree-sitter-markdown/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-markdown/tree-sitter-markdown-inline/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-markdown/tree-sitter-markdown-inline/queries/highlights.scm"),
|
||||||
|
@ -47,6 +52,7 @@ pub fn build(b: *std.Build) void {
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-nix/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-nix/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-nu/queries/nu/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-nu/queries/nu/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-ocaml/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-ocaml/queries/highlights.scm"),
|
||||||
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-odin/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-openscad/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-openscad/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-org/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-org/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-php/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-php/queries/highlights.scm"),
|
||||||
|
@ -59,6 +65,7 @@ pub fn build(b: *std.Build) void {
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-scala/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-scala/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-scheme/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-scheme/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-superhtml/tree-sitter-superhtml/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-superhtml/tree-sitter-superhtml/queries/highlights.scm"),
|
||||||
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-swift/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-toml/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-toml/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-typescript/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-typescript/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-typst/queries/typst/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-typst/queries/typst/highlights.scm"),
|
||||||
|
@ -70,9 +77,11 @@ pub fn build(b: *std.Build) void {
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-ziggy/tree-sitter-ziggy/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-ziggy/tree-sitter-ziggy/queries/highlights.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-ziggy/tree-sitter-ziggy-schema/queries/highlights.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-ziggy/tree-sitter-ziggy-schema/queries/highlights.scm"),
|
||||||
|
|
||||||
|
ts_queryfile(b, tree_sitter_dep, "queries/cmake/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-cpp/queries/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-cpp/queries/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-elixir/queries/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-elixir/queries/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-gitcommit/queries/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-gitcommit/queries/injections.scm"),
|
||||||
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-hare/queries/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-html/queries/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-html/queries/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-javascript/queries/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-javascript/queries/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-kdl/queries/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-kdl/queries/injections.scm"),
|
||||||
|
@ -82,12 +91,14 @@ pub fn build(b: *std.Build) void {
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-nasm/queries/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-nasm/queries/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-nix/queries/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-nix/queries/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-nu/queries/nu/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-nu/queries/nu/injections.scm"),
|
||||||
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-odin/queries/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-openscad/queries/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-openscad/queries/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-php/queries/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-php/queries/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-purescript/queries/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-purescript/queries/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-purescript/vim_queries/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-purescript/vim_queries/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-rust/queries/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-rust/queries/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-superhtml/tree-sitter-superhtml/queries/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-superhtml/tree-sitter-superhtml/queries/injections.scm"),
|
||||||
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-swift/queries/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-typst/queries/typst/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-typst/queries/typst/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-vim/queries/vim/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-vim/queries/vim/injections.scm"),
|
||||||
ts_queryfile(b, tree_sitter_dep, "tree-sitter-zig/queries/injections.scm"),
|
ts_queryfile(b, tree_sitter_dep, "tree-sitter-zig/queries/injections.scm"),
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
.@"tree-sitter" = .{
|
.@"tree-sitter" = .{
|
||||||
.url = "https://github.com/neurocyte/tree-sitter/releases/download/master-876cc5a125cb822d44a9f94f6bde64fac66272ce/source.tar.gz",
|
.url = "https://github.com/neurocyte/tree-sitter/releases/download/master-aea6072c6178d5cd0c97fff33e130f632f355bc2/source.tar.gz",
|
||||||
.hash = "12208efbfead8c57adeabbd2293d6ed19e00f769e1d8aba0d544270479587c9f694a",
|
.hash = "12204c99c6093230023380068f386f7eb32ab83df9a8eb8b586ffe5aa44afa34ff0e",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
|
|
|
@ -11,6 +11,7 @@ pub const FileType = @This();
|
||||||
color: u24,
|
color: u24,
|
||||||
icon: []const u8,
|
icon: []const u8,
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
|
description: []const u8,
|
||||||
lang_fn: LangFn,
|
lang_fn: LangFn,
|
||||||
extensions: []const []const u8,
|
extensions: []const []const u8,
|
||||||
highlights: [:0]const u8,
|
highlights: [:0]const u8,
|
||||||
|
@ -119,6 +120,7 @@ fn load_file_types(comptime Namespace: type) []const FileType {
|
||||||
.color = if (@hasField(@TypeOf(args), "color")) args.color else 0xffffff,
|
.color = if (@hasField(@TypeOf(args), "color")) args.color else 0xffffff,
|
||||||
.icon = if (@hasField(@TypeOf(args), "icon")) args.icon else "",
|
.icon = if (@hasField(@TypeOf(args), "icon")) args.icon else "",
|
||||||
.name = lang,
|
.name = lang,
|
||||||
|
.description = args.description,
|
||||||
.lang_fn = if (@hasField(@TypeOf(args), "parser")) args.parser else get_parser(lang),
|
.lang_fn = if (@hasField(@TypeOf(args), "parser")) args.parser else get_parser(lang),
|
||||||
.extensions = vec(args.extensions),
|
.extensions = vec(args.extensions),
|
||||||
.comment = args.comment,
|
.comment = args.comment,
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
pub const agda = .{
|
pub const agda = .{
|
||||||
|
.description = "Agda",
|
||||||
.extensions = .{"agda"},
|
.extensions = .{"agda"},
|
||||||
.comment = "--",
|
.comment = "--",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const bash = .{
|
pub const bash = .{
|
||||||
|
.description = "Bash",
|
||||||
.color = 0x3e474a,
|
.color = 0x3e474a,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "sh", "bash", ".profile" },
|
.extensions = .{ "sh", "bash", ".profile" },
|
||||||
|
@ -14,14 +16,16 @@ pub const bash = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const c = .{
|
pub const c = .{
|
||||||
|
.description = "C",
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "c", "h" },
|
.extensions = .{"c"},
|
||||||
.comment = "//",
|
.comment = "//",
|
||||||
.formatter = .{"clang-format"},
|
.formatter = .{"clang-format"},
|
||||||
.language_server = .{"clangd"},
|
.language_server = .{"clangd"},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const @"c-sharp" = .{
|
pub const @"c-sharp" = .{
|
||||||
|
.description = "C#",
|
||||||
.color = 0x68217a,
|
.color = 0x68217a,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"cs"},
|
.extensions = .{"cs"},
|
||||||
|
@ -30,6 +34,7 @@ pub const @"c-sharp" = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const conf = .{
|
pub const conf = .{
|
||||||
|
.description = "Config",
|
||||||
.color = 0x000000,
|
.color = 0x000000,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "conf", "config", ".gitconfig" },
|
.extensions = .{ "conf", "config", ".gitconfig" },
|
||||||
|
@ -38,7 +43,20 @@ pub const conf = .{
|
||||||
.parser = fish.parser,
|
.parser = fish.parser,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const cmake = .{
|
||||||
|
.description = "CMake",
|
||||||
|
.color = 0x004078,
|
||||||
|
.icon = "",
|
||||||
|
.extensions = .{ "CMakeLists.txt", "cmake", "cmake.in" },
|
||||||
|
.comment = "#",
|
||||||
|
.highlights = "queries/cmake/highlights.scm",
|
||||||
|
.injections = "queries/cmake/injections.scm",
|
||||||
|
.formatter = .{"cmake-format"},
|
||||||
|
.language_server = .{"cmake-language-server"},
|
||||||
|
};
|
||||||
|
|
||||||
pub const cpp = .{
|
pub const cpp = .{
|
||||||
|
.description = "C++",
|
||||||
.color = 0x9c033a,
|
.color = 0x9c033a,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "cc", "cpp", "cxx", "hpp", "hxx", "h", "ipp", "ixx" },
|
.extensions = .{ "cc", "cpp", "cxx", "hpp", "hxx", "h", "ipp", "ixx" },
|
||||||
|
@ -53,6 +71,7 @@ pub const cpp = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const css = .{
|
pub const css = .{
|
||||||
|
.description = "CSS",
|
||||||
.color = 0x3d8fc6,
|
.color = 0x3d8fc6,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"css"},
|
.extensions = .{"css"},
|
||||||
|
@ -60,11 +79,13 @@ pub const css = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const diff = .{
|
pub const diff = .{
|
||||||
|
.description = "Diff",
|
||||||
.extensions = .{ "diff", "patch" },
|
.extensions = .{ "diff", "patch" },
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const dockerfile = .{
|
pub const dockerfile = .{
|
||||||
|
.description = "Docker",
|
||||||
.color = 0x019bc6,
|
.color = 0x019bc6,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "Dockerfile", "dockerfile", "docker", "Containerfile", "container" },
|
.extensions = .{ "Dockerfile", "dockerfile", "docker", "Containerfile", "container" },
|
||||||
|
@ -72,6 +93,7 @@ pub const dockerfile = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const dtd = .{
|
pub const dtd = .{
|
||||||
|
.description = "DTD",
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"dtd"},
|
.extensions = .{"dtd"},
|
||||||
.comment = "<!--",
|
.comment = "<!--",
|
||||||
|
@ -79,6 +101,7 @@ pub const dtd = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const elixir = .{
|
pub const elixir = .{
|
||||||
|
.description = "Elixir",
|
||||||
.color = 0x4e2a8e,
|
.color = 0x4e2a8e,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "ex", "exs" },
|
.extensions = .{ "ex", "exs" },
|
||||||
|
@ -89,6 +112,7 @@ pub const elixir = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const fish = .{
|
pub const fish = .{
|
||||||
|
.description = "Fish",
|
||||||
.extensions = .{"fish"},
|
.extensions = .{"fish"},
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
.parser = @import("file_type.zig").Parser("fish"),
|
.parser = @import("file_type.zig").Parser("fish"),
|
||||||
|
@ -96,6 +120,7 @@ pub const fish = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const @"git-rebase" = .{
|
pub const @"git-rebase" = .{
|
||||||
|
.description = "Git (rebase)",
|
||||||
.color = 0xf34f29,
|
.color = 0xf34f29,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"git-rebase-todo"},
|
.extensions = .{"git-rebase-todo"},
|
||||||
|
@ -103,6 +128,7 @@ pub const @"git-rebase" = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const gitcommit = .{
|
pub const gitcommit = .{
|
||||||
|
.description = "Git (commit)",
|
||||||
.color = 0xf34f29,
|
.color = 0xf34f29,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"COMMIT_EDITMSG"},
|
.extensions = .{"COMMIT_EDITMSG"},
|
||||||
|
@ -110,15 +136,34 @@ pub const gitcommit = .{
|
||||||
.injections = "tree-sitter-gitcommit/queries/injections.scm",
|
.injections = "tree-sitter-gitcommit/queries/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const gleam = .{
|
||||||
|
.description = "Gleam",
|
||||||
|
.color = 0xffaff3,
|
||||||
|
.icon = "",
|
||||||
|
.extensions = .{"gleam"},
|
||||||
|
.comment = "//",
|
||||||
|
.language_server = .{ "gleam", "lsp" },
|
||||||
|
.formatter = .{ "gleam", "format", "--stdin" },
|
||||||
|
};
|
||||||
|
|
||||||
pub const go = .{
|
pub const go = .{
|
||||||
|
.description = "Go",
|
||||||
.color = 0x00acd7,
|
.color = 0x00acd7,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"go"},
|
.extensions = .{"go"},
|
||||||
.comment = "//",
|
.comment = "//",
|
||||||
.language_server = .{"gopls"},
|
.language_server = .{"gopls"},
|
||||||
|
.formatter = .{"gofmt"},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const hare = .{
|
||||||
|
.description = "Hare",
|
||||||
|
.extensions = .{"ha"},
|
||||||
|
.comment = "//",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const haskell = .{
|
pub const haskell = .{
|
||||||
|
.description = "Haskell",
|
||||||
.color = 0x5E5185,
|
.color = 0x5E5185,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"hs"},
|
.extensions = .{"hs"},
|
||||||
|
@ -127,6 +172,7 @@ pub const haskell = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const html = .{
|
pub const html = .{
|
||||||
|
.description = "HTML",
|
||||||
.color = 0xe54d26,
|
.color = 0xe54d26,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"html"},
|
.extensions = .{"html"},
|
||||||
|
@ -137,6 +183,7 @@ pub const html = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const superhtml = .{
|
pub const superhtml = .{
|
||||||
|
.description = "SuperHTML",
|
||||||
.color = 0xe54d26,
|
.color = 0xe54d26,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"shtml"},
|
.extensions = .{"shtml"},
|
||||||
|
@ -148,6 +195,7 @@ pub const superhtml = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const java = .{
|
pub const java = .{
|
||||||
|
.description = "Java",
|
||||||
.color = 0xEA2D2E,
|
.color = 0xEA2D2E,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"java"},
|
.extensions = .{"java"},
|
||||||
|
@ -155,6 +203,7 @@ pub const java = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const javascript = .{
|
pub const javascript = .{
|
||||||
|
.description = "JavaScript",
|
||||||
.color = 0xf0db4f,
|
.color = 0xf0db4f,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"js"},
|
.extensions = .{"js"},
|
||||||
|
@ -164,13 +213,24 @@ pub const javascript = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const json = .{
|
pub const json = .{
|
||||||
|
.description = "JSON",
|
||||||
.extensions = .{"json"},
|
.extensions = .{"json"},
|
||||||
.comment = "//",
|
.comment = "//",
|
||||||
.language_server = .{ "deno", "lsp" },
|
.language_server = .{ "deno", "lsp" },
|
||||||
.formatter = .{ "hjson", "-j" },
|
.formatter = .{ "hjson", "-j" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const julia = .{
|
||||||
|
.description = "Julia",
|
||||||
|
.color = 0x4D64AE,
|
||||||
|
.icon = "",
|
||||||
|
.extensions = .{"jl"},
|
||||||
|
.comment = "#",
|
||||||
|
.language_server = .{ "julia", "-e", "using LanguageServer; runserver()" },
|
||||||
|
};
|
||||||
|
|
||||||
pub const kdl = .{
|
pub const kdl = .{
|
||||||
|
.description = "KDL",
|
||||||
.color = 0x000000,
|
.color = 0x000000,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"kdl"},
|
.extensions = .{"kdl"},
|
||||||
|
@ -178,6 +238,7 @@ pub const kdl = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const lua = .{
|
pub const lua = .{
|
||||||
|
.description = "Lua",
|
||||||
.color = 0x02027d,
|
.color = 0x02027d,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"lua"},
|
.extensions = .{"lua"},
|
||||||
|
@ -187,12 +248,23 @@ pub const lua = .{
|
||||||
.language_server = .{"lua-lsp"},
|
.language_server = .{"lua-lsp"},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const mail = .{
|
||||||
|
.description = "E-Mail",
|
||||||
|
.icon = "",
|
||||||
|
.extensions = .{ "eml", "mbox" },
|
||||||
|
.comment = ">",
|
||||||
|
.highlights = "tree-sitter-mail/queries/mail/highlights.scm",
|
||||||
|
.first_line_matches = .{ .prefix = "From" },
|
||||||
|
};
|
||||||
|
|
||||||
pub const make = .{
|
pub const make = .{
|
||||||
|
.description = "Make",
|
||||||
.extensions = .{ "makefile", "Makefile", "MAKEFILE", "GNUmakefile", "mk", "mak", "dsp" },
|
.extensions = .{ "makefile", "Makefile", "MAKEFILE", "GNUmakefile", "mk", "mak", "dsp" },
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const markdown = .{
|
pub const markdown = .{
|
||||||
|
.description = "Markdown",
|
||||||
.color = 0x000000,
|
.color = 0x000000,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"md"},
|
.extensions = .{"md"},
|
||||||
|
@ -203,6 +275,7 @@ pub const markdown = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const @"markdown-inline" = .{
|
pub const @"markdown-inline" = .{
|
||||||
|
.description = "Markdown (inline)",
|
||||||
.color = 0x000000,
|
.color = 0x000000,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{},
|
.extensions = .{},
|
||||||
|
@ -212,12 +285,14 @@ pub const @"markdown-inline" = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const nasm = .{
|
pub const nasm = .{
|
||||||
|
.description = "Assembly Language (nasm)",
|
||||||
.extensions = .{ "asm", "nasm" },
|
.extensions = .{ "asm", "nasm" },
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
.injections = "tree-sitter-nasm/queries/injections.scm",
|
.injections = "tree-sitter-nasm/queries/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const nim = .{
|
pub const nim = .{
|
||||||
|
.description = "Nim",
|
||||||
.color = 0xffe953,
|
.color = 0xffe953,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"nim"},
|
.extensions = .{"nim"},
|
||||||
|
@ -226,6 +301,7 @@ pub const nim = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const nimble = .{
|
pub const nimble = .{
|
||||||
|
.description = "Nimble (nim)",
|
||||||
.color = 0xffe953,
|
.color = 0xffe953,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"nimble"},
|
.extensions = .{"nimble"},
|
||||||
|
@ -235,11 +311,13 @@ pub const nimble = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ninja = .{
|
pub const ninja = .{
|
||||||
|
.description = "Ninja",
|
||||||
.extensions = .{"ninja"},
|
.extensions = .{"ninja"},
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const nix = .{
|
pub const nix = .{
|
||||||
|
.description = "Nix",
|
||||||
.color = 0x5277C3,
|
.color = 0x5277C3,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"nix"},
|
.extensions = .{"nix"},
|
||||||
|
@ -248,16 +326,18 @@ pub const nix = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const nu = .{
|
pub const nu = .{
|
||||||
|
.description = "Nushell",
|
||||||
.color = 0x3AA675,
|
.color = 0x3AA675,
|
||||||
.icon = ">",
|
.icon = ">",
|
||||||
.extensions = .{ "nu", "nushell" },
|
.extensions = .{ "nu", "nushell" },
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
.language_server = .{"nu", "--lsp"},
|
.language_server = .{ "nu", "--lsp" },
|
||||||
.highlights = "tree-sitter-nu/queries/nu/highlights.scm",
|
.highlights = "tree-sitter-nu/queries/nu/highlights.scm",
|
||||||
.injections = "tree-sitter-nu/queries/nu/injections.scm",
|
.injections = "tree-sitter-nu/queries/nu/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ocaml = .{
|
pub const ocaml = .{
|
||||||
|
.description = "OCaml",
|
||||||
.color = 0xF18803,
|
.color = 0xF18803,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "ml", "mli" },
|
.extensions = .{ "ml", "mli" },
|
||||||
|
@ -266,7 +346,18 @@ pub const ocaml = .{
|
||||||
.language_server = .{ "ocamllsp", "--fallback-read-dot-merlin" },
|
.language_server = .{ "ocamllsp", "--fallback-read-dot-merlin" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const odin = .{
|
||||||
|
.description = "Odin",
|
||||||
|
.extensions = .{"odin"},
|
||||||
|
.comment = "//",
|
||||||
|
.parser = @import("file_type.zig").Parser("odin"),
|
||||||
|
.injections = "tree-sitter-odin/queries/injections.scm",
|
||||||
|
.language_server = .{"ols"},
|
||||||
|
.formatter = .{ "odinfmt", "-stdin" },
|
||||||
|
};
|
||||||
|
|
||||||
pub const openscad = .{
|
pub const openscad = .{
|
||||||
|
.description = "OpenSCAD",
|
||||||
.color = 0x000000,
|
.color = 0x000000,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"scad"},
|
.extensions = .{"scad"},
|
||||||
|
@ -276,12 +367,14 @@ pub const openscad = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const org = .{
|
pub const org = .{
|
||||||
|
.description = "Org Mode",
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"org"},
|
.extensions = .{"org"},
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const php = .{
|
pub const php = .{
|
||||||
|
.description = "PHP",
|
||||||
.color = 0x6181b6,
|
.color = 0x6181b6,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"php"},
|
.extensions = .{"php"},
|
||||||
|
@ -290,6 +383,7 @@ pub const php = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const purescript = .{
|
pub const purescript = .{
|
||||||
|
.description = "PureScript",
|
||||||
.color = 0x14161a,
|
.color = 0x14161a,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"purs"},
|
.extensions = .{"purs"},
|
||||||
|
@ -298,27 +392,32 @@ pub const purescript = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const python = .{
|
pub const python = .{
|
||||||
|
.description = "Python",
|
||||||
.color = 0xffd845,
|
.color = 0xffd845,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"py"},
|
.extensions = .{ "py", "pyi" },
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
.first_line_matches = .{ .prefix = "#!", .content = "/bin/bash" },
|
.first_line_matches = .{ .prefix = "#!", .content = "python" },
|
||||||
.language_server = .{"pylsp"},
|
.language_server = .{"pylsp"},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const regex = .{
|
pub const regex = .{
|
||||||
|
.description = "Regular expression",
|
||||||
.extensions = .{},
|
.extensions = .{},
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ruby = .{
|
pub const ruby = .{
|
||||||
|
.description = "Ruby",
|
||||||
.color = 0xd91404,
|
.color = 0xd91404,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"rb"},
|
.extensions = .{"rb"},
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
|
.language_server = .{"ruby-lsp"},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const rust = .{
|
pub const rust = .{
|
||||||
|
.description = "Rust",
|
||||||
.color = 0x000000,
|
.color = 0x000000,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"rs"},
|
.extensions = .{"rs"},
|
||||||
|
@ -328,16 +427,29 @@ pub const rust = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const scheme = .{
|
pub const scheme = .{
|
||||||
|
.description = "Scheme",
|
||||||
.extensions = .{ "scm", "ss", "el" },
|
.extensions = .{ "scm", "ss", "el" },
|
||||||
.comment = ";",
|
.comment = ";",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const @"ssh-config" = .{
|
pub const @"ssh-config" = .{
|
||||||
|
.description = "SSH config",
|
||||||
.extensions = .{".ssh/config"},
|
.extensions = .{".ssh/config"},
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const swift = .{
|
||||||
|
.description = "Swift",
|
||||||
|
.color = 0xf05138,
|
||||||
|
.icon = "",
|
||||||
|
.extensions = .{ "swift", "swiftinterface" },
|
||||||
|
.comment = "//",
|
||||||
|
.language_server = .{"sourcekit-lsp"},
|
||||||
|
.formatter = .{"swift-format"},
|
||||||
|
};
|
||||||
|
|
||||||
pub const toml = .{
|
pub const toml = .{
|
||||||
|
.description = "TOML",
|
||||||
.extensions = .{ "toml", "ini" },
|
.extensions = .{ "toml", "ini" },
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
.highlights = "tree-sitter-toml/queries/highlights.scm",
|
.highlights = "tree-sitter-toml/queries/highlights.scm",
|
||||||
|
@ -345,6 +457,7 @@ pub const toml = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const typescript = .{
|
pub const typescript = .{
|
||||||
|
.description = "TypeScript",
|
||||||
.color = 0x007acc,
|
.color = 0x007acc,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "ts", "tsx" },
|
.extensions = .{ "ts", "tsx" },
|
||||||
|
@ -353,6 +466,7 @@ pub const typescript = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const typst = .{
|
pub const typst = .{
|
||||||
|
.description = "Typst",
|
||||||
.color = 0x23b6bc,
|
.color = 0x23b6bc,
|
||||||
.icon = "t",
|
.icon = "t",
|
||||||
.extensions = .{ "typst", "typ" },
|
.extensions = .{ "typst", "typ" },
|
||||||
|
@ -363,6 +477,7 @@ pub const typst = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const vim = .{
|
pub const vim = .{
|
||||||
|
.description = "Vimscript",
|
||||||
.color = 0x007f00,
|
.color = 0x007f00,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"vim"},
|
.extensions = .{"vim"},
|
||||||
|
@ -372,14 +487,17 @@ pub const vim = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const xml = .{
|
pub const xml = .{
|
||||||
|
.description = "XML",
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"xml"},
|
.extensions = .{"xml"},
|
||||||
.comment = "<!--",
|
.comment = "<!--",
|
||||||
.highlights = "tree-sitter-xml/queries/xml/highlights.scm",
|
.highlights = "tree-sitter-xml/queries/xml/highlights.scm",
|
||||||
.first_line_matches = .{ .prefix = "<?xml " },
|
.first_line_matches = .{ .prefix = "<?xml " },
|
||||||
|
.formatter = .{ "xmllint", "--format", "-" },
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const yaml = .{
|
pub const yaml = .{
|
||||||
|
.description = "YAML",
|
||||||
.color = 0x000000,
|
.color = 0x000000,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "yaml", "yml" },
|
.extensions = .{ "yaml", "yml" },
|
||||||
|
@ -387,6 +505,7 @@ pub const yaml = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const zig = .{
|
pub const zig = .{
|
||||||
|
.description = "Zig",
|
||||||
.color = 0xf7a41d,
|
.color = 0xf7a41d,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "zig", "zon" },
|
.extensions = .{ "zig", "zon" },
|
||||||
|
@ -397,6 +516,7 @@ pub const zig = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ziggy = .{
|
pub const ziggy = .{
|
||||||
|
.description = "Ziggy",
|
||||||
.color = 0xf7a41d,
|
.color = 0xf7a41d,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "ziggy", "zgy" },
|
.extensions = .{ "ziggy", "zgy" },
|
||||||
|
@ -405,6 +525,7 @@ pub const ziggy = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const @"ziggy-schema" = .{
|
pub const @"ziggy-schema" = .{
|
||||||
|
.description = "Ziggy (schema)",
|
||||||
.color = 0xf7a41d,
|
.color = 0xf7a41d,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "ziggy-schema", "zyg-schema" },
|
.extensions = .{ "ziggy-schema", "zyg-schema" },
|
||||||
|
|
|
@ -26,7 +26,7 @@ query: *Query,
|
||||||
injections: *Query,
|
injections: *Query,
|
||||||
tree: ?*treez.Tree = null,
|
tree: ?*treez.Tree = null,
|
||||||
|
|
||||||
pub fn create(file_type: *const FileType, allocator: std.mem.Allocator, content: []const u8) !*Self {
|
pub fn create(file_type: *const FileType, allocator: std.mem.Allocator) !*Self {
|
||||||
const self = try allocator.create(Self);
|
const self = try allocator.create(Self);
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
|
@ -38,18 +38,17 @@ pub fn create(file_type: *const FileType, allocator: std.mem.Allocator, content:
|
||||||
};
|
};
|
||||||
errdefer self.destroy();
|
errdefer self.destroy();
|
||||||
try self.parser.setLanguage(self.lang);
|
try self.parser.setLanguage(self.lang);
|
||||||
try self.refresh_full(content);
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_file_type(allocator: std.mem.Allocator, content: []const u8, lang_name: []const u8) !*Self {
|
pub fn create_file_type(allocator: std.mem.Allocator, lang_name: []const u8) !*Self {
|
||||||
const file_type = FileType.get_by_name(lang_name) orelse return error.NotFound;
|
const file_type = FileType.get_by_name(lang_name) orelse return error.NotFound;
|
||||||
return create(file_type, allocator, content);
|
return create(file_type, allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_guess_file_type(allocator: std.mem.Allocator, content: []const u8, file_path: ?[]const u8) !*Self {
|
pub fn create_guess_file_type(allocator: std.mem.Allocator, content: []const u8, file_path: ?[]const u8) !*Self {
|
||||||
const file_type = FileType.guess(file_path, content) orelse return error.NotFound;
|
const file_type = FileType.guess(file_path, content) orelse return error.NotFound;
|
||||||
return create(file_type, allocator, content);
|
return create(file_type, allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy(self: *Self) void {
|
pub fn destroy(self: *Self) void {
|
||||||
|
@ -59,8 +58,15 @@ pub fn destroy(self: *Self) void {
|
||||||
self.allocator.destroy(self);
|
self.allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn reset(self: *Self) void {
|
||||||
|
if (self.tree) |tree| {
|
||||||
|
tree.destroy();
|
||||||
|
self.tree = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn refresh_full(self: *Self, content: []const u8) !void {
|
pub fn refresh_full(self: *Self, content: []const u8) !void {
|
||||||
if (self.tree) |tree| tree.destroy();
|
self.reset();
|
||||||
self.tree = try self.parser.parseString(null, content);
|
self.tree = try self.parser.parseString(null, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,12 +74,6 @@ pub fn edit(self: *Self, ed: Edit) void {
|
||||||
if (self.tree) |tree| tree.edit(&ed);
|
if (self.tree) |tree| tree.edit(&ed);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn refresh(self: *Self, content: []const u8) !void {
|
|
||||||
const old_tree = self.tree;
|
|
||||||
defer if (old_tree) |tree| tree.destroy();
|
|
||||||
self.tree = try self.parser.parseString(old_tree, content);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn refresh_from_buffer(self: *Self, buffer: anytype, metrics: anytype) !void {
|
pub fn refresh_from_buffer(self: *Self, buffer: anytype, metrics: anytype) !void {
|
||||||
const old_tree = self.tree;
|
const old_tree = self.tree;
|
||||||
defer if (old_tree) |tree| tree.destroy();
|
defer if (old_tree) |tree| tree.destroy();
|
||||||
|
@ -105,6 +105,47 @@ pub fn refresh_from_buffer(self: *Self, buffer: anytype, metrics: anytype) !void
|
||||||
self.tree = try self.parser.parse(old_tree, input);
|
self.tree = try self.parser.parse(old_tree, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn refresh_from_string(self: *Self, content: [:0]const u8) !void {
|
||||||
|
const old_tree = self.tree;
|
||||||
|
defer if (old_tree) |tree| tree.destroy();
|
||||||
|
|
||||||
|
const State = struct {
|
||||||
|
content: @TypeOf(content),
|
||||||
|
};
|
||||||
|
var state: State = .{
|
||||||
|
.content = content,
|
||||||
|
};
|
||||||
|
|
||||||
|
const input: Input = .{
|
||||||
|
.payload = &state,
|
||||||
|
.read = struct {
|
||||||
|
fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.C) [*:0]const u8 {
|
||||||
|
bytes_read.* = 0;
|
||||||
|
const ctx: *State = @ptrCast(@alignCast(payload orelse return ""));
|
||||||
|
const pos = (find_line_begin(ctx.content, position.row) orelse return "") + position.column;
|
||||||
|
if (pos >= ctx.content.len) return "";
|
||||||
|
bytes_read.* = @intCast(ctx.content.len - pos);
|
||||||
|
return ctx.content[pos..].ptr;
|
||||||
|
}
|
||||||
|
}.read,
|
||||||
|
.encoding = .utf_8,
|
||||||
|
};
|
||||||
|
self.tree = try self.parser.parse(old_tree, input);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_line_begin(s: []const u8, line: usize) ?usize {
|
||||||
|
var idx: usize = 0;
|
||||||
|
var at_line: usize = 0;
|
||||||
|
while (idx < s.len) {
|
||||||
|
if (at_line == line)
|
||||||
|
return idx;
|
||||||
|
if (s[idx] == '\n')
|
||||||
|
at_line += 1;
|
||||||
|
idx += 1;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
fn CallBack(comptime T: type) type {
|
fn CallBack(comptime T: type) type {
|
||||||
return fn (ctx: T, sel: Range, scope: []const u8, id: u32, capture_idx: usize, node: *const Node) error{Stop}!void;
|
return fn (ctx: T, sel: Range, scope: []const u8, id: u32, capture_idx: usize, node: *const Node) error{Stop}!void;
|
||||||
}
|
}
|
||||||
|
@ -143,3 +184,9 @@ pub fn highlights_at_point(self: *const Self, ctx: anytype, comptime cb: CallBac
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn node_at_point_range(self: *const Self, range: Range) error{Stop}!treez.Node {
|
||||||
|
const tree = self.tree orelse return error.Stop;
|
||||||
|
const root_node = tree.getRootNode();
|
||||||
|
return treez.Node.externs.ts_node_descendant_for_point_range(root_node, range.start_point, range.end_point);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue