kakoune: add kak-tree-sitter

This commit is contained in:
Leonardo Eugênio 2024-08-09 15:07:56 -03:00
parent 6237543c62
commit 991aeebc14
5 changed files with 215 additions and 2 deletions

View file

@ -2,11 +2,12 @@
# You can build them using 'nix build .#example' or (legacy) 'nix-build -A example'
{ pkgs, inputs }:
{
rec {
blade-formatter = pkgs.callPackage ./blade-formatter { };
cargo-checkmate = pkgs.callPackage ./cargo-checkmate.nix { };
lipsum = pkgs.callPackage ./lipsum.nix { };
emmet-cli = pkgs.callPackage ./emmet-cli.nix { };
material-wifi-icons = pkgs.callPackage ./material-wifi-icons.nix { };
gnome-pass-search-provider = pkgs.callPackage ./gnome-pass-search-provider.nix { };
kak-tree-sitter = pkgs.callPackage ./kak-tree-sitter.nix { };
}

34
pkgs/kak-tree-sitter.nix Normal file
View file

@ -0,0 +1,34 @@
{
lib,
stdenv,
rustPlatform,
fetchFromSourcehut,
makeWrapper,
}:
rustPlatform.buildRustPackage rec {
pname = "cargo-checkmate";
version = "1.1.2";
src = fetchFromSourcehut {
owner = "~hadronized";
repo = "kak-tree-sitter";
rev = "kak-tree-sitter-v${version}";
hash = "sha256-wBWfSyR8LGtug/mCD0bJ4lbdN3trIA/03AnCxZoEOSA=";
};
cargoSha256 = "sha256-DDXMsH5wA6Q3jFGjYBkU3x9yOto3zeUSHP6ifkveJe0=";
nativeBuildInputs = [ makeWrapper ];
postFixup = ''
wrapProgram "$out/bin/ktsctl" \
--suffix PATH : ${stdenv.cc}
'';
meta = with lib; {
description = "Server that interfaces tree-sitter with kakoune";
homepage = "https://git.sr.ht/~hadronized/kak-tree-sitter";
license = with licenses; [ mit ];
};
}

View file

@ -114,3 +114,112 @@ with colors;
Hint = "blue";
}
))
+ ''
# Color palette
declare-option str red "red"
declare-option str mauve "magenta"
declare-option str maroon "rgb:ee99a0"
declare-option str pink "rgb:f5bde6"
declare-option str cyan "cyan"
declare-option str yellow "yellow"
declare-option str green "green"
declare-option str white "white"
declare-option str blue "blue"
declare-option str sky "rgb:91d7e3"
declare-option str lavender "rgb:b7bdf8"
declare-option str black1 "rgb:202020"
declare-option str black2 "rgb:272727"
declare-option str black3 "rgb:3a3a3a"
declare-option str orange "rgb:f5a97f"
declare-option str teal "rgb:8bd5ca"
declare-option str flamingo "rgb:f0c6c6"
declare-option str gray0 "rgb:606060"
declare-option str gray1 "rgb:737373"
declare-option str bright_red "%opt{red}+b"
declare-option str bright_green "%opt{green}+b"
declare-option str bright_yellow "%opt{yellow}+b"
declare-option str bright_blue "%opt{blue}+b"
declare-option str bright_cyan "%opt{cyan}+b"
declare-option str foreground %opt{white}
declare-option str background %opt{black2}
declare-option str overlay0 "rgb:878787"
declare-option str overlay1 "rgb:9a9a9a"
# Tree-sitter (<https://git.sr.ht/~hadronized/kak-tree-sitter>)
set-face global ts_attribute "%opt{blue}"
set-face global ts_comment "%opt{overlay0}+i"
set-face global ts_conceal "%opt{mauve}+i"
set-face global ts_constant "%opt{orange}"
set-face global ts_constant_builtin_boolean "%opt{sky}"
set-face global ts_constant_character "%opt{yellow}"
set-face global ts_constant_macro "%opt{mauve}"
set-face global ts_constructor "%opt{cyan}"
set-face global ts_diff_plus "%opt{green}"
set-face global ts_diff_minus "%opt{red}"
set-face global ts_diff_delta "%opt{blue}"
set-face global ts_diff_delta_moved "%opt{mauve}"
set-face global ts_error "%opt{red}+b"
set-face global ts_function "%opt{blue}"
set-face global ts_function_builtin "%opt{blue}+i"
set-face global ts_function_macro "%opt{mauve}"
set-face global ts_hint "%opt{blue}+b"
set-face global ts_info "%opt{green}+b"
set-face global ts_keyword "%opt{mauve}"
set-face global ts_keyword_conditional "%opt{mauve}+i"
set-face global ts_keyword_control_conditional "%opt{mauve}+i"
set-face global ts_keyword_control_directive "%opt{mauve}+i"
set-face global ts_keyword_control_import "%opt{mauve}+i"
set-face global ts_keyword_directive "%opt{mauve}+i"
set-face global ts_keyword_storage "%opt{mauve}"
set-face global ts_keyword_storage_modifier "%opt{mauve}"
set-face global ts_keyword_storage_modifier_mut "%opt{mauve}"
set-face global ts_keyword_storage_modifier_ref "%opt{teal}"
set-face global ts_label "%opt{cyan}+i"
set-face global ts_markup_bold "%opt{orange}+b"
set-face global ts_markup_heading "%opt{red}"
set-face global ts_markup_heading_1 "%opt{red}"
set-face global ts_markup_heading_2 "%opt{mauve}"
set-face global ts_markup_heading_3 "%opt{green}"
set-face global ts_markup_heading_4 "%opt{yellow}"
set-face global ts_markup_heading_5 "%opt{pink}"
set-face global ts_markup_heading_6 "%opt{teal}"
set-face global ts_markup_heading_marker "%opt{orange}+b"
set-face global ts_markup_italic "%opt{pink}+i"
set-face global ts_markup_list_checked "%opt{green}"
set-face global ts_markup_list_numbered "%opt{blue}+i"
set-face global ts_markup_list_unchecked "%opt{teal}"
set-face global ts_markup_list_unnumbered "%opt{mauve}"
set-face global ts_markup_link_label "%opt{blue}"
set-face global ts_markup_link_url "%opt{teal}+u"
set-face global ts_markup_link_uri "%opt{teal}+u"
set-face global ts_markup_link_text "%opt{blue}"
set-face global ts_markup_quote "%opt{gray1}"
set-face global ts_markup_raw "%opt{green}"
set-face global ts_markup_strikethrough "%opt{gray1}+s"
set-face global ts_namespace "%opt{blue}+i"
set-face global ts_operator "%opt{sky}"
set-face global ts_property "%opt{sky}"
set-face global ts_punctuation "%opt{overlay1}"
set-face global ts_punctuation_special "%opt{sky}"
set-face global ts_special "%opt{blue}"
set-face global ts_spell "%opt{mauve}"
set-face global ts_string "%opt{green}"
set-face global ts_string_regex "%opt{orange}"
set-face global ts_string_regexp "%opt{orange}"
set-face global ts_string_escape "%opt{mauve}"
set-face global ts_string_special "%opt{blue}"
set-face global ts_string_special_path "%opt{green}"
set-face global ts_string_special_symbol "%opt{mauve}"
set-face global ts_string_symbol "%opt{red}"
set-face global ts_tag "%opt{mauve}"
set-face global ts_tag_error "%opt{red}"
set-face global ts_text "%opt{white}"
set-face global ts_text_title "%opt{mauve}"
set-face global ts_type "%opt{yellow}"
set-face global ts_type_enum_variant "%opt{flamingo}"
set-face global ts_variable "%opt{white}"
set-face global ts_variable_builtin "%opt{red}"
set-face global ts_variable_other_member "%opt{teal}"
set-face global ts_variable_parameter "%opt{maroon}+i"
set-face global ts_warning "%opt{orange}+b"
''

