Git Product home page Git Product logo

kak-tree's Introduction

Structural selections for Kakoune

kak-tree is a plugin for Kakoune which enables selection of syntax tree nodes. Parsing is performed with tree-sitter.

Status: proof of concept, interface and overall development direction could change drastically based on feedback.

Installation

Replace "rust javascript" with a list of languages you need. Or use all to build all supported languages. Note that all build takes a long time, and resulting binary is quite fat which could have a negative impact on responsiveness.

git clone --recurse-submodules
cargo install --path . --force --features "rust javascript"
cp rc/tree.kak ~/.config/kak/autoload/

Look at Cargo.toml for a full list of supported languages.

It is possible to check programmaticaly if kak-tree was built with support for a given filetype:

kak-tree --do-you-understand rust

If language is supported then exit code is 0 otherwise it’s non-zero (1 at the moment, but it is not guaranteed in future).

Usage

Tree-sitter parsers produce very detailed syntax tree, many elements of which are not interesting for day-to-day selection purposes. kak-tree introduces the concept of a visible node. Node is visible when:

  1. Node is named in the tree-sitter grammar for the given language (as opposed to anonymous nodes, more).

  2. Either there is no white/blacklist for the given filetype or node kind is whitelisted or not blacklisted. See Configuration for details about white/blacklisting.

Most of the kak-tree commands operate on visible nodes and skip not visible ones.

tree-select-parent-node [<KIND>]

Select the closest visible ancestor or ancestor of KIND when provided.

tree-select-next-node [<KIND>]

Select the closest visible next sibling or next sibling of KIND when provided.

tree-select-previous-node [<KIND>]

Select the closest visible previous sibling or previous sibling of KIND when provided.

tree-select-children [<KIND>]

Select all immediate visible children or all descendants matching KIND when provided.

tree-select-first-child [<KIND>]

Select the first immediate visible children or the first descendant matching KIND when provided.

tree-node-sexp

Show info box with a syntax tree of the main selection parent.

Configuration

kak-tree supports configuration via a configuration file. As for now there is no default path to load the configuration file, and it must be given using CLI option --config or -c for short:

set global tree_cmd 'kak-tree -c /path/to/kak-tree.toml'

Filetype configuration

Configuration for specific filetypes should be provided like this:

[filetype.rust]
blacklist = ["identifier", "scoped_identifier", "string_literal"]
whitelist = ["function_item"]
group.identifier = ["identifier", "scoped_identifier"]
group.fn = ["function_item"]

[filetype.javascript]
group.fn = ["function", "arrow_function"]

Configuration under the [filetype.default] key will be used for all filetypes without configuration. Specific filetype configuration doesn’t extend default configuration but rather overwrites it.

White/blacklisting

If whitelist array is provided then kak-tree selection will skip nodes which kinds are not whitelisted. If blacklist array is provided then kak-tree selection will skip nodes which kinds are blacklisted.

Note
whitelist takes precedence over blacklist. In the Rust example above kak-tree would expand selection up to the function definition, ignoring other node kinds.
Note
tree-node-sexp command is useful for exploring node kinds which appear in the specific code.

Whitelisting or blacklisting node kinds could be tedious as tree-sitter parsers define many of them, but it also could be rewarding as you will be able to quickly modify selection in scopes which matter for you with fewer keystrokes.

Kind groups

Groups of node kinds serve a two-fold purpose:

  1. Groups allow matching functionally similar node kinds (i.e. identifier and scoped_identifier in Rust) by a single query.

  2. Groups allow matching functionally similar nodes across filetypes (i.e. function_item in Rust and function in JavaScript) as tree-sitter parsers don’t use uniform node kind names.

Note
whitelist and blacklist options doesn’t expand groups yet.

License

For kak-tree see UNLICENSE file. For tree-sitter and its parsers look at their repositories.

kak-tree's People

Contributors

bhougland18 avatar brianhicks avatar jcai849 avatar screwtapello avatar ul avatar vbauerster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

kak-tree's Issues

Script to show the different navigation options dynamically

Hi, I wanted to explore what parts of the buffer the different navigation functions span in an interactive and dynamic way so I wrote this script. Wasn't sure where to post it so posting it here in case someone finds it interesting:

