Skip to content

Commit

Permalink
add an outline jumper for Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Jun 23, 2021
1 parent 99e4a38 commit 0ed32ee
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dotfiles/kakoune.nix
Expand Up @@ -297,6 +297,8 @@ in {
echo 'hook buffer BufWritePre .* format'
fi
}
map buffer normal <a-minus> ': outline-jump-rust<ret>'
}
hook global WinSetOption filetype=ruby %{
Expand Down
24 changes: 24 additions & 0 deletions pkgs/kak-tree-grepper/rc/kak-tree-grepper.kak
Expand Up @@ -74,3 +74,27 @@ define-command -override -docstring "jump somewhere in an Haskell file's definit
printf "evaluate-commands -client %s edit %s\n" "$CLIENT" "$EDIT_LOCATION" | indiekak -p "$SESSION"
} -- %opt{tree_grepper_path} %opt{tree_grepper_fzf_path} %val{bufname} %arg{1} %val{client} %val{session}
}

define-command -override -docstring "jump somewhere in an Rust file's definition outline" -params 0..1 outline-jump-rust %{
tmux-terminal-horizontal sh -c %{
set -euo pipefail

# what tools do we have available?
TREE_GREPPER=${1:-tree-grepper}
FZF=${2:-fzf}

# what do we care about?
FILE=$3
FZF_QUERY=$4

# where do we return results?
CLIENT=$5
SESSION=$6

# do the magic!
QUERY="(use_declaration)@use (function_item _ (_) @function) (struct_item (type_identifier) @out) (field_declaration)@field (parameter) (let_declaration)@let (enum_item (type_identifier)@enum) (enum_variant)"

EDIT_LOCATION="$("$TREE_GREPPER" --language rust "$QUERY" "$FILE" | fzf --with-nth 4,5 --nth 2,1 --delimiter=: --query "$FZF_QUERY" --select-1 | cut -d : -f 1-3 | tr : ' ')"
printf "evaluate-commands -client %s edit %s\n" "$CLIENT" "$EDIT_LOCATION" | indiekak -p "$SESSION"
} -- %opt{tree_grepper_path} %opt{tree_grepper_fzf_path} %val{bufname} %arg{1} %val{client} %val{session}
}
37 changes: 37 additions & 0 deletions sample-projects/rust/src/main.rs
@@ -0,0 +1,37 @@
use std::fs;
use std::path::PathBuf;

fn main() {
println!("Hello, World!")
}

struct Foo {
fieldName: String,
count: u8,
}

impl Foo {
pub fn new(bar: String) -> Foo {
Foo {
fieldName: bar,
count: 0
}
}

pub fn boop(&mut self) {
let to_add = 1;
self.count += to_add
}
}

impl Drop for Foo {
fn drop(&mut self) {
println!("Dropping foo!")
}
}

enum MyOption<T> {
TheresNothingHereMan,
WhoahTheresAThing(T)
}

0 comments on commit 0ed32ee

Please sign in to comment.