Skip to content

Commit cbc8f9b

Browse files
committed
feat: markOrRemoveGlobalCompletions! (disabled by default)
1 parent 79b81f1 commit cbc8f9b

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/configurationType.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export type Configuration = {
4444
* @default true
4545
* */
4646
'removeUselessFunctionProps.enable': boolean
47+
/**
48+
* @default disable
49+
*/
50+
'removeOrMarkGlobalCompletions.action': 'disable' | 'mark' | 'remove'
4751
/**
4852
* Useful for Number types.
4953
* Patch `toString()`: Removes arg tabstop
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { compact } from '@zardoy/utils'
2+
import { GetConfig } from '../types'
3+
4+
const isLibCompletion = (symbol: ts.Symbol) => {
5+
return symbol.declarations?.[0]?.getSourceFile().fileName.includes('node_modules/typescript/lib/')
6+
}
7+
8+
export default (entries: ts.CompletionEntry[], position: number, languageService: ts.LanguageService, c: GetConfig) => {
9+
const action = c('removeOrMarkGlobalCompletions.action')
10+
if (action === 'disable') return
11+
12+
return compact(
13+
entries.map(entry => {
14+
if (entry.sourceDisplay) return entry
15+
const symbol = entry['symbol'] as ts.Symbol | undefined
16+
if (!symbol) return entry
17+
if (!isLibCompletion(symbol)) return entry
18+
if (action === 'remove') return undefined
19+
return {
20+
...entry,
21+
sourceDisplay: [
22+
{
23+
kind: 'text',
24+
text: 'global',
25+
},
26+
],
27+
}
28+
}),
29+
)
30+
}

typescript/src/completionsAtPosition.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import jsdocDefault from './completions/jsdocDefault'
1919
import defaultHelpers from './completions/defaultHelpers'
2020
import objectLiteralCompletions from './completions/objectLiteralCompletions'
2121
import filterJsxElements from './completions/filterJsxComponents'
22+
import markOrRemoveGlobalCompletions from './completions/markOrRemoveGlobalCompletions'
2223

2324
export type PrevCompletionMap = Record<string, { originalName?: string; documentationOverride?: string | ts.SymbolDisplayPart[] }>
2425

@@ -182,6 +183,7 @@ export const getCompletionsAtPosition = (
182183
})
183184
}
184185

186+
prior.entries = markOrRemoveGlobalCompletions(prior.entries, position, languageService, c) ?? prior.entries
185187
if (exactNode) prior.entries = filterJsxElements(prior.entries, exactNode, position, languageService, c) ?? prior.entries
186188

187189
if (c('correctSorting.enable')) {

0 commit comments

Comments
 (0)