@@ -6,7 +6,7 @@ import * as emmet from '@vscode/emmet-helper'
66//@ts -ignore
77import type { Configuration } from '../../src/configurationType'
88
9- export = function ( { typescript } : { typescript : typeof import ( 'typescript/lib/tsserverlibrary' ) } ) {
9+ export = function ( { typescript } : { typescript : typeof import ( 'typescript/lib/tsserverlibrary' ) } ) {
1010 const ts = typescript
1111 let _configuration : Configuration
1212 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
163163 const entryNames = new Set ( prior . entries . map ( ( { name } ) => name ) )
164164 if ( c ( 'removeUselessFunctionProps.enable' ) ) prior . entries = prior . entries . filter ( e => ! [ 'Symbol' , 'caller' , 'prototype' ] . includes ( e . name ) )
165165 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 ,
179178 }
179+ }
180180
181- return entry
182- } )
183- }
181+ return entry
182+ } )
183+ }
184184
185185 if ( c ( 'patchToString.enable' ) ) {
186186 // const indexToPatch = arrayMoveItemToFrom(
@@ -205,6 +205,16 @@ export = function({ typescript }: { typescript: typeof import('typescript/lib/ts
205205 // TODO change to startsWith?
206206 return ! banAutoImportPackages . includes ( text )
207207 } )
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+
208218 for ( const rule of c ( 'replaceSuggestions' ) ) {
209219 let foundIndex : number
210220 const suggestion = prior . entries . find ( ( { name, kind } , index ) => {
@@ -215,19 +225,15 @@ export = function({ typescript }: { typescript: typeof import('typescript/lib/ts
215225 } )
216226 if ( ! suggestion ) continue
217227
218- if ( rule . delete )
219- prior . entries . splice ( foundIndex ! , 1 )
220-
228+ if ( rule . delete ) prior . entries . splice ( foundIndex ! , 1 )
221229
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 } )
224231
225232 Object . assign ( suggestion , rule . patch ?? { } )
226233 if ( rule . patch ?. insertText ) suggestion . isSnippet = true
227234 }
228235
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 } ` } ) )
231237
232238 // console.log('signatureHelp', JSON.stringify(info.languageService.getSignatureHelpItems(fileName, position, {})))
233239 // console.timeEnd('slow-down')
@@ -283,8 +289,7 @@ export = function({ typescript }: { typescript: typeof import('typescript/lib/ts
283289
284290 // @ts -expect-error some experiments
285291 proxy . ignored = ( fileName : string , positionOrRange : number , preferences : any ) => {
286- if ( typeof positionOrRange !== 'number' )
287- positionOrRange = positionOrRange
292+ if ( typeof positionOrRange !== 'number' ) positionOrRange = positionOrRange
288293
289294 // ts.createSourceFile(fileName, sourceText, languageVersion)
290295 const { textSpan } = proxy . getSmartSelectionRange ( fileName , positionOrRange )
@@ -351,8 +356,7 @@ function findChildContainingPosition(
351356 position : number ,
352357) : tslib . Node | undefined {
353358 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
356360
357361 return
358362 }
0 commit comments