@@ -3,7 +3,7 @@ import inKeywordCompletions from './completions/inKeywordCompletions'
3
3
// import * as emmet from '@vscode/emmet-helper'
4
4
import isInBannedPosition from './completions/isInBannedPosition'
5
5
import { GetConfig } from './types'
6
- import { findChildContainingExactPosition , findChildContainingPosition , isTs5 } from './utils'
6
+ import { findChildContainingExactPosition , findChildContainingPosition , isTs5 , patchMethod } from './utils'
7
7
import indexSignatureAccessCompletions from './completions/indexSignatureAccess'
8
8
import fixPropertiesSorting from './completions/fixPropertiesSorting'
9
9
import { isGoodPositionBuiltinMethodCompletion } from './completions/isGoodPositionMethodCompletion'
@@ -20,7 +20,7 @@ import defaultHelpers from './completions/defaultHelpers'
20
20
import objectLiteralCompletions from './completions/objectLiteralCompletions'
21
21
import filterJsxElements from './completions/filterJsxComponents'
22
22
import markOrRemoveGlobalCompletions from './completions/markOrRemoveGlobalLibCompletions'
23
- import { compact , oneOf } from '@zardoy/utils'
23
+ import { compact } from '@zardoy/utils'
24
24
import adjustAutoImports from './completions/adjustAutoImports'
25
25
import escapeStringRegexp from 'escape-string-regexp'
26
26
import addSourceDefinition from './completions/addSourceDefinition'
@@ -30,6 +30,7 @@ import changeKindToFunction from './completions/changeKindToFunction'
30
30
import functionPropsAndMethods from './completions/functionPropsAndMethods'
31
31
import { getTupleSignature } from './tupleSignature'
32
32
import stringTemplateTypeCompletions from './completions/stringTemplateType'
33
+ import localityBonus from './completions/localityBonus'
33
34
34
35
export type PrevCompletionMap = Record <
35
36
string ,
@@ -271,11 +272,13 @@ export const getCompletionsAtPosition = (
271
272
}
272
273
// #endregion
273
274
274
- prior . entries = addSourceDefinition ( prior . entries , prevCompletionsMap , c ) ?? prior . entries
275
+ addSourceDefinition ( prior . entries )
275
276
displayImportedInfo ( prior . entries )
276
277
277
278
if ( c ( 'improveJsxCompletions' ) && leftNode ) prior . entries = improveJsxCompletions ( prior . entries , leftNode , position , sourceFile , c ( 'jsxCompletionsMap' ) )
278
279
280
+ prior . entries = localityBonus ( prior . entries ) ?? prior . entries
281
+
279
282
const processedEntries = new Set < ts . CompletionEntry > ( )
280
283
for ( const rule of c ( 'replaceSuggestions' ) ) {
281
284
if ( rule . filter ?. fileNamePattern ) {
@@ -376,17 +379,6 @@ export const getCompletionsAtPosition = (
376
379
}
377
380
}
378
381
379
- type ArrayPredicate < T > = ( value : T , index : number ) => boolean
380
- const arrayMoveItemToFrom = < T > ( array : T [ ] , originalItem : ArrayPredicate < T > , itemToMove : ArrayPredicate < T > ) => {
381
- const originalItemIndex = array . findIndex ( originalItem )
382
- if ( originalItemIndex === - 1 ) return undefined
383
- const itemToMoveIndex = array . findIndex ( itemToMove )
384
- if ( itemToMoveIndex === - 1 ) return undefined
385
- array . splice ( originalItemIndex , 0 , array [ itemToMoveIndex ] ! )
386
- array . splice ( itemToMoveIndex + 1 , 1 )
387
- return originalItemIndex
388
- }
389
-
390
382
const patchBuiltinMethods = ( c : GetConfig , languageService : ts . LanguageService , isCheckedFile : boolean ) => {
391
383
if ( isTs5 ( ) && ( isCheckedFile || ! c ( 'additionalIncludeExtensions' ) . length ) ) return
392
384
@@ -408,24 +400,21 @@ const patchBuiltinMethods = (c: GetConfig, languageService: ts.LanguageService,
408
400
// Its known that fuzzy completion don't work within import completions
409
401
// TODO! when file name without with half-ending is typed it doesn't these completions! (seems ts bug, but probably can be fixed here)
410
402
// e.g. /styles.css import './styles.c|' - no completions
411
- const oldGetSupportedExtensions = tsFull . getSupportedExtensions
412
- Object . defineProperty ( tsFull , 'getSupportedExtensions' , {
413
- value : ( options , extraFileExtensions ) => {
414
- addFileExtensions ??= getAddFileExtensions ( )
415
- // though I extensions could be just inlined as is
416
- return oldGetSupportedExtensions (
417
- options ,
418
- extraFileExtensions ?. length
419
- ? extraFileExtensions
420
- : addFileExtensions . map ( ext => ( {
421
- extension : ext ,
422
- isMixedContent : true ,
423
- scriptKind : ts . ScriptKind . Deferred ,
424
- } ) ) ,
425
- )
426
- } ,
403
+ const unpatch = patchMethod ( tsFull , 'getSupportedExtensions' , ( oldGetSupportedExtensions ) : any => ( options , extraFileExtensions ) => {
404
+ addFileExtensions ??= getAddFileExtensions ( )
405
+ // though extensions could be just inlined as is
406
+ return oldGetSupportedExtensions (
407
+ options ,
408
+ extraFileExtensions ?. length
409
+ ? extraFileExtensions
410
+ : addFileExtensions . map ( ext => ( {
411
+ extension : ext ,
412
+ isMixedContent : true ,
413
+ scriptKind : ts . ScriptKind . Deferred ,
414
+ } ) ) ,
415
+ )
427
416
} )
428
417
return ( ) => {
429
- Object . defineProperty ( tsFull , 'getSupportedExtensions' , { value : oldGetSupportedExtensions } )
418
+ unpatch ( )
430
419
}
431
420
}
0 commit comments