@@ -15,6 +15,7 @@ import switchCaseExcludeCovered from './completions/switchCaseExcludeCovered'
1515import additionalTypesSuggestions from './completions/additionalTypesSuggestions'
1616import boostKeywordSuggestions from './completions/boostKeywordSuggestions'
1717import boostTextSuggestions from './completions/boostNameSuggestions'
18+ import keywordsSpace from './completions/keywordsSpace'
1819
1920export type PrevCompletionMap = Record < string , { originalName ?: string ; documentationOverride ?: string | ts . SymbolDisplayPart [ ] } >
2021
@@ -48,6 +49,7 @@ export const getCompletionsAtPosition = (
4849 /** node that is one character behind
4950 * useful as in most cases we work with node that is behind the cursor */
5051 const leftNode = findChildContainingPosition ( ts , sourceFile , position - 1 )
52+ const tokenAtPosition = tsFull . getTokenAtPosition ( sourceFile as any , position ) as ts . Node
5153 if ( [ '.jsx' , '.tsx' ] . some ( ext => fileName . endsWith ( ext ) ) ) {
5254 // #region JSX tag improvements
5355 if ( node ) {
@@ -158,34 +160,7 @@ export const getCompletionsAtPosition = (
158160 } )
159161
160162 if ( c ( 'suggestions.keywordsInsertText' ) === 'space' ) {
161- const charAhead = scriptSnapshot . getText ( position , position + 1 )
162- const bannedKeywords = [
163- 'true' ,
164- 'false' ,
165- 'undefined' ,
166- 'null' ,
167- 'never' ,
168- 'unknown' ,
169- 'any' ,
170- 'symbol' ,
171- 'string' ,
172- 'number' ,
173- 'boolean' ,
174- 'object' ,
175- 'this' ,
176- 'catch' ,
177- 'constructor' ,
178- 'continue' ,
179- 'break' ,
180- 'debugger' ,
181- 'default' ,
182- 'super' ,
183- 'import' ,
184- ]
185- prior . entries = prior . entries . map ( entry => {
186- if ( entry . kind !== ts . ScriptElementKind . keyword || charAhead === ' ' || bannedKeywords . includes ( entry . name ) ) return entry
187- return { ...entry , insertText : `${ entry . name } ` }
188- } )
163+ prior . entries = keywordsSpace ( prior . entries , scriptSnapshot , position , tokenAtPosition )
189164 }
190165
191166 if ( leftNode && c ( 'switchExcludeCoveredCases' ) ) prior . entries = switchCaseExcludeCovered ( prior . entries , position , sourceFile , leftNode ) ?? prior . entries
0 commit comments