try %{
    decl range-specs tree_first
    decl range-specs tree_next
    decl range-specs tree_prev
    decl range-specs tree_parent
    decl range-specs tree_children
}
def dyntree %{
    rmhooks window tree
    try %{
        addhl window/ ranges tree_children
        addhl window/ ranges tree_first
        addhl window/ ranges tree_prev
        addhl window/ ranges tree_next
        addhl window/ ranges tree_parent
    }
    hook -group tree window NormalIdle .* %{
        set window tree_children %val{timestamp}
        set window tree_first %val{timestamp}
        set window tree_prev %val{timestamp}
        set window tree_next %val{timestamp}
        set window tree_parent %val{timestamp}
        eval -draft -itersel %{ try %{
            tree-select-next-node
            set -add window tree_next "%val{selection_desc}|default+b"
        }}
        eval -draft -itersel %{ try %{
            tree-select-previous-node
            set -add window tree_prev "%val{selection_desc}|default+i"
        }}
        eval -draft -itersel %{ try %{
            tree-select-parent-node
            set -add window tree_parent "%val{selection_desc}|default,rgb:333333"
        }}
        eval -draft -itersel %{ try %{
            tree-select-children
            eval -draft -itersel %{
                set -add window tree_children "%val{selection_desc}|default+u"
            }
        }}
        eval -draft -itersel %{ try %{
            tree-select-first
            set -add window tree_first "%val{selection_desc}|default,red"
        }}
    }
}

Build fails when Clojure parser is enabled

It looks like there's a linker error when building with Clojure support, not sure if the issue is on the kak-tree end or with tree-sitter-clojure. Building with any language other than Clojure works fine.

  Installing kak-tree v0.1.0 (/tmp/kak-tree)
    Updating crates.io index
   Compiling libc v0.2.93
   Compiling autocfg v1.0.1
   Compiling proc-macro2 v1.0.26
   Compiling unicode-xid v0.2.1
   Compiling cfg-if v1.0.0
   Compiling syn v1.0.69
   Compiling slog v2.7.0
   Compiling serde_derive v1.0.125
   Compiling memchr v2.3.4
   Compiling serde v1.0.125
   Compiling lazy_static v1.4.0
   Compiling log v0.4.14
   Compiling crc32fast v1.2.1
   Compiling regex-syntax v0.6.23
   Compiling ryu v1.0.5
   Compiling once_cell v1.7.2
   Compiling arc-swap v1.2.0
   Compiling serde_json v1.0.64
   Compiling bitflags v1.2.1
   Compiling take_mut v0.2.2
   Compiling rle-decode-fast v1.0.1
   Compiling itoa v0.4.7
   Compiling crossbeam v0.2.12
   Compiling adler32 v1.2.0
   Compiling unicode-width v0.1.8
   Compiling vec_map v0.8.2
   Compiling either v1.6.1
   Compiling ansi_term v0.11.0
   Compiling strsim v0.8.0
   Compiling num-traits v0.2.14
   Compiling num-integer v0.1.44
   Compiling crossbeam-utils v0.8.3
   Compiling thread_local v1.1.3
   Compiling textwrap v0.11.0
   Compiling itertools v0.8.2
   Compiling aho-corasick v0.7.15
   Compiling slog-scope v4.4.0
   Compiling quote v1.0.9
   Compiling dirs-sys-next v0.1.2
   Compiling time v0.1.43
   Compiling atty v0.2.14
   Compiling log v0.3.9
   Compiling jobserver v0.1.21
   Compiling libflate v0.1.27
   Compiling dirs-next v2.0.0
   Compiling clap v2.33.3
   Compiling slog-stdlog v3.0.5
   Compiling crossbeam-channel v0.5.0
   Compiling regex v1.4.5
   Compiling cc v1.0.67
   Compiling term v0.7.0
   Compiling slog-async v2.6.0
   Compiling slog-kvfilter v0.7.0
   Compiling chrono v0.4.19
   Compiling tree-sitter v0.6.3
   Compiling kak-tree v0.1.0 (/tmp/kak-tree)
   Compiling trackable_derive v1.0.0
   Compiling slog-term v2.8.0
   Compiling trackable v1.2.0
   Compiling trackable v0.2.24
