|
1 | 1 | import { GetConfig } from './types'
|
2 | 2 | import { findChildContainingExactPosition } from './utils'
|
3 | 3 | import { join } from 'path-browserify'
|
| 4 | +import { ModuleDeclaration } from 'typescript' |
4 | 5 |
|
5 | 6 | export default (proxy: ts.LanguageService, info: ts.server.PluginCreateInfo, c: GetConfig) => {
|
6 | 7 | proxy.getDefinitionAndBoundSpan = (fileName, position) => {
|
@@ -35,7 +36,8 @@ export default (proxy: ts.LanguageService, info: ts.server.PluginCreateInfo, c:
|
35 | 36 | }
|
36 | 37 | }
|
37 | 38 |
|
38 |
| - // thoughts about type definition: no impl here, will be simpler to do this in core |
| 39 | + // partial fix for https://github.com/microsoft/TypeScript/issues/49033 (string literal in function call definition) |
| 40 | + // thoughts about type definition: no impl here, will be simpler to do this in core instead |
39 | 41 | if (ts.isCallExpression(node.parent)) {
|
40 | 42 | const parameterIndex = node.parent.arguments.indexOf(node)
|
41 | 43 | const typeChecker = program.getTypeChecker()
|
@@ -116,12 +118,30 @@ export default (proxy: ts.LanguageService, info: ts.server.PluginCreateInfo, c:
|
116 | 118 | const isJsFileExist = info.languageServiceHost.fileExists?.(jsFileName)
|
117 | 119 | if (isJsFileExist) prior.definitions = [{ ...firstDef, fileName: jsFileName }]
|
118 | 120 | }
|
119 |
| - if (c('miscDefinitionImprovement') && prior.definitions?.length === 2) { |
120 |
| - prior.definitions = prior.definitions.filter(({ fileName, containerName }) => { |
121 |
| - const isFcDef = fileName.endsWith('node_modules/@types/react/index.d.ts') && containerName === 'FunctionComponent' |
122 |
| - return !isFcDef |
| 121 | + if (c('miscDefinitionImprovement') && prior.definitions) { |
| 122 | + const filterOutReactFcDef = prior.definitions.length === 2 |
| 123 | + prior.definitions = prior.definitions.filter(({ fileName, containerName, containerKind, kind, name, ...rest }) => { |
| 124 | + const isFcDef = filterOutReactFcDef && fileName.endsWith('node_modules/@types/react/index.d.ts') && containerName === 'FunctionComponent' |
| 125 | + if (isFcDef) return false |
| 126 | + // filter out css modules index definition |
| 127 | + if (containerName === 'classes' && containerKind === undefined && rest['isAmbient'] && kind === 'index' && name === '__index') { |
| 128 | + // ensure we don't filter out something important? |
| 129 | + const nodeAtDefinition = findChildContainingExactPosition( |
| 130 | + info.languageService.getProgram()!.getSourceFile(fileName)!, |
| 131 | + firstDef.textSpan.start, |
| 132 | + ) |
| 133 | + let moduleDeclaration: ModuleDeclaration | undefined |
| 134 | + ts.findAncestor(nodeAtDefinition, node => { |
| 135 | + if (ts.isModuleDeclaration(node)) { |
| 136 | + moduleDeclaration = node |
| 137 | + return 'quit' |
| 138 | + } |
| 139 | + return false |
| 140 | + }) |
| 141 | + if (moduleDeclaration?.name.getText() === '*.module.css') return false |
| 142 | + } |
| 143 | + return true |
123 | 144 | })
|
124 |
| - // 11 |
125 | 145 | }
|
126 | 146 |
|
127 | 147 | if (
|
|
0 commit comments