Compare commits
No commits in common. "6e6ad7a82b0dc4142f4db2c06a0a80f1c1ca151a" and "05319779a3158bad61fc5a5c212847e3c0ac65ff" have entirely different histories.
6e6ad7a82b
...
05319779a3
|
@ -1,8 +0,0 @@
|
||||||
[filetype.rust]
|
|
||||||
group.identifier = ["identifier", "scoped_identifier"]
|
|
||||||
group.function = ["function_item"]
|
|
||||||
group.declaration = ["function_item", "struct_item", "enum_item"]
|
|
||||||
group.call = ["macro_invocation", "call_expression"]
|
|
||||||
group.arguments = ["arguments", "token_tree"]
|
|
||||||
group.statement = ["expression_statement", "let_declaration"]
|
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
# Path to the kak-tree executable.
|
# Path to the kak-tree executable.
|
||||||
|
# To load config: set-option global tree_cmd "kak-tree --config /path/to/kak-tree.toml"
|
||||||
# To enable debug logging: set-option global tree_cmd "kak-tree -vvv"
|
# To enable debug logging: set-option global tree_cmd "kak-tree -vvv"
|
||||||
declare-option str tree_cmd "kak-tree"
|
declare-option str tree_cmd "kak-tree"
|
||||||
|
|
||||||
# Path to the config file. Defaults to the built-in file default_config.toml
|
|
||||||
declare-option str tree_config %sh{ printf "$(dirname ${kak_source})/default_config.toml" }
|
|
||||||
|
|
||||||
# Path to the log file.
|
# Path to the log file.
|
||||||
declare-option str tree_log "/tmp/kak-tree.log"
|
declare-option str tree_log "/tmp/kak-tree.log"
|
||||||
|
|
||||||
|
@ -35,7 +33,7 @@ content = """
|
||||||
[op]
|
[op]
|
||||||
type = "%s"
|
type = "%s"
|
||||||
%s
|
%s
|
||||||
' "${kak_opt_filetype}" "${kak_selections_desc}" "${tree_draft}" $1 "$2" | ${kak_opt_tree_cmd} --config "${kak_opt_tree_config}" 2>${kak_opt_tree_log}
|
' "${kak_opt_filetype}" "${kak_selections_desc}" "${tree_draft}" $1 "$2" | ${kak_opt_tree_cmd} 2>${kak_opt_tree_log}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,8 @@ impl Default for Config {
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn load<P: AsRef<std::path::Path>>(path: P) -> Option<Self> {
|
pub fn load<P: AsRef<std::path::Path>>(path: P) -> Option<Self> {
|
||||||
let config = std::fs::read_to_string(&path).map_err(|e| { eprintln!("Could not open config {}", path.as_ref().display()); e}).ok()?;
|
let config = std::fs::read_to_string(path).ok()?;
|
||||||
let mut config: Config = toml::from_str(&config).map_err(|e| { eprintln!("Could not read config: {e}"); e}).ok()?;
|
let mut config: Config = toml::from_str(&config).ok()?;
|
||||||
if config.filetype.get("default").is_none() {
|
if config.filetype.get("default").is_none() {
|
||||||
config
|
config
|
||||||
.filetype
|
.filetype
|
||||||
|
|
|
@ -168,8 +168,9 @@ fn handle_request(config: &Config, request: &Request) -> String {
|
||||||
Some(kind) => {
|
Some(kind) => {
|
||||||
let kinds = filetype_config.resolve_alias(kind);
|
let kinds = filetype_config.resolve_alias(kind);
|
||||||
for range in &ranges {
|
for range in &ranges {
|
||||||
let node = tree::shrink_to_range(tree.root_node(), range);
|
for node in tree::nodes_in_range(tree.root_node(), range) {
|
||||||
select_nodes(&node, &kinds, &mut new_ranges);
|
select_nodes(&node, &kinds, &mut new_ranges);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
|
41
src/tree.rs
41
src/tree.rs
|
@ -22,6 +22,47 @@ pub fn shrink_to_range<'a>(root_node: Node<'a>, range: &Range) -> Node<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn nodes_in_range<'a>(root_node: Node<'a>, range: &Range) -> Vec<Node<'a>> {
|
||||||
|
let mut nodes = Vec::new();
|
||||||
|
let node = shrink_to_range(root_node, range);
|
||||||
|
if node.range().start_byte >= range.start_byte && range.end_byte >= node.range().end_byte {
|
||||||
|
nodes.push(node);
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
let mut cursor = node.walk();
|
||||||
|
for child in node.children(&mut cursor) {
|
||||||
|
if child.range().start_byte <= range.start_byte && range.end_byte >= child.range().end_byte
|
||||||
|
{
|
||||||
|
nodes.extend(nodes_in_range(
|
||||||
|
child,
|
||||||
|
&Range {
|
||||||
|
start_byte: range.start_byte,
|
||||||
|
start_point: range.start_point,
|
||||||
|
end_byte: child.range().end_byte,
|
||||||
|
end_point: child.range().end_point,
|
||||||
|
},
|
||||||
|
));
|
||||||
|
} else if child.range().start_byte >= range.start_byte
|
||||||
|
&& range.end_byte <= child.range().end_byte
|
||||||
|
{
|
||||||
|
nodes.extend(nodes_in_range(
|
||||||
|
child,
|
||||||
|
&Range {
|
||||||
|
start_byte: child.range().start_byte,
|
||||||
|
start_point: child.range().start_point,
|
||||||
|
end_byte: range.end_byte,
|
||||||
|
end_point: range.end_point,
|
||||||
|
},
|
||||||
|
));
|
||||||
|
} else if child.range().start_byte >= range.start_byte
|
||||||
|
&& range.end_byte >= child.range().end_byte
|
||||||
|
{
|
||||||
|
nodes.push(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nodes
|
||||||
|
}
|
||||||
|
|
||||||
fn highest_node_of_same_range<'a>(current_node: Node<'a>) -> Node<'a> {
|
fn highest_node_of_same_range<'a>(current_node: Node<'a>) -> Node<'a> {
|
||||||
let start_byte = current_node.start_byte();
|
let start_byte = current_node.start_byte();
|
||||||
let end_byte = current_node.end_byte();
|
let end_byte = current_node.end_byte();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user