View file

@ -6,7 +6,6 @@
}:
let
inherit (config.my)
key
dmenu
editor
theme
@ -17,6 +16,7 @@ let
inherit (pkgs.kakouneUtils) buildKakounePlugin;
in
{
imports = [ ./kak-tree-sitter.nix ];
config = {
programs.kakoune = {
enable = true;
@ -100,6 +100,9 @@ in
)
)
+ ''
try %{
eval %sh{ kak-tree-sitter -vvvv -dks --init $kak_session }
}
set global scrolloff 10,20
set global autoreload yes
@ -118,11 +121,13 @@ in
home.file = {
".config/kak-lsp/kak-lsp.toml".source = ./kak-lsp.toml;
};
home.packages = with pkgs; [
terminal
ranger
bmenu
kak-lsp
kak-tree-sitter
kak-pager
kak-man-pager

View file

@ -0,0 +1,64 @@
{ pkgs, lib, ... }:
let
hx-src = pkgs.helix.src;
kts-src = pkgs.kak-tree-sitter.src;
inherit (pkgs) fetchFromGitHub;
in
with pkgs.tree-sitter-grammars;
{
xdg.configFile."kak-tree-sitter/config.toml".text =
lib.foldlAttrs
(
acc: name: vals:
acc
+ ''
[language.${name}.grammar.source.local]
path = "${vals.parser}"
[language.${name}.grammar]
compile = "cc"
compile_args = ["-c", "-fpic", "../scanner.c", "../parser.c", "-I", ".."]
compile_flags = ["-O3"]
link = "cc"
link_args = ["-shared", "-fpic", "scanner.o", "parser.o", "-o", "typescript.so"]
link_flags = ["-O3"]
[language.${name}.queries.source.local]
path = "${vals.queries}"
[language.${name}.queries]
path = "${vals.queries}"
''
)
""
{
nix = {
parser = tree-sitter-nix + "/parser";
queries = tree-sitter-nix + "/queries";
};
scss = {
parser = tree-sitter-scss + "/parser";
queries = tree-sitter-scss + "/queries";
};
css = {
parser = tree-sitter-css + "/parser";
queries = tree-sitter-css + "/queries";
};
javascript = {
parser = tree-sitter-javascript + "/parser";
queries = tree-sitter-javascript + "/queries";
};
typescript = {
parser =
tree-sitter-typescript.overrideAttrs (old: {
src = fetchFromGitHub {
owner = "tree-sitter";
repo = "tree-sitter-typescript";
rev = "b1bf4825d9eaa0f3bdeb1e52f099533328acfbdf";
hash = "sha256-oZKit8kScXcOptmT2ckywL5JlAVe+wuwhuj6ThEI5OQ=";
};
})
+ "/parser";
queries = kts-src + "/runtime/queries/typescript";
};
};
}