@@ -87,13 +87,9 @@ export = function ({ typescript }: { typescript: typeof import('typescript/lib/t
87
87
// description: '',
88
88
// changes: []
89
89
// })
90
- // prior.codeActions = [{ description: '', changes: [{ fileName, textChanges: [{ span: { start: position, length: 0 }, newText: '()' }] }] }]
91
- // formatOptions
92
- // info.languageService.getDefinitionAtPosition(fileName, position)
93
90
return prior
94
91
}
95
92
96
- // proxy.getCombinedCodeFix(scope, fixId, formatOptions, preferences)
97
93
proxy . getApplicableRefactors = ( fileName , positionOrRange , preferences ) => {
98
94
let prior = info . languageService . getApplicableRefactors ( fileName , positionOrRange , preferences )
99
95
@@ -140,9 +136,35 @@ export = function ({ typescript }: { typescript: typeof import('typescript/lib/t
140
136
return prior
141
137
}
142
138
139
+ proxy . getDefinitionAndBoundSpan = ( fileName , position ) => {
140
+ const prior = info . languageService . getDefinitionAndBoundSpan ( fileName , position )
141
+ if ( ! prior ) return
142
+ // used after check
143
+ const firstDef = prior . definitions ! [ 0 ] !
144
+ if (
145
+ c ( 'changeDtsFileDefinitionToJs' ) &&
146
+ prior . definitions ?. length === 1 &&
147
+ // default, namespace import or import path click
148
+ firstDef . containerName === '' &&
149
+ firstDef . fileName . endsWith ( '.d.ts' )
150
+ ) {
151
+ const jsFileName = `${ firstDef . fileName . slice ( 0 , - '.d.ts' . length ) } .js`
152
+ const isJsFileExist = info . languageServiceHost . fileExists ?.( jsFileName )
153
+ if ( isJsFileExist ) prior . definitions = [ { ...firstDef , fileName : jsFileName } ]
154
+ }
155
+ if ( c ( 'miscDefinitionImprovement' ) && prior . definitions ?. length === 2 ) {
156
+ prior . definitions = prior . definitions . filter ( ( { fileName, containerName } ) => {
157
+ const isFcDef = fileName . endsWith ( 'node_modules/@types/react/index.d.ts' ) && containerName === 'FunctionComponent'
158
+ return ! isFcDef
159
+ } )
160
+ }
161
+ return prior
162
+ }
163
+
143
164
proxy . findReferences = ( fileName , position ) => {
144
165
let prior = info . languageService . findReferences ( fileName , position )
145
- if ( prior && c ( 'removeDefinitionFromReferences' ) ) {
166
+ if ( ! prior ) return
167
+ if ( c ( 'removeDefinitionFromReferences' ) ) {
146
168
prior = prior . map ( ( { references, ...other } ) => ( { ...other , references : references . filter ( ( { isDefinition } ) => ! isDefinition ) } ) )
147
169
}
148
170
return prior
0 commit comments