warning: In file included from vendor/tree-sitter-rust/src/parser.c:1:
warning: vendor/tree-sitter-rust/src/parser.c: In function ‘ts_lex_keywords’:
warning: vendor/tree-sitter-rust/src/tree_sitter/parser.h:131:8: warning: variable ‘eof’ set but not used [-Wunused-but-set-variable]
warning:   131 |   bool eof = false;             \
warning:       |        ^~~
warning: vendor/tree-sitter-rust/src/parser.c:4786:3: note: in expansion of macro ‘START_LEXER’
warning:  4786 |   START_LEXER();
warning:       |   ^~~~~~~~~~~
warning: vendor/tree-sitter-rust/src/scanner.c: In function ‘tree_sitter_rust_external_scanner_destroy’:
warning: vendor/tree-sitter-rust/src/scanner.c:12:54: warning: unused parameter ‘p’ [-Wunused-parameter]
warning:    12 | void tree_sitter_rust_external_scanner_destroy(void *p) {}
warning:       |                                                ~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c: In function ‘tree_sitter_rust_external_scanner_reset’:
warning: vendor/tree-sitter-rust/src/scanner.c:13:52: warning: unused parameter ‘p’ [-Wunused-parameter]
warning:    13 | void tree_sitter_rust_external_scanner_reset(void *p) {}
warning:       |                                              ~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c: In function ‘tree_sitter_rust_external_scanner_serialize’:
warning: vendor/tree-sitter-rust/src/scanner.c:14:60: warning: unused parameter ‘p’ [-Wunused-parameter]
warning:    14 | unsigned tree_sitter_rust_external_scanner_serialize(void *p, char *buffer) { return 0; }
warning:       |                                                      ~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c:14:69: warning: unused parameter ‘buffer’ [-Wunused-parameter]
warning:    14 | unsigned tree_sitter_rust_external_scanner_serialize(void *p, char *buffer) { return 0; }
warning:       |                                                               ~~~~~~^~~~~~
warning: vendor/tree-sitter-rust/src/scanner.c: In function ‘tree_sitter_rust_external_scanner_deserialize’:
warning: vendor/tree-sitter-rust/src/scanner.c:15:58: warning: unused parameter ‘p’ [-Wunused-parameter]
warning:    15 | void tree_sitter_rust_external_scanner_deserialize(void *p, const char *b, unsigned n) {}
warning:       |                                                    ~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c:15:73: warning: unused parameter ‘b’ [-Wunused-parameter]
warning:    15 | void tree_sitter_rust_external_scanner_deserialize(void *p, const char *b, unsigned n) {}
warning:       |                                                             ~~~~~~~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c:15:85: warning: unused parameter ‘n’ [-Wunused-parameter]
warning:    15 | void tree_sitter_rust_external_scanner_deserialize(void *p, const char *b, unsigned n) {}
warning:       |                                                                            ~~~~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c: In function ‘tree_sitter_rust_external_scanner_scan’:
warning: vendor/tree-sitter-rust/src/scanner.c:25:51: warning: unused parameter ‘payload’ [-Wunused-parameter]
warning:    25 | bool tree_sitter_rust_external_scanner_scan(void *payload, TSLexer *lexer,
warning:       |                                             ~~~~~~^~~~~~~
   Compiling sloggers v0.3.6
   Compiling toml v0.5.8
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-Wl,--eh-frame-hdr" "-L" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.0.rcgu.o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.1.rcgu.o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.10.rcgu.o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.11.rcgu.o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.12.rcgu.o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.13.rcgu.o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.14.rcgu.o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.15.rcgu.o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.2.rcgu.o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.3.rcgu.o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.4.rcgu.o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.5.rcgu.o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.6.rcgu.o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.7.rcgu.o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.8.rcgu.o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.9.rcgu.o" "-o" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd" "/tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.4ofns8yp5ufdmjr5.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/tmp/kak-tree/target/release/deps" "-L" "/tmp/kak-tree/target/release/build/kak-tree-ab61f15e16d32ff4/out" "-L" "/tmp/kak-tree/target/release/build/tree-sitter-306936e9b8cc66eb/out" "-L" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,--whole-archive" "-ltree_sitter_rust" "-Wl,--no-whole-archive" "/tmp/kak-tree/target/release/deps/libsloggers-1eeed2c6bd9a410e.rlib" "/tmp/kak-tree/target/release/deps/libslog_stdlog-5645424089bba576.rlib" "/tmp/kak-tree/target/release/deps/liblog-cee1a2d76e2c2040.rlib" "/tmp/kak-tree/target/release/deps/liblog-3217f079d39ad321.rlib" "/tmp/kak-tree/target/release/deps/libslog_scope-27523e7d6ae9f3f5.rlib" "/tmp/kak-tree/target/release/deps/libarc_swap-efd09bc77ce54347.rlib" "/tmp/kak-tree/target/release/deps/libslog_term-4a3068b01d4c8cc6.rlib" "/tmp/kak-tree/target/release/deps/libterm-dc165d97de4583d0.rlib" "/tmp/kak-tree/target/release/deps/libdirs_next-21910acbbce7f489.rlib" "/tmp/kak-tree/target/release/deps/libdirs_sys_next-0d62cf5325636b23.rlib" "/tmp/kak-tree/target/release/deps/libslog_kvfilter-79ce97abe554b79e.rlib" "/tmp/kak-tree/target/release/deps/libslog_async-43eca4efd6a2accf.rlib" "/tmp/kak-tree/target/release/deps/libthread_local-bb811fc8ce57121e.rlib" "/tmp/kak-tree/target/release/deps/libonce_cell-21e9da22f98e7d77.rlib" "/tmp/kak-tree/target/release/deps/libcrossbeam_channel-7a2069f71f26076e.rlib" "/tmp/kak-tree/target/release/deps/libcrossbeam_utils-c62ff02066b71b37.rlib" "/tmp/kak-tree/target/release/deps/liblazy_static-49b79ac062ddc731.rlib" "/tmp/kak-tree/target/release/deps/liblibflate-a0e3b73efdde4630.rlib" "/tmp/kak-tree/target/release/deps/libtake_mut-193d4ebcb9156139.rlib" "/tmp/kak-tree/target/release/deps/librle_decode_fast-6fcf494338ada9cb.rlib" "/tmp/kak-tree/target/release/deps/libcrc32fast-274d6f6356d94d49.rlib" "/tmp/kak-tree/target/release/deps/libcfg_if-b95e3d47d2a2d145.rlib" "/tmp/kak-tree/target/release/deps/libadler32-0ee79bcb36f70fa9.rlib" "/tmp/kak-tree/target/release/deps/libchrono-302881bbca6b1abe.rlib" "/tmp/kak-tree/target/release/deps/libnum_integer-2525a9e376d5a1b6.rlib" "/tmp/kak-tree/target/release/deps/libnum_traits-bd4102865d3c8970.rlib" "/tmp/kak-tree/target/release/deps/libtime-29ac76053d9df293.rlib" "/tmp/kak-tree/target/release/deps/libtrackable-6bb424b4fbf54565.rlib" "/tmp/kak-tree/target/release/deps/libtrackable-65fbadd61b6dbd0d.rlib" "/tmp/kak-tree/target/release/deps/libslog-c0caacfe6620a2ac.rlib" "/tmp/kak-tree/target/release/deps/libitertools-e85e3838ae2fd07b.rlib" "/tmp/kak-tree/target/release/deps/libeither-a362c5c541bcdacf.rlib" "/tmp/kak-tree/target/release/deps/libtree_sitter-5db51dddabd2d7fa.rlib" "/tmp/kak-tree/target/release/deps/libserde_json-80772460659655b2.rlib" "/tmp/kak-tree/target/release/deps/libryu-3fa383024d70cfd5.rlib" "/tmp/kak-tree/target/release/deps/libitoa-8be987539cea4b1a.rlib" "/tmp/kak-tree/target/release/deps/libregex-c77882308e7405a0.rlib" "/tmp/kak-tree/target/release/deps/libregex_syntax-7ee6b1ce20264869.rlib" "/tmp/kak-tree/target/release/deps/libaho_corasick-c173c70426dfa388.rlib" "/tmp/kak-tree/target/release/deps/libmemchr-181c467024449d26.rlib" "/tmp/kak-tree/target/release/deps/libtoml-292dd52216298da8.rlib" "/tmp/kak-tree/target/release/deps/libserde-29830bcbd37a4322.rlib" "/tmp/kak-tree/target/release/deps/libclap-f4ab859b9018ac7c.rlib" "/tmp/kak-tree/target/release/deps/libvec_map-c42ec140ccfeaea4.rlib" "/tmp/kak-tree/target/release/deps/libtextwrap-62842afc18504c5d.rlib" "/tmp/kak-tree/target/release/deps/libunicode_width-3b67f6fb85ed7051.rlib" "/tmp/kak-tree/target/release/deps/libstrsim-05739d31f55d9fad.rlib" "/tmp/kak-tree/target/release/deps/libbitflags-ba348557b137d58f.rlib" "/tmp/kak-tree/target/release/deps/libatty-5172cacccb0041c5.rlib" "/tmp/kak-tree/target/release/deps/liblibc-908b86b80da34306.rlib" "/tmp/kak-tree/target/release/deps/libansi_term-441f14aa2c239a15.rlib" "-Wl,--start-group" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-e12de7683a34c500.rlib" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-446a53c2e468675f.rlib" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-86fef9fb252a2d33.rlib" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-3bed9bfd30304751.rlib" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-0e38eeb474a7b386.rlib" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-a846ed547b824740.rlib" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-c9540f0a4fb9265d.rlib" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-7d2ca66c92c356eb.rlib" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-147e2c808f949493.rlib" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-bd2a4369506670e9.rlib" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-74bfdd0ce7d0ed48.rlib" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-6777f47f1c491841.rlib" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-b104f1790174f2be.rlib" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-db37898996f45c13.rlib" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-25b7435131fc4938.rlib" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-9d4b6f3c097e876e.rlib" "-Wl,--end-group" "/home/adrusi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-3f953ad652ab829a.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc"
  = note: /usr/bin/ld: /tmp/kak-tree/target/release/deps/kak_tree-236aa2289bc214bd.kak_tree.athnaazl-cgu.5.rcgu.o: in function `kak_tree::main':
          kak_tree.athnaazl-cgu.5:(.text._ZN8kak_tree4main17hc00e256c4b715222E+0x6fb): undefined reference to `tree_sitter_clojure'
          /usr/bin/ld: kak_tree.athnaazl-cgu.5:(.text._ZN8kak_tree4main17hc00e256c4b715222E+0x2381): undefined reference to `tree_sitter_clojure'
          collect2: error: ld returned 1 exit status


error: aborting due to previous error

The following warnings were emitted during compilation:

warning: In file included from vendor/tree-sitter-rust/src/parser.c:1:
warning: vendor/tree-sitter-rust/src/parser.c: In function ‘ts_lex_keywords’:
warning: vendor/tree-sitter-rust/src/tree_sitter/parser.h:131:8: warning: variable ‘eof’ set but not used [-Wunused-but-set-variable]
warning:   131 |   bool eof = false;             \
warning:       |        ^~~
warning: vendor/tree-sitter-rust/src/parser.c:4786:3: note: in expansion of macro ‘START_LEXER’
warning:  4786 |   START_LEXER();
warning:       |   ^~~~~~~~~~~
warning: vendor/tree-sitter-rust/src/scanner.c: In function ‘tree_sitter_rust_external_scanner_destroy’:
warning: vendor/tree-sitter-rust/src/scanner.c:12:54: warning: unused parameter ‘p’ [-Wunused-parameter]
warning:    12 | void tree_sitter_rust_external_scanner_destroy(void *p) {}
warning:       |                                                ~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c: In function ‘tree_sitter_rust_external_scanner_reset’:
warning: vendor/tree-sitter-rust/src/scanner.c:13:52: warning: unused parameter ‘p’ [-Wunused-parameter]
warning:    13 | void tree_sitter_rust_external_scanner_reset(void *p) {}
warning:       |                                              ~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c: In function ‘tree_sitter_rust_external_scanner_serialize’:
warning: vendor/tree-sitter-rust/src/scanner.c:14:60: warning: unused parameter ‘p’ [-Wunused-parameter]
warning:    14 | unsigned tree_sitter_rust_external_scanner_serialize(void *p, char *buffer) { return 0; }
warning:       |                                                      ~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c:14:69: warning: unused parameter ‘buffer’ [-Wunused-parameter]
warning:    14 | unsigned tree_sitter_rust_external_scanner_serialize(void *p, char *buffer) { return 0; }
warning:       |                                                               ~~~~~~^~~~~~
warning: vendor/tree-sitter-rust/src/scanner.c: In function ‘tree_sitter_rust_external_scanner_deserialize’:
warning: vendor/tree-sitter-rust/src/scanner.c:15:58: warning: unused parameter ‘p’ [-Wunused-parameter]
warning:    15 | void tree_sitter_rust_external_scanner_deserialize(void *p, const char *b, unsigned n) {}
warning:       |                                                    ~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c:15:73: warning: unused parameter ‘b’ [-Wunused-parameter]
warning:    15 | void tree_sitter_rust_external_scanner_deserialize(void *p, const char *b, unsigned n) {}
warning:       |                                                             ~~~~~~~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c:15:85: warning: unused parameter ‘n’ [-Wunused-parameter]
warning:    15 | void tree_sitter_rust_external_scanner_deserialize(void *p, const char *b, unsigned n) {}
warning:       |                                                                            ~~~~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c: In function ‘tree_sitter_rust_external_scanner_scan’:
warning: vendor/tree-sitter-rust/src/scanner.c:25:51: warning: unused parameter ‘payload’ [-Wunused-parameter]
warning:    25 | bool tree_sitter_rust_external_scanner_scan(void *payload, TSLexer *lexer,
warning:       |                                             ~~~~~~^~~~~~~

error: failed to compile `kak-tree v0.1.0 (/tmp/kak-tree)`, intermediate artifacts can be found at `/tmp/kak-tree/target`

Caused by:
  could not compile `kak-tree`

To learn more, run the command again with --verbose.

Modifying selections with path patterns

Raw Kakoune has commands to add and move selections through the file's linear structure, like h and C and ]p.

kak-tree has commands to add and move selections through the file's hierarchical structure, like tree-select-node and tree-select-prev-node and tree-select-children.

Raw Kakoune also has commands to sub-select and filter selections based on the file's linear structure, like s and k.

kak-tree should have commands to sub-select and filter selections based on the file's hierarchical structure:

  • tree-select-nodes KIND selects all the KIND nodes wholly contained within an existing selection
  • tree-split-nodes KIND slices the KIND nodes out of existing selections
    • not so useful in a hierarchical context, but for completeness and by analogy with Kakoune's core operators
  • tree-keep-matching KIND discards selections that do not wholly contain at least one KIND node
  • tree-kill-matching KIND discards selections that do wholly contain at least one KIND node

Ideally, these commands should use -shell-script-candidates to let Kakoune auto-complete the possible kinds for the current file.

There's possible extension here for kind-paths, like arguments/string_literal to only select string_literals directly inside an arguments or /arguments//string_literal to select string_literals anywhere inside whichever selections exactly cover an arguments, but that's all polish and future extension work.

Panicking on set_language

Hi!

kak-tree is panicking when trying to set the language (in this current case, to Rust, but it also happens for any other language I've tested) with the following message:

thread 'main' panicked at src/main.rs:88:35:
called `Result::unwrap()` on an `Err` value: LanguageError { version: 13 }

Steps to reproduce

You can reproduce it by building kak-tree using the instructions on README and only the Rust language as a feature (cargo install --path . --force --features rust), then running any plugin's command (e.g. tree-node-sexp).

Extra info

Rust version: 1.76 on Linux. But I'm sure it has happen for a while, since I tried it several times in the last year.

I've edited the code to print the debug information of the language variable, and it shows: Language(0x000055955bd6fa40). Not sure if it can be useful.

Is tree_cmd option ignored?

None of tree-* commands respect my config, which has some blacklist for go file types.
I've tree_cmd option set in my kakrc and it expands correctly:

set-option global tree_cmd "kak-tree -c %val{config}/kak-tree.toml"

This is content of my kak-tree.toml:

[filetype.go]
blacklist = ["nil", "block", "identifier"]

For example, if I issue tree-node-sexp, I still can see blacklisted items.

Unexpected lack of parents for expressions in python

Hi ul, I'm a bit puzzled why the python tree sitter does not go from expressions to statements. In the code below the parent nodes of the ones become 1 + 1 but the parent for that is not return 1 + 1.

def test():
    return 1 + 1

I am expecting return 1 + 1 to be the parent of 1 + 1, but right now nothing happens with tree-select-parent-node.

Kak-tree not working

Sorry for the vague title, but I really do not get a clue about why, I'm loading the rc file generated when you build kak-tree with the source command, also tried in autoloads, I built it with javascript, ruby and clojure, when I check with the --do-you-understand command those languages I indeed get the 0 code return, but inside kakoune when I run tree-node-sexp I get just nothing, I also copied the config file on the readme, I'm not getting errors in the debug buffer or anything.

Maybe I forgot to do something?

Cargo install results in binary only working with rust

I'm using rust 1.33.0-nightly.

When I do cargo build --release --features "bash c cpp julia php python rust"

I get a binary in ./target/release that works with all those languages.

However, if I run cargo install --path . the installed binary and the binary in ./target/release only work for rust. Note that I cannot simply run cargo install in this version of rust because of

error: Using `cargo install` to install the binaries for the package in current working directory is no longer supported, use `cargo install --path .` instead. Use `cargo build` if you want to simply build the package.

This might be an issue with a newer rust version.

README : be more explicit about <KIND> and add small example

Hi,
I have been advised to use kak-tree for a plugin I'm working on. But I have trouble getting started with it.
What are the value I can use in the variable ?
Could it be possible to have a tiny example of a basic workflow ? For example how to use kak-tree in a plugin script ?

panic in main

I just compiled from master with rustc 1.39.0 (4560ea788 2019-11-04) with command:

cargo install --path . --force --features "rust go"

and got following panic:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "Incompatible language version 11. Expected 10."', src/libcore/result.rs:1165:5
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::continue_panic_fmt
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::result::unwrap_failed
  10: kak_tree::main
  11: std::rt::lang_start::{{closure}}
  12: std::panicking::try::do_call
  13: __rust_maybe_catch_panic
  14: std::rt::lang_start_internal
  15: main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Cannot select between statements in C

Use this file:

int main(void) {
    printf("hello world\n");
    return 0;
}

Select from p to ; on the printf line. Now running tree-select-parent-node, tree-select-next-node, and tree-select-previous-node are no-ops.

Cargo build fails

Cloning the repo:
hub clone ul/kak-tree --recurse-submodules | tail

Output:

remote: Enumerating objects: 88, done.
remote: Total 88 (delta 0), reused 0 (delta 0), pack-reused 88
Submodule path 'vendor/tree-sitter-bash/examples/bash-it/test_lib/bats-assert': checked out '9f88b4207da750093baabc4e3f41bf68f0dd3630'
Submodule path 'vendor/tree-sitter-bash/examples/bash-it/test_lib/bats-core': checked out '85388685632f85d5a1c32e6bca2deec401964cf7'
Submodule path 'vendor/tree-sitter-bash/examples/bash-it/test_lib/bats-file': checked out '2fddb2b831d65cdf2e411f3b47f4677fbb15729c'
Submodule path 'vendor/tree-sitter-bash/examples/bash-it/test_lib/bats-support': checked out '004e707638eedd62e0481e8cdc9223ad471f12ee'
error: Server does not allow request for unadvertised object 627806ec6a6109b17de8400384474395ac2afb2d
Fetched in submodule path 'vendor/tree-sitter-c', but it did not contain 627806ec6a6109b17de8400384474395ac2afb2d. Direct fetching of that commit failed.

Building the executable:
cargo install --path . --force --features "rust"

Output:

  Installing kak-tree v0.1.0 (/Users/vincent/repos/ul/kak-tree)
    Updating crates.io index
   Compiling serde_derive v1.0.104
   Compiling kak-tree v0.1.0 (/Users/vincent/repos/ul/kak-tree)
   Compiling trackable_derive v0.1.2
error: failed to run custom build command for `kak-tree v0.1.0 (/Users/vincent/repos/ul/kak-tree)`

Caused by:
  process didn't exit successfully: `/Users/vincent/repos/ul/kak-tree/target/release/build/kak-tree-2c230ccdf8b60dd7/build-script-build` (exit code: 1)
--- stdout
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-apple-darwin")
CC_x86_64-apple-darwin = None
CC_x86_64_apple_darwin = None
HOST_CC = None
CC = None
CFLAGS_x86_64-apple-darwin = None
CFLAGS_x86_64_apple_darwin = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2,sse3,ssse3")
running: "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "vendor/tree-sitter-rust/src" "-Wall" "-Wextra" "-o" "/Users/vincent/repos/ul/kak-tree/target/release/build/kak-tree-73953501e48e9377/out/vendor/tree-sitter-rust/src/parser.o" "-c" "vendor/tree-sitter-rust/src/parser.c"
cargo:warning=clang: error: no such file or directory: 'vendor/tree-sitter-rust/src/parser.c'
cargo:warning=clang: error: no input files
exit code: 1

--- stderr


error occurred: Command "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "vendor/tree-sitter-rust/src" "-Wall" "-Wextra" "-o" "/Users/vincent/repos/ul/kak-tree/target/release/build/kak-tree-73953501e48e9377/out/vendor/tree-sitter-rust/src/parser.o" "-c" "vendor/tree-sitter-rust/src/parser.c" with args "cc" did not execute successfully (status code exit code: 1).



warning: build failed, waiting for other jobs to finish...
error: failed to compile `kak-tree v0.1.0 (/Users/vincent/repos/ul/kak-tree)`, intermediate artifacts can be found at `/Users/vincent/repos/ul/kak-tree/target`

Caused by:
  build failed
cargo -V
cargo 1.39.0 (1c6ec66d5 2019-09-30)

Build error

Could you help me to solve a compilation problem.

$ cargo install --path . --force --features "python"
  Installing kak-tree v0.1.0 (/home/user/kak-tree)
    Updating crates.io index
warning: In file included from vendor/tree-sitter-python/src/parser.c:1:
warning: vendor/tree-sitter-python/src/parser.c: In function ‘ts_lex_keywords’:
warning: vendor/tree-sitter-python/src/tree_sitter/parser.h:131:8: warning: variable ‘eof’ set but not used [-Wunused-but-set-variable]
warning:   131 |   bool eof = false;             \
warning:       |        ^~~
warning: vendor/tree-sitter-python/src/parser.c:2803:3: note: in expansion of macro ‘START_LEXER’
warning:  2803 |   START_LEXER();
warning:       |   ^~~~~~~~~~~
warning: vendor/tree-sitter-rust/src/scanner.c: In function ‘tree_sitter_rust_external_scanner_destroy’:
warning: vendor/tree-sitter-rust/src/scanner.c:12:54: warning: unused parameter ‘p’ [-Wunused-parameter]
warning:    12 | void tree_sitter_rust_external_scanner_destroy(void *p) {}
warning:       |                                                ~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c: In function ‘tree_sitter_rust_external_scanner_reset’:
warning: vendor/tree-sitter-rust/src/scanner.c:13:52: warning: unused parameter ‘p’ [-Wunused-parameter]
warning:    13 | void tree_sitter_rust_external_scanner_reset(void *p) {}
warning:       |                                              ~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c: In function ‘tree_sitter_rust_external_scanner_serialize’:
warning: vendor/tree-sitter-rust/src/scanner.c:14:60: warning: unused parameter ‘p’ [-Wunused-parameter]
warning:    14 | unsigned tree_sitter_rust_external_scanner_serialize(void *p, char *buffer) { return 0; }
warning:       |                                                      ~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c:14:69: warning: unused parameter ‘buffer’ [-Wunused-parameter]
warning:    14 | unsigned tree_sitter_rust_external_scanner_serialize(void *p, char *buffer) { return 0; }
warning:       |                                                               ~~~~~~^~~~~~
warning: vendor/tree-sitter-rust/src/scanner.c: In function ‘tree_sitter_rust_external_scanner_deserialize’:
warning: vendor/tree-sitter-rust/src/scanner.c:15:58: warning: unused parameter ‘p’ [-Wunused-parameter]
warning:    15 | void tree_sitter_rust_external_scanner_deserialize(void *p, const char *b, unsigned n) {}
warning:       |                                                    ~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c:15:73: warning: unused parameter ‘b’ [-Wunused-parameter]
warning:    15 | void tree_sitter_rust_external_scanner_deserialize(void *p, const char *b, unsigned n) {}
warning:       |                                                             ~~~~~~~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c:15:85: warning: unused parameter ‘n’ [-Wunused-parameter]
warning:    15 | void tree_sitter_rust_external_scanner_deserialize(void *p, const char *b, unsigned n) {}
warning:       |                                                                            ~~~~~~~~~^
warning: vendor/tree-sitter-rust/src/scanner.c: In function ‘tree_sitter_rust_external_scanner_scan’:
warning: vendor/tree-sitter-rust/src/scanner.c:25:51: warning: unused parameter ‘payload’ [-Wunused-parameter]
warning:    25 | bool tree_sitter_rust_external_scanner_scan(void *payload, TSLexer *lexer,
warning:       |                                             ~~~~~~^~~~~~~
warning: In file included from vendor/tree-sitter-rust/src/parser.c:1:
warning: vendor/tree-sitter-rust/src/parser.c: In function ‘ts_lex_keywords’:
warning: vendor/tree-sitter-rust/src/tree_sitter/parser.h:131:8: warning: variable ‘eof’ set but not used [-Wunused-but-set-variable]
warning:   131 |   bool eof = false;             \
warning:       |        ^~~
warning: vendor/tree-sitter-rust/src/parser.c:4786:3: note: in expansion of macro ‘START_LEXER’
warning:  4786 |   START_LEXER();
warning:       |   ^~~~~~~~~~~
   Compiling kak-tree v0.1.0 (/home/user/kak-tree)
error: linking with `cc` failed: exit status: 1

Not sure if it's kak-tree issue , probably of tree-sitter-python

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.