Skip to content

Commit e820410

Browse files
committed
fix: *Remove Useless Function Props*: finally we carefully remove only actual function props and not every completion that has bad name e.g. global Symbol completion
1 parent e019d60 commit e820410

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

src/configurationType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export type Configuration = {
6767
*/
6868
// volarLoadConfigPaths: string[]
6969
/**
70-
* Removes `Symbol`, `caller`, `prototype` everywhere
70+
* Removes annoying `Symbol`, `caller`, `prototype` everywhere
7171
* @default true
7272
* */
7373
'removeUselessFunctionProps.enable': boolean

typescript/src/completions/functionPropsAndMethods.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import { oneOf } from '@zardoy/utils'
2+
import { matchParents } from '../utils'
23
import { sharedCompletionContext } from './sharedContext'
34

45
export default (entries: ts.CompletionEntry[]) => {
56
const { c, prevCompletionsMap } = sharedCompletionContext
67

78
if (c('removeUselessFunctionProps.enable')) {
89
entries = entries.filter(entry => {
9-
if (oneOf(entry.kind, ts.ScriptElementKind.warning)) return true
10-
return !['Symbol', 'caller', 'prototype'].includes(entry.name)
10+
const completionDeclaration = entry.symbol?.valueDeclaration
11+
if (
12+
['Symbol', 'caller', 'prototype'].includes(entry.name) &&
13+
!oneOf(entry.kind, ts.ScriptElementKind.warning) &&
14+
(entry.insertText === '[Symbol]' ||
15+
(completionDeclaration?.getSourceFile().fileName.includes('node_modules/typescript/lib/lib') &&
16+
matchParents(completionDeclaration.parent, ['InterfaceDeclaration'])?.name.text === 'Function'))
17+
) {
18+
return false
19+
}
20+
return true
1121
})
1222
}
1323

typescript/test/completions.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,28 @@ test('String template type completions', () => {
415415
})
416416
})
417417

418+
test('Remove Useless Function Props', () => {
419+
const tester = fourslashLikeTester(/* ts */ `
420+
const a = () => {}
421+
a./*1*/
422+
const b = {
423+
Symbol: 5,
424+
prototype: 5,
425+
caller: 5,
426+
}
427+
b./*2*/
428+
`)
429+
const badProps = ['Symbol', 'caller', 'prototype']
430+
tester.completion(1, {
431+
excludes: badProps,
432+
})
433+
tester.completion(2, {
434+
includes: {
435+
names: badProps,
436+
},
437+
})
438+
})
439+
418440
test('Switch Case Exclude Covered', () => {
419441
const [, _, numPositions] = fileContentsSpecialPositions(/*ts*/ `
420442
let test: 'foo' | 'bar'

typescript/test/testing.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ export const fourslashLikeTester = (contents: string, fileName = entrypoint) =>
130130
}
131131
}
132132
if (excludes) {
133-
expect(result?.entryNames, message).not.toContain(excludes)
133+
for (const exclude of excludes) {
134+
expect(result?.entryNames, message).not.toContain(exclude)
135+
}
134136
}
135137
}
136138
},

0 commit comments

Comments
 (0)