@@ -10,35 +10,46 @@ import { disposeAll } from '../utils/dispose';
1010
1111const testDocumentUri = vscode . Uri . parse ( 'untitled:test.ts' ) ;
1212
13- const configOverrides : { readonly [ key : string ] : any } = Object . freeze ( {
14- 'editor.suggestSelection' : 'first' ,
15- 'typescript.suggest.completeFunctionCalls' : false ,
16- } ) ;
13+ type VsCodeConfiguration = { [ key : string ] : any } ;
14+
15+ async function updateConfig ( newConfig : VsCodeConfiguration ) : Promise < VsCodeConfiguration > {
16+ const oldConfig : VsCodeConfiguration = { } ;
17+ const config = vscode . workspace . getConfiguration ( undefined , testDocumentUri ) ;
18+ for ( const configKey of Object . keys ( newConfig ) ) {
19+ oldConfig [ configKey ] = config . get ( configKey ) ;
20+ await new Promise ( ( resolve , reject ) =>
21+ config . update ( configKey , newConfig [ configKey ] , vscode . ConfigurationTarget . Global )
22+ . then ( ( ) => resolve ( ) , reject ) ) ;
23+ }
24+ return oldConfig ;
25+ }
26+
27+ namespace Config {
28+ export const suggestSelection = 'editor.suggestSelection' ;
29+ export const completeFunctionCalls = 'typescript.suggest.completeFunctionCalls' ;
30+ }
1731
1832suite ( 'TypeScript Completions' , ( ) => {
33+ const configDefaults : VsCodeConfiguration = Object . freeze ( {
34+ [ Config . suggestSelection ] : 'first' ,
35+ [ Config . completeFunctionCalls ] : false ,
36+ } ) ;
37+
1938 const _disposables : vscode . Disposable [ ] = [ ] ;
2039 let oldConfig : { [ key : string ] : any } = { } ;
2140
2241 setup ( async ( ) => {
2342 await wait ( 100 ) ;
2443
25- // save off config and update overrides
26- oldConfig = { } ;
27- const config = vscode . workspace . getConfiguration ( undefined , testDocumentUri ) ;
28- for ( const configKey of Object . keys ( configOverrides ) ) {
29- oldConfig [ configKey ] = config . get ( configKey ) ;
30- await new Promise ( ( resolve , reject ) => config . update ( configKey , configOverrides [ configKey ] , vscode . ConfigurationTarget . Global ) . then ( ( ) => resolve ( ) , reject ) ) ;
31- }
44+ // Save off config and apply defaults
45+ oldConfig = await updateConfig ( configDefaults ) ;
3246 } ) ;
3347
3448 teardown ( async ( ) => {
3549 disposeAll ( _disposables ) ;
3650
3751 // Restore config
38- const config = vscode . workspace . getConfiguration ( undefined , testDocumentUri ) ;
39- for ( const configKey of Object . keys ( oldConfig ) ) {
40- await new Promise ( ( resolve , reject ) => config . update ( configKey , oldConfig [ configKey ] , vscode . ConfigurationTarget . Global ) . then ( ( ) => resolve ( ) , reject ) ) ;
41- }
52+ await updateConfig ( oldConfig ) ;
4253
4354 return vscode . commands . executeCommand ( 'workbench.action.closeAllEditors' ) ;
4455 } ) ;
@@ -176,6 +187,83 @@ suite('TypeScript Completions', () => {
176187 `abc`
177188 ) ) ;
178189 } ) ;
190+
191+ test ( 'completeFunctionCalls should complete function parameters when at end of word' , async ( ) => {
192+ await updateConfig ( {
193+ [ Config . completeFunctionCalls ] : true ,
194+ } ) ;
195+
196+ // Complete with-in word
197+ await createTestEditor ( testDocumentUri ,
198+ `function abcdef(x, y, z) { }` ,
199+ `abcdef$0`
200+ ) ;
201+
202+ const document = await acceptFirstSuggestion ( testDocumentUri , _disposables ) ;
203+ assert . strictEqual (
204+ document . getText ( ) ,
205+ joinLines (
206+ `function abcdef(x, y, z) { }` ,
207+ `abcdef(x, y, z)`
208+ ) ) ;
209+ } ) ;
210+
211+ test . skip ( 'completeFunctionCalls should complete function parameters when within word' , async ( ) => {
212+ await updateConfig ( {
213+ [ Config . completeFunctionCalls ] : true ,
214+ } ) ;
215+
216+ await createTestEditor ( testDocumentUri ,
217+ `function abcdef(x, y, z) { }` ,
218+ `abcd$0ef`
219+ ) ;
220+
221+ const document = await acceptFirstSuggestion ( testDocumentUri , _disposables ) ;
222+ assert . strictEqual (
223+ document . getText ( ) ,
224+ joinLines (
225+ `function abcdef(x, y, z) { }` ,
226+ `abcdef(x, y, z)`
227+ ) ) ;
228+ } ) ;
229+
230+ test ( 'completeFunctionCalls should not complete function parameters at end of word if we are already in something that looks like a function call, #18131' , async ( ) => {
231+ await updateConfig ( {
232+ [ Config . completeFunctionCalls ] : true ,
233+ } ) ;
234+
235+ await createTestEditor ( testDocumentUri ,
236+ `function abcdef(x, y, z) { }` ,
237+ `abcdef$0(1, 2, 3)`
238+ ) ;
239+
240+ const document = await acceptFirstSuggestion ( testDocumentUri , _disposables ) ;
241+ assert . strictEqual (
242+ document . getText ( ) ,
243+ joinLines (
244+ `function abcdef(x, y, z) { }` ,
245+ `abcdef(1, 2, 3)`
246+ ) ) ;
247+ } ) ;
248+
249+ test . skip ( 'completeFunctionCalls should not complete function parameters within word if we are already in something that looks like a function call, #18131' , async ( ) => {
250+ await updateConfig ( {
251+ [ Config . completeFunctionCalls ] : true ,
252+ } ) ;
253+
254+ await createTestEditor ( testDocumentUri ,
255+ `function abcdef(x, y, z) { }` ,
256+ `abcd$0ef(1, 2, 3)`
257+ ) ;
258+
259+ const document = await acceptFirstSuggestion ( testDocumentUri , _disposables ) ;
260+ assert . strictEqual (
261+ document . getText ( ) ,
262+ joinLines (
263+ `function abcdef(x, y, z) { }` ,
264+ `abcdef(1, 2, 3)`
265+ ) ) ;
266+ } ) ;
179267} ) ;
180268
181269const joinLines = ( ...args : string [ ] ) => args . join ( '\n' ) ;
@@ -187,6 +275,9 @@ async function acceptFirstSuggestion(uri: vscode.Uri, _disposables: vscode.Dispo
187275 const didSuggest = onDidSuggest ( _disposables ) ;
188276 await vscode . commands . executeCommand ( 'editor.action.triggerSuggest' ) ;
189277 await didSuggest ;
278+ // TODO: depends on reverting fix for https://github.com/Microsoft/vscode/issues/64257
279+ // Make sure we have time to resolve the suggestion because `acceptSelectedSuggestion` doesn't
280+ await wait ( 40 ) ;
190281 await vscode . commands . executeCommand ( 'acceptSelectedSuggestion' ) ;
191282 return await didChangeDocument ;
192283}
0 commit comments