@@ -6,7 +6,7 @@ import * as emmet from '@vscode/emmet-helper'
6
6
//@ts -ignore
7
7
import type { Configuration } from '../../src/configurationType'
8
8
9
- export = function ( { typescript } : { typescript : typeof import ( 'typescript/lib/tsserverlibrary' ) } ) {
9
+ export = function ( { typescript } : { typescript : typeof import ( 'typescript/lib/tsserverlibrary' ) } ) {
10
10
const ts = typescript
11
11
let _configuration : Configuration
12
12
const c = < T extends keyof Configuration > ( key : T ) : Configuration [ T ] => get ( _configuration , key )
@@ -163,24 +163,24 @@ export = function({ typescript }: { typescript: typeof import('typescript/lib/ts
163
163
const entryNames = new Set ( prior . entries . map ( ( { name } ) => name ) )
164
164
if ( c ( 'removeUselessFunctionProps.enable' ) ) prior . entries = prior . entries . filter ( e => ! [ 'Symbol' , 'caller' , 'prototype' ] . includes ( e . name ) )
165
165
if ( [ 'bind' , 'call' , 'caller' ] . every ( name => entryNames . has ( name ) ) && c ( 'highlightNonFunctionMethods.enable' ) ) {
166
- const standardProps = new Set ( [ 'Symbol' , 'apply' , 'arguments' , 'bind' , 'call' , 'caller' , 'length' , 'name' , 'prototype' , 'toString' ] )
167
- // TODO lift up!
168
- prior . entries = prior . entries . map ( entry => {
169
- if ( ! standardProps . has ( entry . name ) && entry . kind !== ts . ScriptElementKind . warning ) {
170
- const newName = `☆${ entry . name } `
171
- prevCompletionsMap [ newName ] = {
172
- originalName : entry . name ,
173
- }
174
- return {
175
- ...entry ,
176
- insertText : entry . insertText ?? entry . name ,
177
- name : newName ,
178
- }
166
+ const standardProps = new Set ( [ 'Symbol' , 'apply' , 'arguments' , 'bind' , 'call' , 'caller' , 'length' , 'name' , 'prototype' , 'toString' ] )
167
+ // TODO lift up!
168
+ prior . entries = prior . entries . map ( entry => {
169
+ if ( ! standardProps . has ( entry . name ) && entry . kind !== ts . ScriptElementKind . warning ) {
170
+ const newName = `☆${ entry . name } `
171
+ prevCompletionsMap [ newName ] = {
172
+ originalName : entry . name ,
173
+ }
174
+ return {
175
+ ...entry ,
176
+ insertText : entry . insertText ?? entry . name ,
177
+ name : newName ,
179
178
}
179
+ }
180
180
181
- return entry
182
- } )
183
- }
181
+ return entry
182
+ } )
183
+ }
184
184
185
185
if ( c ( 'patchToString.enable' ) ) {
186
186
// const indexToPatch = arrayMoveItemToFrom(
@@ -205,6 +205,16 @@ export = function({ typescript }: { typescript: typeof import('typescript/lib/ts
205
205
// TODO change to startsWith?
206
206
return ! banAutoImportPackages . includes ( text )
207
207
} )
208
+
209
+ if ( c ( 'suggestions.keywordsInsertText' ) === 'space' ) {
210
+ const charAhead = scriptSnapshot . getText ( position , position + 1 )
211
+ prior . entries = prior . entries . map ( entry => {
212
+ if ( entry . kind !== ts . ScriptElementKind . keyword ) return entry
213
+ entry . insertText = charAhead === ' ' ? entry . name : `${ entry . name } `
214
+ return entry
215
+ } )
216
+ }
217
+
208
218
for ( const rule of c ( 'replaceSuggestions' ) ) {
209
219
let foundIndex : number
210
220
const suggestion = prior . entries . find ( ( { name, kind } , index ) => {
@@ -215,19 +225,15 @@ export = function({ typescript }: { typescript: typeof import('typescript/lib/ts
215
225
} )
216
226
if ( ! suggestion ) continue
217
227
218
- if ( rule . delete )
219
- prior . entries . splice ( foundIndex ! , 1 )
220
-
228
+ if ( rule . delete ) prior . entries . splice ( foundIndex ! , 1 )
221
229
222
- if ( rule . duplicateOriginal )
223
- prior . entries . splice ( rule . duplicateOriginal === 'above' ? foundIndex ! : foundIndex ! + 1 , 0 , { ...suggestion } )
230
+ if ( rule . duplicateOriginal ) prior . entries . splice ( rule . duplicateOriginal === 'above' ? foundIndex ! : foundIndex ! + 1 , 0 , { ...suggestion } )
224
231
225
232
Object . assign ( suggestion , rule . patch ?? { } )
226
233
if ( rule . patch ?. insertText ) suggestion . isSnippet = true
227
234
}
228
235
229
- if ( c ( 'correctSorting.enable' ) )
230
- prior . entries = prior . entries . map ( ( entry , index ) => ( { ...entry , sortText : `${ entry . sortText ?? '' } ${ index } ` } ) )
236
+ if ( c ( 'correctSorting.enable' ) ) prior . entries = prior . entries . map ( ( entry , index ) => ( { ...entry , sortText : `${ entry . sortText ?? '' } ${ index } ` } ) )
231
237
232
238
// console.log('signatureHelp', JSON.stringify(info.languageService.getSignatureHelpItems(fileName, position, {})))
233
239
// console.timeEnd('slow-down')
@@ -283,8 +289,7 @@ export = function({ typescript }: { typescript: typeof import('typescript/lib/ts
283
289
284
290
// @ts -expect-error some experiments
285
291
proxy . ignored = ( fileName : string , positionOrRange : number , preferences : any ) => {
286
- if ( typeof positionOrRange !== 'number' )
287
- positionOrRange = positionOrRange
292
+ if ( typeof positionOrRange !== 'number' ) positionOrRange = positionOrRange
288
293
289
294
// ts.createSourceFile(fileName, sourceText, languageVersion)
290
295
const { textSpan } = proxy . getSmartSelectionRange ( fileName , positionOrRange )
@@ -351,8 +356,7 @@ function findChildContainingPosition(
351
356
position : number ,
352
357
) : tslib . Node | undefined {
353
358
function find ( node : ts . Node ) : ts . Node | undefined {
354
- if ( position >= node . getStart ( ) && position < node . getEnd ( ) )
355
- return typescript . forEachChild ( node , find ) || node
359
+ if ( position >= node . getStart ( ) && position < node . getEnd ( ) ) return typescript . forEachChild ( node , find ) || node
356
360
357
361
return
358
362
}
0 commit comments