Skip to content

Commit 591227c

Browse files
committed
fix: object literal completions disappear on used props 🤦
1 parent d61f9be commit 591227c

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

typescript/src/completions/objectLiteralCompletions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default (
2222
const properties = objType.getProperties()
2323
for (const property of properties) {
2424
const entry = entries.find(({ name }) => name === property.name)
25-
if (!entry) return
25+
if (!entry) continue
2626
const type = typeChecker.getTypeOfSymbolAtLocation(property, node)
2727
if (!type) continue
2828
if (isMethodCompletionCall(type, typeChecker)) {

typescript/test/completions.spec.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ const getCompletionsAtPosition = (pos: number, fileName = entrypoint) => {
8080
return {
8181
...result,
8282
entries: result.completions.entries,
83-
entriesSorted: _.sortBy(result.completions.entries, ({ sortText }) => sortText),
83+
/** Can be used in snapshots */
84+
entriesSorted: _.sortBy(result.completions.entries, ({ sortText }) => sortText)
85+
.map(({ sortText, ...rest }) => rest)
86+
.map(entry => Object.fromEntries(Object.entries(entry).filter(([, value]) => value !== undefined))) as ts.CompletionEntry[],
8487
entryNames: result.completions.entries.map(({ name }) => name),
8588
}
8689
}
@@ -261,6 +264,7 @@ test('Switch Case Exclude Covered', () => {
261264
test('Object Literal Completions', () => {
262265
const [_positivePositions, _negativePositions, numPositions] = fileContentsSpecialPositions(/* ts */ `
263266
interface Options {
267+
usedOption
264268
mood?: 'happy' | 'sad'
265269
callback?()
266270
additionalOptions?: {
@@ -271,70 +275,64 @@ test('Object Literal Completions', () => {
271275
272276
const makeDay = (options: Options) => {}
273277
makeDay({
278+
usedOption,
274279
/*1*/
275280
})
276281
`)
277282
const { entriesSorted } = getCompletionsAtPosition(numPositions[1]!) ?? {}
278283
// todo resolve sorting problem + add tests with other keepOriginal (it was tested manually)
279-
expect(entriesSorted?.map(entry => Object.fromEntries(Object.entries(entry).filter(([, value]) => value !== undefined)))).toMatchInlineSnapshot(`
284+
for (const entry of entriesSorted ?? []) {
285+
entry.insertText = entry.insertText?.replaceAll('\n', '\\n')
286+
}
287+
expect(entriesSorted).toMatchInlineSnapshot(`
280288
[
281289
{
282290
"insertText": "plugins",
283291
"isSnippet": true,
284292
"kind": "property",
285293
"kindModifiers": "",
286294
"name": "plugins",
287-
"sortText": "110000",
288295
},
289296
{
290-
"insertText": "plugins: [
291-
$1
292-
],$0",
297+
"insertText": "plugins: [\\\\n $1\\\\n],$0",
293298
"isSnippet": true,
294299
"kind": "property",
295300
"kindModifiers": "",
296301
"labelDetails": {
297302
"detail": ": [],",
298303
},
299304
"name": "plugins",
300-
"sortText": "110001",
301305
},
302306
{
303307
"insertText": "additionalOptions",
304308
"isSnippet": true,
305309
"kind": "property",
306310
"kindModifiers": "optional",
307311
"name": "additionalOptions",
308-
"sortText": "120002",
309312
},
310313
{
311-
"insertText": "additionalOptions: {
312-
$1
313-
},$0",
314+
"insertText": "additionalOptions: {\\\\n $1\\\\n},$0",
314315
"isSnippet": true,
315316
"kind": "property",
316317
"kindModifiers": "optional",
317318
"labelDetails": {
318319
"detail": ": {},",
319320
},
320321
"name": "additionalOptions",
321-
"sortText": "120003",
322322
},
323323
{
324324
"insertText": "callback",
325325
"isSnippet": true,
326326
"kind": "method",
327327
"kindModifiers": "optional",
328328
"name": "callback",
329-
"sortText": "120004",
330329
},
331330
{
332331
"insertText": "mood",
333332
"isSnippet": true,
334333
"kind": "property",
335334
"kindModifiers": "optional",
336335
"name": "mood",
337-
"sortText": "120005",
338336
},
339337
{
340338
"insertText": "mood: \\"$1\\",$0",
@@ -345,7 +343,6 @@ test('Object Literal Completions', () => {
345343
"detail": ": \\"\\",",
346344
},
347345
"name": "mood",
348-
"sortText": "120006",
349346
},
350347
]
351348
`)

0 commit comments

Comments
 (0)