From 44ebe9115116583f37c1fc69fb13bb0bc29f62d4 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Mon, 7 Oct 2024 22:26:49 +0200 Subject: [PATCH] Revert tree-sitter --- packages/common/kak-tree-sitter/default.nix | 1 - .../common/kak-tree-sitter/user_config.patch | 129 -------------- packages/common/nki-kakoune/default.nix | 5 +- .../nki-kakoune/tree-sitter/default.nix | 167 ------------------ .../nki-kakoune/tree-sitter/grammars.nix | 120 ------------- 5 files changed, 1 insertion(+), 421 deletions(-) delete mode 100644 packages/common/kak-tree-sitter/user_config.patch delete mode 100644 packages/common/nki-kakoune/tree-sitter/default.nix delete mode 100644 packages/common/nki-kakoune/tree-sitter/grammars.nix diff --git a/packages/common/kak-tree-sitter/default.nix b/packages/common/kak-tree-sitter/default.nix index 69da116..9819e3a 100644 --- a/packages/common/kak-tree-sitter/default.nix +++ b/packages/common/kak-tree-sitter/default.nix @@ -34,7 +34,6 @@ let self.runtime_dir.join("sources").join(url_dir) '') - ./user_config.patch ]; meta.mainProgram = "kak-tree-sitter"; diff --git a/packages/common/kak-tree-sitter/user_config.patch b/packages/common/kak-tree-sitter/user_config.patch deleted file mode 100644 index b2b1b6a..0000000 --- a/packages/common/kak-tree-sitter/user_config.patch +++ /dev/null @@ -1,129 +0,0 @@ -diff --git a/kak-tree-sitter-config/src/lib.rs b/kak-tree-sitter-config/src/lib.rs -index e4edc42..a9c92cb 100644 ---- a/kak-tree-sitter-config/src/lib.rs -+++ b/kak-tree-sitter-config/src/lib.rs -@@ -52,9 +52,13 @@ impl Config { - } - - /// Load the default configuration, the user configuration, and merge both. -- pub fn load_default_user() -> Result { -+ pub fn load_default_user(path: Option>) -> Result { - let mut config = Self::load_default_config()?; -- match UserConfig::load_from_xdg() { -+ let user_config = match path { -+ Some(p) => UserConfig::load(p), -+ None => UserConfig::load_from_xdg(), -+ }; -+ match user_config { - Ok(user_config) => { - config.merge_user_config(user_config)?; - } -@@ -448,7 +452,7 @@ impl UserConfig { - } - - /// Load the configuration from a given path. -- fn load(path: impl AsRef) -> Result { -+ pub fn load(path: impl AsRef) -> Result { - let path = path.as_ref(); - - log::debug!("loading configuration at {path}", path = path.display()); -diff --git a/kak-tree-sitter/src/cli.rs b/kak-tree-sitter/src/cli.rs -index b8102cd..923312c 100644 ---- a/kak-tree-sitter/src/cli.rs -+++ b/kak-tree-sitter/src/cli.rs -@@ -22,6 +22,10 @@ pub struct Cli { - #[clap(short, long)] - pub server: bool, - -+ /// Specify a custom path for the user config. -+ #[clap(short, long)] -+ pub user_config: Option, -+ - /// Try to daemonize, if not already done. - #[clap(short, long)] - pub daemonize: bool, -diff --git a/kak-tree-sitter/src/main.rs b/kak-tree-sitter/src/main.rs -index bee9698..cbd7b39 100644 ---- a/kak-tree-sitter/src/main.rs -+++ b/kak-tree-sitter/src/main.rs -@@ -43,7 +43,7 @@ fn start() -> Result<(), OhNo> { - } - } - -- let config = Config::load_default_user()?; -+ let config = Config::load_default_user(cli.user_config.as_ref())?; - - // inject rc if we start from Kakoune - if cli.kakoune && cli.init.is_some() { -diff --git a/kak-tree-sitter/src/server.rs b/kak-tree-sitter/src/server.rs -index f3b7723..000c81d 100644 ---- a/kak-tree-sitter/src/server.rs -+++ b/kak-tree-sitter/src/server.rs -@@ -73,6 +73,7 @@ impl Server { - log::debug!("creating IO handler"); - let io_handler = IOHandler::new( - config, -+ cli.user_config.clone(), - cli.is_standalone(), - cli.with_highlighting || config.features.highlighting, - resources, -@@ -165,6 +166,7 @@ struct IOHandler { - connections: HashMap, - enqueue_response: EnqueueResponse, - handler: Handler, -+ user_config_path: Option, - } - - impl IOHandler { -@@ -173,6 +175,7 @@ impl IOHandler { - - fn new( - config: &Config, -+ user_config_path: Option, - is_standalone: bool, - with_highlighting: bool, - resources: ServerResources, -@@ -203,6 +206,7 @@ impl IOHandler { - connections, - enqueue_response, - handler, -+ user_config_path, - }) - } - -@@ -450,7 +454,7 @@ impl IOHandler { - } - - fn reload(&mut self) { -- let config = match Config::load_default_user() { -+ let config = match Config::load_default_user(self.user_config_path.as_ref()) { - Ok(config) => config, - Err(err) => { - log::error!("reloading config failed: {err}"); -diff --git a/ktsctl/src/cli.rs b/ktsctl/src/cli.rs -index dfac5c3..09f86f3 100644 ---- a/ktsctl/src/cli.rs -+++ b/ktsctl/src/cli.rs -@@ -11,6 +11,9 @@ pub struct Cli { - #[clap(long)] - pub verbose: bool, - -+ #[clap(short, long)] -+ pub user_config: Option, -+ - #[clap(subcommand)] - pub cmd: Cmd, - } -diff --git a/ktsctl/src/main.rs b/ktsctl/src/main.rs -index f9a3499..f823633 100644 ---- a/ktsctl/src/main.rs -+++ b/ktsctl/src/main.rs -@@ -37,7 +37,7 @@ fn start() -> Result<(), HellNo> { - simple_logger::init_with_level(log::Level::Debug)?; - } - -- let config = Config::load_default_user()?; -+ let config = Config::load_default_user(cli.user_config.as_ref())?; - log::debug!("ktsctl configuration:\n{config:#?}"); - - match cli.cmd { diff --git a/packages/common/nki-kakoune/default.nix b/packages/common/nki-kakoune/default.nix index c7d4324..f4851af 100644 --- a/packages/common/nki-kakoune/default.nix +++ b/packages/common/nki-kakoune/default.nix @@ -1,9 +1,7 @@ { callPackage, kakoune, kakoune-unwrapped, ... }: let lsp = callPackage ./lsp.nix { }; - rc = (callPackage ./rc.nix { - # prependRc = tree-sitter.rc; - }); + rc = (callPackage ./rc.nix { }); in (kakoune.override { plugins = callPackage ./plugins.nix { } @@ -12,7 +10,6 @@ in (callPackage ./kaktex { }) (callPackage ./faces.nix { }) rc - # tree-sitter.plugin lsp.plugin ]; }).overrideAttrs (attrs: { diff --git a/packages/common/nki-kakoune/tree-sitter/default.nix b/packages/common/nki-kakoune/tree-sitter/default.nix deleted file mode 100644 index b94a771..0000000 --- a/packages/common/nki-kakoune/tree-sitter/default.nix +++ /dev/null @@ -1,167 +0,0 @@ -{ lib -, callPackage -, formats -, runCommandLocal -, kak-tree-sitter -, ... -}: -let - utils = callPackage ../utils.nix { }; - grammars = (callPackage ./grammars.nix { }).grammars; - # Highlighter groups to add to the `highlighterGroups`. Maps from group names to face names. - highlighterGroups = { - attribute = "@attribute"; - comment = "@comment"; - conceal = "%opt{mauve}+i"; - constant = "%opt{peach}"; - constant_builtin_boolean = "%opt{sky}"; - constant_character = "%opt{yellow}"; - constant_macro = "%opt{mauve}"; - constant_numeric = "%opt{peach}"; - constructor = "%opt{sapphire}"; - diff_plus = "%opt{green}"; - diff_minus = "%opt{red}"; - diff_delta = "%opt{blue}"; - diff_delta_moved = "%opt{mauve}"; - error = "%opt{red}+b"; - function = "@function"; - function_builtin = "@builtin"; - function_macro = "+i@ts_function"; - hint = "%opt{blue}+b"; - info = "%opt{green}+b"; - keyword = "keyword"; - keyword_conditional = "+i@ts_keyword"; - keyword_control_conditional = "+i@ts_keyword"; - keyword_control_directive = "+i@ts_keyword"; - keyword_control_import = "+i@ts_keyword"; - keyword_directive = "+i@ts_keyword"; - label = "%opt{sapphire}+i"; - markup_bold = "%opt{peach}+b"; - markup_heading = "%opt{red}"; - markup_heading_1 = "%opt{red}"; - markup_heading_2 = "%opt{mauve}"; - markup_heading_3 = "%opt{green}"; - markup_heading_4 = "%opt{yellow}"; - markup_heading_5 = "%opt{pink}"; - markup_heading_6 = "%opt{teal}"; - markup_heading_marker = "%opt{peach}+b"; - markup_italic = "%opt{pink}+i"; - markup_list_checked = "%opt{green}"; - markup_list_numbered = "%opt{blue}+i"; - markup_list_unchecked = "%opt{teal}"; - markup_list_unnumbered = "%opt{mauve}"; - markup_link_label = "%opt{blue}"; - markup_link_url = "%opt{teal}+u"; - markup_link_uri = "%opt{teal}+u"; - markup_link_text = "%opt{blue}"; - markup_quote = "%opt{crust}"; - markup_raw = "%opt{sky}"; - markup_raw_block = "%opt{sky}"; - markup_raw_inline = "%opt{green}"; - markup_strikethrough = "%opt{crust}+s"; - namespace = "@module"; - operator = "@operator"; - property = "%opt{sky}"; - punctuation = "%opt{overlay2}"; - punctuation_special = "%opt{sky}"; - special = "%opt{blue}"; - spell = "%opt{mauve}"; - string = "%opt{green}"; - string_regex = "%opt{peach}"; - string_regexp = "%opt{peach}"; - string_escape = "%opt{mauve}"; - string_special = "%opt{blue}"; - string_special_path = "%opt{green}"; - string_special_symbol = "%opt{mauve}"; - string_symbol = "%opt{red}"; - tag = "%opt{teal}"; - tag_error = "%opt{red}"; - text_title = "%opt{mauve}"; - type = "@type"; - type_enum_variant = "+i@ts_type"; - variable = "@variable"; - variable_builtin = "@builtin"; - variable_other_member = "%opt{teal}"; - variable_parameter = "+i@variable"; - warning = "%opt{peach}+b"; - }; - - # Highlighter groups to be aliased by other groups - aliases = { - comment_block = "comment"; - comment_line = "comment"; - constant_character_escape = "constant_character"; - constant_numeric_float = "constant_numeric"; - constant_numeric_integer = "constant_numeric"; - function_method = "function"; - function_special = "function"; - keyword_control = "keyword"; - keyword_control_repeat = "keyword"; - keyword_control_return = "keyword"; - keyword_control_except = "keyword"; - keyword_control_exception = "keyword"; - keyword_function = "keyword"; - keyword_operator = "keyword"; - keyword_special = "keyword"; - keyword_storage = "keyword"; - keyword_storage_modifier = "keyword"; - keyword_storage_modifier_mut = "keyword"; - keyword_storage_modifier_ref = "keyword"; - keyword_storage_type = "keyword"; - punctuation_bracket = "punctuation"; - punctuation_delimiter = "punctuation"; - text = "string"; - type_builtin = "type"; - - # Scala stuff - method = "function"; - module = "namespace"; - function_call = "function"; - method_call = "method"; - - boolean = "constant_builtin_boolean"; - number = "constant_numeric"; - float = "constant_numeric_float"; - - type_qualifier = "keyword_special"; - storageclass = "keyword_storage_modifier"; - conditional = "keyword_conditional"; - include = "keyword_control_import"; - }; - - configFile = - let - toScm = name: lib.concatStringsSep "." (lib.splitString "_" name); - toml = formats.toml { }; - in - toml.generate "config.toml" { - highlight.groups = builtins.map toScm (builtins.attrNames highlighterGroups ++ builtins.attrNames aliases); - features = { - highlighting = true; - text_objects = true; - }; - language = grammars; - }; - - extraFaces = - let - toTs = name: "ts_${lib.concatStringsSep "_" (lib.splitString "." name)}"; - - definedFaces = lib.mapAttrs' (name: value: { inherit value; name = toTs name; }) highlighterGroups; - aliasFaces = lib.mapAttrs' (name: value: { name = toTs name; value = "@${toTs value}"; }) aliases; - faces = lib.recursiveUpdate definedFaces aliasFaces; - in - faces; -in -{ - rc = '' - # Enable kak-tree-sitter - eval %sh{kak-tree-sitter --kakoune -d --server --init $kak_session --user-config ${configFile}} - map global normal ": enter-user-mode tree-sitter" - ''; - - extraPaths = "${kak-tree-sitter}/bin"; - - plugin = utils.mkFacesScript "kak-tree-sitter" extraFaces; -} - diff --git a/packages/common/nki-kakoune/tree-sitter/grammars.nix b/packages/common/nki-kakoune/tree-sitter/grammars.nix deleted file mode 100644 index d1f6417..0000000 --- a/packages/common/nki-kakoune/tree-sitter/grammars.nix +++ /dev/null @@ -1,120 +0,0 @@ -{ lib, stdenv, fetchFromGitHub, runCommandLocal, ... }: -let - mkGrammarPackage = - { name - , src - , grammarPath ? "src" - , grammarCompileArgs ? [ "-O3" "-c" "-fpic" "../parser.c" "../scanner.c" "-I" ".." ] - , grammarLinkArgs ? [ "-shared" "-fpic" "parser.o" "scanner.o" ] - , ... - }: stdenv.mkDerivation { - inherit src; - name = "kak-tree-sitter-grammar-${name}"; - version = "latest"; - buildPhase = '' - mkdir ${grammarPath}/build - cd ${grammarPath}/build - $CC ${lib.concatStringsSep " " grammarCompileArgs} - $CC ${lib.concatStringsSep " " grammarLinkArgs} -o ${name}.so - ''; - installPhase = '' - mkdir $out - cp ${name}.so $out - ''; - }; - mkGrammar = - args @ { name - , src - , grammarPath ? "src" - , grammarCompileArgs ? [ "-O3" "-c" "-fpic" "../parser.c" "../scanner.c" "-I" ".." ] - , grammarLinkArgs ? [ "-shared" "-fpic" "parser.o" "scanner.o" ] - , querySrc ? src - , queryPath ? "runtime/queries/${name}" - , - }: { - grammar.source.local.path = "${mkGrammarPackage args}"; - grammar.link_args = grammarLinkArgs ++ [ "-o" "${name}.so" ]; - queries.source.local.path = querySrc; - queries.path = queryPath; - }; - - tree-sitter-go = fetchFromGitHub { - owner = "tree-sitter"; - repo = "tree-sitter-go"; - rev = "v0.20.0"; - hash = "sha256-G7d8CHCyKDAb9j6ijRfHk/HlgPqSI+uvkuRIRRvjkHI="; - }; -in -{ - grammars = builtins.mapAttrs (name: value: mkGrammar ({ inherit name; } // value)) { - scala = { - src = fetchFromGitHub { - owner = "tree-sitter"; - repo = "tree-sitter-scala"; - rev = "70afdd5632d57dd63a960972ab25945e353a52f6"; - hash = "sha256-bi0Lqo/Zs2Uaz1efuKAARpEDg5Hm59oUe7eSXgL1Wow="; - }; - queryPath = "queries/scala"; - }; - haskell = { - src = fetchFromGitHub { - owner = "tree-sitter"; - repo = "tree-sitter-haskell"; - rev = "ba0bfb0e5d8e9e31c160d287878c6f26add3ec08"; - hash = "sha256-ZSOF0CLOn82GwU3xgvFefmh/AD2j5zz8I0t5YPwfan0="; - }; - grammarCompileArgs = [ "-O3" "-c" "-fpic" "../parser.c" "../scanner.c" "../unicode.h" "-I" ".." ]; - queryPath = "queries"; - }; - yaml = { - src = fetchFromGitHub { - owner = "ikatyang"; - repo = "tree-sitter-yaml"; - rev = "0e36bed171768908f331ff7dff9d956bae016efb"; - hash = "sha256-bpiT3FraOZhJaoiFWAoVJX1O+plnIi8aXOW2LwyU23M="; - }; - grammarCompileArgs = [ "-c" "-fpic" "../scanner.cc" "../parser.c" "-I" ".." ]; - grammarLinkArgs = [ "-lstdc++" "-shared" "-fpic" "scanner.o" "parser.o" ]; - querySrc = fetchFromGitHub { - owner = "helix-editor"; - repo = "helix"; - rev = "dbd248fdfa680373d94fbc10094a160aafa0f7a7"; - hash = "sha256-wk8qVUDFXhAOi1Ibc6iBMzDCXb6t+YiWZcTd0IJybqc="; - }; - }; - templ = rec { - src = fetchFromGitHub { - owner = "vrischmann"; - repo = "tree-sitter-templ"; - rev = "044ad200092170727650fa6d368df66a8da98f9d"; - hash = "sha256-hJuB3h5pp+LLfP0/7bAYH0uLVo+OQk5jpzJb3J9BNkY="; - }; - querySrc = runCommandLocal "templ-tree-sitter-queries" { } '' - mkdir -p $out/queries - # copy most stuff from tree-sitter-templ - install -m644 ${src}/queries/templ/* $out/queries - # override inherited files - cat ${tree-sitter-go}/queries/highlights.scm ${src}/queries/templ/highlights.scm > $out/queries/highlights.scm - ''; - queryPath = "queries"; - }; - go = { - src = tree-sitter-go; - grammarCompileArgs = [ "-O3" "-c" "-fpic" "../parser.c" "-I" ".." ]; - grammarLinkArgs = [ "-shared" "-fpic" "parser.o" ]; - queryPath = "queries"; - }; - hylo = { - src = fetchFromGitHub { - owner = "natsukagami"; - repo = "tree-sitter-hylo"; - rev = "494cbdff0d13cbc67348316af2efa0286dbddf6f"; - hash = "sha256-R5UeoglCTl0do3VDJ/liCTeqbxU9slvmVKNRA/el2VY="; - }; - grammarCompileArgs = [ "-O3" "-c" "-fpic" "../parser.c" "-I" ".." ]; - grammarLinkArgs = [ "-shared" "-fpic" "parser.o" ]; - queryPath = "queries"; - }; - }; -} -