@@ -87,13 +87,9 @@ export = function ({ typescript }: { typescript: typeof import('typescript/lib/t
8787 // description: '',
8888 // changes: []
8989 // })
90- // prior.codeActions = [{ description: '', changes: [{ fileName, textChanges: [{ span: { start: position, length: 0 }, newText: '()' }] }] }]
91- // formatOptions
92- // info.languageService.getDefinitionAtPosition(fileName, position)
9390 return prior
9491 }
9592
96- // proxy.getCombinedCodeFix(scope, fixId, formatOptions, preferences)
9793 proxy . getApplicableRefactors = ( fileName , positionOrRange , preferences ) => {
9894 let prior = info . languageService . getApplicableRefactors ( fileName , positionOrRange , preferences )
9995
@@ -140,9 +136,35 @@ export = function ({ typescript }: { typescript: typeof import('typescript/lib/t
140136 return prior
141137 }
142138
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+
143164 proxy . findReferences = ( fileName , position ) => {
144165 let prior = info . languageService . findReferences ( fileName , position )
145- if ( prior && c ( 'removeDefinitionFromReferences' ) ) {
166+ if ( ! prior ) return
167+ if ( c ( 'removeDefinitionFromReferences' ) ) {
146168 prior = prior . map ( ( { references, ...other } ) => ( { ...other , references : references . filter ( ( { isDefinition } ) => ! isDefinition ) } ) )
147169 }
148170 return prior
0 commit comments