@@ -6,15 +6,18 @@ import SnippetsStorage from "./snippetsStorage";
6
6
import languages from "./languages" ;
7
7
8
8
function quickPickCustom (
9
- items : vscode . QuickPickItem [ ]
9
+ items : vscode . QuickPickItem [ ] ,
10
+ clearActiveItems = true
10
11
) : Promise < string | vscode . QuickPickItem > {
11
12
return new Promise ( ( resolve ) => {
12
13
const quickPick = vscode . window . createQuickPick ( ) ;
13
14
quickPick . title = 'Enter keywords for snippet search (e.g. "read file")' ;
14
15
quickPick . items = items ;
15
16
16
17
quickPick . onDidChangeValue ( ( ) => {
17
- quickPick . activeItems = [ ] ;
18
+ if ( clearActiveItems ) {
19
+ quickPick . activeItems = [ ] ;
20
+ }
18
21
} ) ;
19
22
20
23
quickPick . onDidAccept ( ( ) => {
@@ -38,7 +41,8 @@ export interface QueryResult {
38
41
39
42
export async function query (
40
43
language : string ,
41
- snippetsStorage : SnippetsStorage
44
+ snippetsStorage : SnippetsStorage ,
45
+ suggestOnlySaved = false
42
46
) : Promise < QueryResult > {
43
47
const suggestions = new Set (
44
48
cache . state . get < string [ ] > ( `snippet_suggestions_${ language } ` , [ ] )
@@ -58,15 +62,20 @@ export async function query(
58
62
}
59
63
}
60
64
61
- for ( const suggestion of suggestions ) {
62
- const tempQuickItem : vscode . QuickPickItem = {
63
- label : suggestion ,
64
- description : "" ,
65
- } ;
66
- suggestionsQuickItems . push ( tempQuickItem ) ;
65
+ if ( ! suggestOnlySaved ) {
66
+ for ( const suggestion of suggestions ) {
67
+ const tempQuickItem : vscode . QuickPickItem = {
68
+ label : suggestion ,
69
+ description : "" ,
70
+ } ;
71
+ suggestionsQuickItems . push ( tempQuickItem ) ;
72
+ }
67
73
}
68
74
69
- const selectedItem = await quickPickCustom ( suggestionsQuickItems ) ;
75
+ const selectedItem = await quickPickCustom (
76
+ suggestionsQuickItems ,
77
+ ! suggestOnlySaved
78
+ ) ;
70
79
const input =
71
80
typeof selectedItem === "string" ? selectedItem : selectedItem . label ;
72
81
const savedSnippetContent =
0 commit comments