1- use super :: { SemanticSuggestion , completion_options:: NuMatcher } ;
2- use crate :: completions:: Completer ;
1+ use super :: SemanticSuggestion ;
2+ use crate :: completions:: {
3+ Completer ,
4+ matcher_helper:: { add_semantic_suggestion, suggestion_results} ,
5+ } ;
36use nu_protocol:: {
4- CompletionOptions , Span , SuggestionKind ,
7+ CompletionOptions , NuMatcher , Span , SuggestionKind ,
58 engine:: { Stack , StateWorkingSet } ,
69} ;
710use reedline:: Suggestion ;
@@ -26,22 +29,25 @@ impl Completer for AttributeCompletion {
2629
2730 for ( decl_id, name, desc, ty) in attr_commands {
2831 let name = name. strip_prefix ( b"attr " ) . unwrap_or ( & name) ;
29- matcher. add_semantic_suggestion ( SemanticSuggestion {
30- suggestion : Suggestion {
31- value : String :: from_utf8_lossy ( name) . into_owned ( ) ,
32- description : desc,
33- span : reedline:: Span {
34- start : span. start - offset,
35- end : span. end - offset,
32+ add_semantic_suggestion (
33+ & mut matcher,
34+ SemanticSuggestion {
35+ suggestion : Suggestion {
36+ value : String :: from_utf8_lossy ( name) . into_owned ( ) ,
37+ description : desc,
38+ span : reedline:: Span {
39+ start : span. start - offset,
40+ end : span. end - offset,
41+ } ,
42+ append_whitespace : false ,
43+ ..Default :: default ( )
3644 } ,
37- append_whitespace : false ,
38- ..Default :: default ( )
45+ kind : Some ( SuggestionKind :: Command ( ty, Some ( decl_id) ) ) ,
3946 } ,
40- kind : Some ( SuggestionKind :: Command ( ty, Some ( decl_id) ) ) ,
41- } ) ;
47+ ) ;
4248 }
4349
44- matcher . suggestion_results ( )
50+ suggestion_results ( matcher )
4551 }
4652}
4753
@@ -62,25 +68,28 @@ impl Completer for AttributableCompletion {
6268 . find_decl ( s. as_bytes ( ) )
6369 . expect ( "internal error, builtin declaration not found" ) ;
6470 let cmd = working_set. get_decl ( decl_id) ;
65- matcher. add_semantic_suggestion ( SemanticSuggestion {
66- suggestion : Suggestion {
67- value : cmd. name ( ) . into ( ) ,
68- description : Some ( cmd. description ( ) . into ( ) ) ,
69- span : reedline:: Span {
70- start : span. start - offset,
71- end : span. end - offset,
71+ add_semantic_suggestion (
72+ & mut matcher,
73+ SemanticSuggestion {
74+ suggestion : Suggestion {
75+ value : cmd. name ( ) . into ( ) ,
76+ description : Some ( cmd. description ( ) . into ( ) ) ,
77+ span : reedline:: Span {
78+ start : span. start - offset,
79+ end : span. end - offset,
80+ } ,
81+ append_whitespace : true ,
82+ ..Default :: default ( )
7283 } ,
73- append_whitespace : true ,
74- ..Default :: default ( )
84+ kind : Some ( SuggestionKind :: Command (
85+ cmd. command_type ( ) ,
86+ // for snippet completion in LSP
87+ working_set. find_decl ( s. as_bytes ( ) ) ,
88+ ) ) ,
7589 } ,
76- kind : Some ( SuggestionKind :: Command (
77- cmd. command_type ( ) ,
78- // for snippet completion in LSP
79- working_set. find_decl ( s. as_bytes ( ) ) ,
80- ) ) ,
81- } ) ;
90+ ) ;
8291 }
8392
84- matcher . suggestion_results ( )
93+ suggestion_results ( matcher )
8594 }
8695}
0 commit comments