@@ -28,6 +28,9 @@ function createRequest({
28
28
}
29
29
30
30
describe ( "AutoCompleteAdapter" , ( ) => {
31
+ let server : ActiveServer
32
+ let autoCompleteAdapter : AutoCompleteAdapter
33
+
31
34
function createActiveServerSpy ( ) : ActiveServer {
32
35
return {
33
36
capabilities : { completionProvider : { } } ,
@@ -38,6 +41,27 @@ describe("AutoCompleteAdapter", () => {
38
41
}
39
42
}
40
43
44
+ type getSuggestionParams = Parameters < typeof autoCompleteAdapter . getSuggestions >
45
+
46
+ /** Function that stubs `server.connection.completion` and returns the `autoCompleteAdapter.getSuggestions(...)` */
47
+ async function getSuggestionsMock (
48
+ items : CompletionItem [ ] ,
49
+ request : getSuggestionParams [ 1 ] ,
50
+ onDidConvertCompletionItem ?: getSuggestionParams [ 2 ] ,
51
+ minimumWordLength ?: getSuggestionParams [ 3 ] ,
52
+ ) : Promise < ac . AnySuggestion [ ] > {
53
+ const resultsSandBox = sinon . createSandbox ( )
54
+ resultsSandBox . stub ( server . connection , "completion" ) . resolves ( items )
55
+ const results = autoCompleteAdapter . getSuggestions (
56
+ server ,
57
+ request ,
58
+ onDidConvertCompletionItem ,
59
+ minimumWordLength ,
60
+ )
61
+ resultsSandBox . restore ( )
62
+ return results
63
+ }
64
+
41
65
const completionItems : CompletionItem [ ] = [
42
66
{
43
67
label : "thisHasFiltertext" ,
@@ -73,45 +97,21 @@ describe("AutoCompleteAdapter", () => {
73
97
const request = createRequest ( { prefix : "lab" } )
74
98
75
99
describe ( "getSuggestions" , ( ) => {
76
- let server : ActiveServer
77
- let autoCompleteAdapter : AutoCompleteAdapter
78
-
79
- type getSuggestionParams = Parameters < typeof autoCompleteAdapter . getSuggestions >
80
-
81
- /** Function that stubs `server.connection.completion` and returns the `autoCompleteAdapter.getSuggestions(...)` */
82
- async function getSuggestionsMock (
83
- items : CompletionItem [ ] ,
84
- requestParams : Parameters < typeof createRequest > [ 0 ] ,
85
- onDidConvertCompletionItem ?: getSuggestionParams [ 2 ] ,
86
- minimumWordLength ?: getSuggestionParams [ 3 ] ,
87
- ) : Promise < ac . AnySuggestion [ ] > {
88
- const resultsSandBox = sinon . createSandbox ( )
89
- resultsSandBox . stub ( server . connection , "completion" ) . resolves ( items )
90
- const results = autoCompleteAdapter . getSuggestions (
91
- server ,
92
- createRequest ( requestParams ) ,
93
- onDidConvertCompletionItem ,
94
- minimumWordLength ,
95
- )
96
- resultsSandBox . restore ( )
97
- return results
98
- }
99
-
100
100
beforeEach ( ( ) => {
101
101
server = createActiveServerSpy ( )
102
102
autoCompleteAdapter = new AutoCompleteAdapter ( )
103
103
} )
104
104
105
105
it ( "gets AutoComplete suggestions via LSP given an AutoCompleteRequest" , async ( ) => {
106
- const results = await getSuggestionsMock ( completionItems , { prefix : "" } )
106
+ const results = await getSuggestionsMock ( completionItems , createRequest ( { prefix : "" } ) )
107
107
expect ( results . length ) . equals ( completionItems . length )
108
108
} )
109
109
110
110
it ( "provides a filtered selection based on the filterKey" , async ( ) => {
111
- const results = await getSuggestionsMock ( completionItems , { prefix : "lab" } )
112
- expect ( results . length ) . equals ( 2 )
113
- expect ( results . some ( ( r ) => r . displayText === "thisHasFiltertext" ) ) . to . be . true
114
- expect ( results . some ( ( r ) => r . displayText === "label3" ) ) . to . be . true
111
+ const resultsLab = await getSuggestionsMock ( completionItems , createRequest ( { prefix : "lab" } ) )
112
+ expect ( resultsLab . length ) . equals ( 2 )
113
+ expect ( resultsLab . some ( ( r ) => r . displayText === "thisHasFiltertext" ) ) . to . be . true
114
+ expect ( resultsLab . some ( ( r ) => r . displayText === "label3" ) ) . to . be . true
115
115
} )
116
116
117
117
it ( "uses the sortText property to arrange completions when there is no prefix" , async ( ) => {
@@ -120,7 +120,7 @@ describe("AutoCompleteAdapter", () => {
120
120
{ label : "b" } ,
121
121
{ label : "c" , sortText : "a" } ,
122
122
]
123
- const results = await getSuggestionsMock ( sortedItems , { prefix : "" } )
123
+ const results = await getSuggestionsMock ( sortedItems , createRequest ( { prefix : "" } ) )
124
124
125
125
expect ( results . length ) . equals ( sortedItems . length )
126
126
expect ( results [ 0 ] . displayText ) . equals ( "c" )
@@ -129,7 +129,7 @@ describe("AutoCompleteAdapter", () => {
129
129
} )
130
130
131
131
it ( "uses the filterText property to arrange completions when there is a prefix" , async ( ) => {
132
- const results = await getSuggestionsMock ( completionItems , { prefix : "lab" } )
132
+ const results = await getSuggestionsMock ( completionItems , createRequest ( { prefix : "lab" } ) )
133
133
expect ( results . length ) . equals ( 2 )
134
134
expect ( results [ 0 ] . displayText ) . equals ( "label3" ) // shorter than 'labrador', so expected to be first
135
135
expect ( results [ 1 ] . displayText ) . equals ( "thisHasFiltertext" )
@@ -225,9 +225,6 @@ describe("AutoCompleteAdapter", () => {
225
225
} ,
226
226
]
227
227
228
- let server : ActiveServer
229
- let autoCompleteAdapter : AutoCompleteAdapter
230
-
231
228
beforeEach ( ( ) => {
232
229
server = createActiveServerSpy ( )
233
230
autoCompleteAdapter = new AutoCompleteAdapter ( )
0 commit comments