@@ -9,7 +9,7 @@ import { CompletionItemKind, CompletionList, DiagnosticSeverity, InsertTextForma
9
9
import { Command , Diagnostic , Hover , Location , SignatureHelp , SymbolInformation , SymbolKind } from 'vscode-languageserver-types' ;
10
10
import { LanguageClient , RemoteLanguageClient } from '../lang-handler' ;
11
11
import { DependencyReference , PackageInformation , ReferenceInformation , TextDocumentContentParams , WorkspaceFilesParams } from '../request-type' ;
12
- import { ClientCapabilities , SymbolLocationInformation } from '../request-type' ;
12
+ import { ClientCapabilities , CompletionItem , SymbolLocationInformation } from '../request-type' ;
13
13
import { TypeScriptService , TypeScriptServiceFactory } from '../typescript-service' ;
14
14
import { observableFromIterable , toUnixPath , uri2path } from '../util' ;
15
15
@@ -2154,7 +2154,62 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
2154
2154
2155
2155
afterEach ( shutdownService ) ;
2156
2156
2157
- it ( 'should produce completions with snippets if supported' , async function ( this : TestContext & ITestCallbackContext ) {
2157
+ it ( 'should produce completions' , async function ( this : TestContext & ITestCallbackContext ) {
2158
+ const result : CompletionList = await this . service . textDocumentCompletion ( {
2159
+ textDocument : {
2160
+ uri : rootUri + 'a.ts'
2161
+ } ,
2162
+ position : {
2163
+ line : 11 ,
2164
+ character : 2
2165
+ }
2166
+ } ) . reduce < Operation , CompletionList > ( applyReducer , null as any ) . toPromise ( ) ;
2167
+ assert . equal ( result . isIncomplete , false ) ;
2168
+ assert . sameDeepMembers ( result . items , [
2169
+ {
2170
+ label : 'bar' ,
2171
+ kind : CompletionItemKind . Method ,
2172
+ sortText : '0' ,
2173
+ data : {
2174
+ entryName : 'bar' ,
2175
+ offset : 210 ,
2176
+ uri : rootUri + 'a.ts'
2177
+ }
2178
+ } ,
2179
+ {
2180
+ label : 'baz' ,
2181
+ kind : CompletionItemKind . Method ,
2182
+ sortText : '0' ,
2183
+ data : {
2184
+ entryName : 'baz' ,
2185
+ offset : 210 ,
2186
+ uri : rootUri + 'a.ts'
2187
+ }
2188
+ } ,
2189
+ {
2190
+ label : 'foo' ,
2191
+ kind : CompletionItemKind . Method ,
2192
+ sortText : '0' ,
2193
+ data : {
2194
+ entryName : 'foo' ,
2195
+ offset : 210 ,
2196
+ uri : rootUri + 'a.ts'
2197
+ }
2198
+ } ,
2199
+ {
2200
+ label : 'qux' ,
2201
+ kind : CompletionItemKind . Property ,
2202
+ sortText : '0' ,
2203
+ data : {
2204
+ entryName : 'qux' ,
2205
+ offset : 210 ,
2206
+ uri : rootUri + 'a.ts'
2207
+ }
2208
+ }
2209
+ ] ) ;
2210
+ } ) ;
2211
+
2212
+ it ( 'should resolve completions with snippets' , async function ( this : TestContext & ITestCallbackContext ) {
2158
2213
const result : CompletionList = await this . service . textDocumentCompletion ( {
2159
2214
textDocument : {
2160
2215
uri : rootUri + 'a.ts'
@@ -2169,15 +2224,25 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
2169
2224
// * the end of the snippet. Placeholders with equal identifiers are linked,
2170
2225
// * that is typing in one will update others too.
2171
2226
assert . equal ( result . isIncomplete , false ) ;
2172
- assert . sameDeepMembers ( result . items , [
2227
+
2228
+ const resolvedItems = await Observable . from ( result . items )
2229
+ . mergeMap ( item => this . service
2230
+ . completionItemResolve ( item )
2231
+ . reduce < Operation , CompletionItem > ( applyReducer , null as any )
2232
+ )
2233
+ . toArray ( )
2234
+ . toPromise ( ) ;
2235
+
2236
+ assert . sameDeepMembers ( resolvedItems , [
2173
2237
{
2174
2238
label : 'bar' ,
2175
2239
kind : CompletionItemKind . Method ,
2176
2240
documentation : 'bar doc' ,
2177
2241
sortText : '0' ,
2178
2242
insertTextFormat : InsertTextFormat . Snippet ,
2179
2243
insertText : 'bar(${1:num})' ,
2180
- detail : '(method) A.bar(num: number): number'
2244
+ detail : '(method) A.bar(num: number): number' ,
2245
+ data : undefined
2181
2246
} ,
2182
2247
{
2183
2248
label : 'baz' ,
@@ -2186,7 +2251,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
2186
2251
sortText : '0' ,
2187
2252
insertTextFormat : InsertTextFormat . Snippet ,
2188
2253
insertText : 'baz(${1:num})' ,
2189
- detail : '(method) A.baz(num: number): string'
2254
+ detail : '(method) A.baz(num: number): string' ,
2255
+ data : undefined
2190
2256
} ,
2191
2257
{
2192
2258
label : 'foo' ,
@@ -2195,7 +2261,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
2195
2261
sortText : '0' ,
2196
2262
insertTextFormat : InsertTextFormat . Snippet ,
2197
2263
insertText : 'foo()' ,
2198
- detail : '(method) A.foo(): void'
2264
+ detail : '(method) A.foo(): void' ,
2265
+ data : undefined
2199
2266
} ,
2200
2267
{
2201
2268
label : 'qux' ,
@@ -2204,9 +2271,11 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
2204
2271
sortText : '0' ,
2205
2272
insertTextFormat : InsertTextFormat . Snippet ,
2206
2273
insertText : 'qux' ,
2207
- detail : '(property) A.qux: number'
2274
+ detail : '(property) A.qux: number' ,
2275
+ data : undefined
2208
2276
}
2209
2277
] ) ;
2278
+
2210
2279
} ) ;
2211
2280
} ) ;
2212
2281
@@ -2258,14 +2327,77 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
2258
2327
} ) . reduce < Operation , CompletionList > ( applyReducer , null as any ) . toPromise ( ) ;
2259
2328
assert . equal ( result . isIncomplete , false ) ;
2260
2329
assert . sameDeepMembers ( result . items , [
2330
+ {
2331
+ data : {
2332
+ entryName : 'bar' ,
2333
+ offset : 188 ,
2334
+ uri : rootUri + 'a.ts'
2335
+ } ,
2336
+ label : 'bar' ,
2337
+ kind : CompletionItemKind . Method ,
2338
+ sortText : '0'
2339
+ } ,
2340
+ {
2341
+ data : {
2342
+ entryName : 'baz' ,
2343
+ offset : 188 ,
2344
+ uri : rootUri + 'a.ts'
2345
+ } ,
2346
+ label : 'baz' ,
2347
+ kind : CompletionItemKind . Method ,
2348
+ sortText : '0'
2349
+ } ,
2350
+ {
2351
+ data : {
2352
+ entryName : 'foo' ,
2353
+ offset : 188 ,
2354
+ uri : rootUri + 'a.ts'
2355
+ } ,
2356
+ label : 'foo' ,
2357
+ kind : CompletionItemKind . Method ,
2358
+ sortText : '0'
2359
+ } ,
2360
+ {
2361
+ data : {
2362
+ entryName : 'qux' ,
2363
+ offset : 188 ,
2364
+ uri : rootUri + 'a.ts'
2365
+ } ,
2366
+ label : 'qux' ,
2367
+ kind : CompletionItemKind . Property ,
2368
+ sortText : '0'
2369
+ }
2370
+ ] ) ;
2371
+ } ) ;
2372
+
2373
+ it ( 'resolves completions in the same file' , async function ( this : TestContext & ITestCallbackContext ) {
2374
+ const result : CompletionList = await this . service . textDocumentCompletion ( {
2375
+ textDocument : {
2376
+ uri : rootUri + 'a.ts'
2377
+ } ,
2378
+ position : {
2379
+ line : 11 ,
2380
+ character : 2
2381
+ }
2382
+ } ) . reduce < Operation , CompletionList > ( applyReducer , null as any ) . toPromise ( ) ;
2383
+ assert . equal ( result . isIncomplete , false ) ;
2384
+
2385
+ const resolveItem = ( item : CompletionItem ) => this . service
2386
+ . completionItemResolve ( item )
2387
+ . reduce < Operation , CompletionItem > ( applyReducer , null as any ) . toPromise ( ) ;
2388
+
2389
+ const resolvedItems = await Promise . all ( result . items . map ( resolveItem ) ) ;
2390
+
2391
+ assert . sameDeepMembers ( resolvedItems , [
2261
2392
{
2262
2393
label : 'bar' ,
2263
2394
kind : CompletionItemKind . Method ,
2264
2395
documentation : 'bar doc' ,
2265
2396
insertText : 'bar' ,
2266
2397
insertTextFormat : InsertTextFormat . PlainText ,
2267
2398
sortText : '0' ,
2268
- detail : '(method) A.bar(): number'
2399
+ detail : '(method) A.bar(): number' ,
2400
+ data : undefined
2269
2401
} ,
2270
2402
{
2271
2403
label : 'baz' ,
@@ -2274,7 +2406,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
2274
2406
insertText : 'baz' ,
2275
2407
insertTextFormat : InsertTextFormat . PlainText ,
2276
2408
sortText : '0' ,
2277
- detail : '(method) A.baz(): string'
2409
+ detail : '(method) A.baz(): string' ,
2410
+ data : undefined
2278
2411
} ,
2279
2412
{
2280
2413
label : 'foo' ,
@@ -2283,7 +2416,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
2283
2416
insertText : 'foo' ,
2284
2417
insertTextFormat : InsertTextFormat . PlainText ,
2285
2418
sortText : '0' ,
2286
- detail : '(method) A.foo(): void'
2419
+ detail : '(method) A.foo(): void' ,
2420
+ data : undefined
2287
2421
} ,
2288
2422
{
2289
2423
label : 'qux' ,
@@ -2292,9 +2426,11 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
2292
2426
insertText : 'qux' ,
2293
2427
insertTextFormat : InsertTextFormat . PlainText ,
2294
2428
sortText : '0' ,
2295
- detail : '(property) A.qux: number'
2429
+ detail : '(property) A.qux: number' ,
2430
+ data : undefined
2296
2431
}
2297
2432
] ) ;
2433
+
2298
2434
} ) ;
2299
2435
2300
2436
it ( 'produces completions for imported symbols' , async function ( this : TestContext & ITestCallbackContext ) {
@@ -2310,12 +2446,13 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
2310
2446
assert . deepEqual ( result , {
2311
2447
isIncomplete : false ,
2312
2448
items : [ {
2449
+ data : {
2450
+ entryName : 'd' ,
2451
+ offset : 32 ,
2452
+ uri : rootUri + 'uses-import.ts'
2453
+ } ,
2313
2454
label : 'd' ,
2314
2455
kind : CompletionItemKind . Function ,
2315
- documentation : 'd doc' ,
2316
- insertText : 'd' ,
2317
- insertTextFormat : InsertTextFormat . PlainText ,
2318
- detail : 'function d(): void' ,
2319
2456
sortText : '0'
2320
2457
} ]
2321
2458
} ) ;
@@ -2333,13 +2470,14 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
2333
2470
assert . deepEqual ( result , {
2334
2471
isIncomplete : false ,
2335
2472
items : [ {
2473
+ data : {
2474
+ entryName : 'bar' ,
2475
+ offset : 51 ,
2476
+ uri : rootUri + 'uses-reference.ts'
2477
+ } ,
2336
2478
label : 'bar' ,
2337
2479
kind : CompletionItemKind . Interface ,
2338
- documentation : 'bar doc' ,
2339
- insertText : 'bar' ,
2340
- insertTextFormat : InsertTextFormat . PlainText ,
2341
- sortText : '0' ,
2342
- detail : 'interface foo.bar'
2480
+ sortText : '0'
2343
2481
} ]
2344
2482
} ) ;
2345
2483
} ) ;
0 commit comments