@@ -8,6 +8,8 @@ import { GetConfig } from './types'
8
8
import { getCompletionsAtPosition , PrevCompletionMap } from './completionsAtPosition'
9
9
import { oneOf } from '@zardoy/utils'
10
10
import { isGoodPositionMethodCompletion } from './isGoodPositionMethodCompletion'
11
+ import { inspect } from 'util'
12
+ import { getIndentFromPos } from './utils'
11
13
12
14
const thisPluginMarker = Symbol ( '__essentialPluginsMarker__' )
13
15
@@ -132,12 +134,25 @@ export = function ({ typescript }: { typescript: typeof import('typescript/lib/t
132
134
133
135
proxy . getCodeFixesAtPosition = ( fileName , start , end , errorCodes , formatOptions , preferences ) => {
134
136
let prior = info . languageService . getCodeFixesAtPosition ( fileName , start , end , errorCodes , formatOptions , preferences )
137
+ // fix builtin codefixes/refactorings
138
+ prior . forEach ( fix => {
139
+ if ( fix . fixName === 'fixConvertConstToLet' ) {
140
+ const { start, length } = fix . changes [ 0 ] ! . textChanges [ 0 ] ! . span
141
+ const fixedLength = 'const' . length as 5
142
+ fix . changes [ 0 ] ! . textChanges [ 0 ] ! . span . start = start + length - fixedLength
143
+ fix . changes [ 0 ] ! . textChanges [ 0 ] ! . span . length = fixedLength
144
+ }
145
+ return fix
146
+ } )
135
147
// const scriptSnapshot = info.project.getScriptSnapshot(fileName)
136
148
const diagnostics = proxy . getSemanticDiagnostics ( fileName )
137
149
138
150
// https://github.com/Microsoft/TypeScript/blob/v4.5.5/src/compiler/diagnosticMessages.json#L458
139
151
const appliableErrorCode = [ 1156 , 1157 ] . find ( code => errorCodes . includes ( code ) )
140
152
if ( appliableErrorCode ) {
153
+ const program = info . languageService . getProgram ( )
154
+ const sourceFile = program ! . getSourceFile ( fileName ) !
155
+ const startIndent = getIndentFromPos ( typescript , sourceFile , end )
141
156
const diagnostic = diagnostics . find ( ( { code } ) => code === appliableErrorCode ) !
142
157
prior = [
143
158
...prior ,
@@ -148,8 +163,8 @@ export = function ({ typescript }: { typescript: typeof import('typescript/lib/t
148
163
{
149
164
fileName,
150
165
textChanges : [
151
- { span : { start : diagnostic . start ! , length : 0 } , newText : '{' } ,
152
- { span : { start : diagnostic . start ! + diagnostic . length ! , length : 0 } , newText : '}' } ,
166
+ { span : { start : diagnostic . start ! , length : 0 } , newText : `{\n ${ startIndent } \t` } ,
167
+ { span : { start : diagnostic . start ! + diagnostic . length ! , length : 0 } , newText : `\n ${ startIndent } }` } ,
153
168
] ,
154
169
} ,
155
170
] ,
@@ -197,7 +212,10 @@ export = function ({ typescript }: { typescript: typeof import('typescript/lib/t
197
212
let prior = info . languageService . findReferences ( fileName , position )
198
213
if ( ! prior ) return
199
214
if ( c ( 'removeDefinitionFromReferences' ) ) {
200
- prior = prior . map ( ( { references, ...other } ) => ( { ...other , references : references . filter ( ( { isDefinition } ) => ! isDefinition ) } ) )
215
+ prior = prior . map ( ( { references, ...other } ) => ( {
216
+ ...other ,
217
+ references : references . filter ( ( { isDefinition } ) => ! isDefinition ) ,
218
+ } ) )
201
219
}
202
220
return prior
203
221
}
0 commit comments