Debian Codegraph @

contrib/completion/hx.elv

raw
1 # You can move it here ~/.config/elvish/lib/hx.elv
2 # Or add `eval (slurp < ~/$REPOS/helix/contrib/completion/hx.elv)`
3 # Be sure to replace `$REPOS` with something that makes sense for you!
4
5 ### Renders a pretty completion candidate
6 var candidate = { | _stem _desc |
7 edit:complex-candidate $_stem &display=(styled $_stem bold)(styled " "$_desc dim)
8 }
9
10 ### These commands will invalidate further input (i.e. not react to them)
11 var skips = [ "--tutor" "--help" "--version" "-V" "--health" ]
12
13 ### Grammar commands
14 var grammar = [ "--grammar" "-g" ]
15
16 ### Config commands
17 var config = [ "--config" "-c" ]
18
19 ### Set an arg-completer for the `hx` binary
20 set edit:completion:arg-completer[hx] = {|@args|
21 var n = (count $args)
22 if (>= $n 3) {
23 # Stop completions if passed arg will take precedence
24 # and invalidate further input
25 if (has-value $skips $args[-2]) {
26 return
27 }
28 # If the previous arg == --grammar, then only suggest:
29 if (has-value $grammar $args[-2]) {
30 $candidate "fetch" "Fetch the tree-sitter grammars"
31 $candidate "build" "Build the tree-sitter grammars"
32 return
33 }
34 # When we have --config, we need a file
35 if (has-values $config $args[-2]) {
36 edit:complete-filename $args[-1] | each { |v| put $v[stem] }
37 return
38 }
39 # When we have --log, we need a file
40 if (has-values "log" $args[-2]) {
41 edit:complete-filename $args[-1] | each { |v| put $v[stem] }
42 return
43 }
44 }
45 edit:complete-filename $args[-1] | each { |v| put $v[stem]}
46 $candidate "--help" "(Prints help information)"
47 $candidate "--strict" "(Bail on error for commands that can fail)"
48 $candidate "--version" "(Prints version information)"
49 $candidate "--tutor" "(Loads the tutorial)"
50 $candidate "--health" "(Checks for errors in editor setup)"
51 $candidate "--grammar" "(Fetch or build the tree-sitter grammars)"
52 $candidate "--vsplit" "(Splits all given files vertically)"
53 $candidate "--hsplit" "(Splits all given files horizontally)"
54 $candidate "--config" "(Specifies a file to use for configuration)"
55 $candidate "--log" "(Specifies a file to write log data into)"
56 }