Skip to content

Commit e6074bb

Browse files
committed
feat: rework removeOrMarkGlobalLibCompletions text, also it was renamed from removeOrMarkGlobalCompletions!
1 parent 8ce3888 commit e6074bb

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/configurationType.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ export type Configuration = {
4545
* */
4646
'removeUselessFunctionProps.enable': boolean
4747
/**
48+
* Of course it makes no sense to use `remove`, but `mark` might be really useful
4849
* @default disable
4950
*/
50-
'removeOrMarkGlobalCompletions.action': 'disable' | 'mark' | 'remove'
51+
'removeOrMarkGlobalLibCompletions.action': 'disable' | 'mark' | 'remove'
5152
/**
5253
* Useful for Number types.
5354
* Patch `toString()`: Removes arg tabstop
@@ -364,4 +365,16 @@ export type Configuration = {
364365
* @default false
365366
*/
366367
'experiments.excludeNonJsxCompletions': boolean
368+
/**
369+
* Format of this setting is very close to `jsxCompletionsMap` setting:
370+
* path#symbol
371+
* Examples (keys in object):
372+
* #join - adjust `join` symbol from every module
373+
* path/win32#join - adjust `join` symbol from from path/win32 module
374+
* path/
375+
* Adjust actions (values in object):
376+
* false - completely disable symbol(s) suggesting
377+
* array of strings - change sorting of - first takes precedence for auto-imports (code actions & suggestions)
378+
*/
379+
'autoImport.adjustBySymbol': { ['path#symbol'] }
367380
}

typescript/src/completions/markOrRemoveGlobalCompletions.ts renamed to typescript/src/completions/markOrRemoveGlobalLibCompletions.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
import { compact } from '@zardoy/utils'
22
import { GetConfig } from '../types'
3+
import { basename } from 'path-browserify'
34

45
const isLibCompletion = (symbol: ts.Symbol) => {
5-
return symbol.declarations?.[0]?.getSourceFile().fileName.includes('node_modules/typescript/lib/')
6+
const fileName = symbol.declarations?.[0]?.getSourceFile().fileName
7+
if (!fileName) return
8+
if (!fileName.includes('node_modules/typescript/lib/')) return
9+
return basename(fileName).slice(0, -'.d.ts'.length)
610
}
711

812
export default (entries: ts.CompletionEntry[], position: number, languageService: ts.LanguageService, c: GetConfig) => {
9-
const action = c('removeOrMarkGlobalCompletions.action')
13+
const action = c('removeOrMarkGlobalLibCompletions.action')
1014
if (action === 'disable') return
1115

1216
return compact(
1317
entries.map(entry => {
1418
if (entry.sourceDisplay) return entry
1519
const symbol = entry['symbol'] as ts.Symbol | undefined
1620
if (!symbol) return entry
17-
if (!isLibCompletion(symbol)) return entry
21+
const libCompletionEnding = isLibCompletion(symbol)
22+
if (!libCompletionEnding) return entry
1823
if (action === 'remove') return undefined
1924
return {
2025
...entry,
2126
sourceDisplay: [
2227
{
2328
kind: 'text',
24-
text: 'global',
29+
text: libCompletionEnding,
2530
},
2631
],
2732
}

typescript/src/completionsAtPosition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import jsdocDefault from './completions/jsdocDefault'
2020
import defaultHelpers from './completions/defaultHelpers'
2121
import objectLiteralCompletions from './completions/objectLiteralCompletions'
2222
import filterJsxElements from './completions/filterJsxComponents'
23-
import markOrRemoveGlobalCompletions from './completions/markOrRemoveGlobalCompletions'
23+
import markOrRemoveGlobalCompletions from './completions/markOrRemoveGlobalLibCompletions'
2424
import { oneOf } from '@zardoy/utils'
2525

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

0 commit comments

Comments
 (0)