File tree Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -3076,7 +3076,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
30763076 aliases : & [ ] ,
30773077 doc : "Set the diff source for the file. If no argument is provided, show the current source." ,
30783078 fun : diff_source,
3079- signature : CommandSignature :: none ( ) ,
3079+ signature : CommandSignature :: all ( completers :: diff_source ) ,
30803080 } ,
30813081 TypableCommand {
30823082 name : "clear-register" ,
Original file line number Diff line number Diff line change @@ -259,6 +259,7 @@ pub mod completers {
259259 use crate :: ui:: prompt:: Completion ;
260260 use helix_core:: fuzzy:: fuzzy_match;
261261 use helix_core:: syntax:: LanguageServerFeature ;
262+ use helix_vcs:: DiffSource ;
262263 use helix_view:: document:: SCRATCH_BUFFER_NAME ;
263264 use helix_view:: theme;
264265 use helix_view:: { editor:: Config , Editor } ;
@@ -399,6 +400,15 @@ pub mod completers {
399400 } )
400401 }
401402
403+ pub fn diff_source ( _editor : & Editor , input : & str ) -> Vec < Completion > {
404+ let iter = DiffSource :: all_values ( ) ;
405+
406+ fuzzy_match ( input, iter, false )
407+ . into_iter ( )
408+ . map ( |( & name, _) | ( ( 0 ..) , name. into ( ) ) )
409+ . collect ( )
410+ }
411+
402412 #[ derive( Copy , Clone , PartialEq , Eq ) ]
403413 enum FileMatch {
404414 /// Entry should be ignored
Original file line number Diff line number Diff line change @@ -125,6 +125,25 @@ impl DiffSource {
125125 }
126126 } ) ;
127127 }
128+
129+ /// Used to offer completion options for the `diff-source` command
130+ pub fn all_values ( ) -> & ' static [ & ' static str ] {
131+ // To force a miscompilation and remember to add the value to the list
132+ match Self :: None {
133+ Self :: None => ( ) ,
134+ #[ cfg( feature = "git" ) ]
135+ Self :: File => ( ) ,
136+ Self :: Git => ( ) ,
137+ }
138+
139+ // Keep it sorted alphabetically
140+ & [
141+ "file" ,
142+ #[ cfg( feature = "git" ) ]
143+ "git" ,
144+ "none" ,
145+ ]
146+ }
128147}
129148
130149impl FromStr for DiffSource {
@@ -136,7 +155,7 @@ impl FromStr for DiffSource {
136155 "file" => Ok ( Self :: File ) ,
137156 #[ cfg( feature = "git" ) ]
138157 "git" => Ok ( Self :: Git ) ,
139- s => bail ! ( "invalid diff source '{s}', pick one of 'none', 'file' or 'git' " ) ,
158+ s => bail ! ( "invalid diff source '{s}'" ) ,
140159 }
141160 }
142161}
@@ -175,4 +194,12 @@ mod tests {
175194 #[ cfg( feature = "git" ) ]
176195 assert_eq ! ( DiffSource :: Git . to_string( ) , "git" ) ;
177196 }
197+
198+ #[ test]
199+ fn test_diff_source_all_values ( ) {
200+ let all = DiffSource :: all_values ( ) ;
201+ let mut all_sorted = all. to_vec ( ) ;
202+ all_sorted. sort_unstable ( ) ;
203+ assert_eq ! ( all, all_sorted) ;
204+ }
178205}
You can’t perform that action at this time.
0 commit comments