add an outline jumper for Rust

main
Brian Hicks 2021-06-23 10:29:09 -05:00
parent 99e4a38cdd
commit 0ed32ee920
3 changed files with 63 additions and 0 deletions

View File

@ -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 %{

View File

@ -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}
}

View File

@ -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)
}