@@ -120,16 +120,13 @@ export default (proxy: ts.LanguageService, info: ts.server.PluginCreateInfo, c:
120120 }
121121 if ( c ( 'miscDefinitionImprovement' ) && prior . definitions ) {
122122 const filterOutReactFcDef = prior . definitions . length === 2
123- prior . definitions = prior . definitions . filter ( ( { fileName, containerName, containerKind, kind, name, ...rest } ) => {
123+ prior . definitions = prior . definitions . filter ( ( { fileName, containerName, containerKind, kind, name, textSpan , ...rest } ) => {
124124 const isFcDef = filterOutReactFcDef && fileName . endsWith ( 'node_modules/@types/react/index.d.ts' ) && containerName === 'FunctionComponent'
125125 if ( isFcDef ) return false
126126 // filter out css modules index definition
127127 if ( containerName === 'classes' && containerKind === undefined && rest [ 'isAmbient' ] && kind === 'index' && name === '__index' ) {
128128 // ensure we don't filter out something important?
129- const nodeAtDefinition = findChildContainingExactPosition (
130- info . languageService . getProgram ( ) ! . getSourceFile ( fileName ) ! ,
131- firstDef . textSpan . start ,
132- )
129+ const nodeAtDefinition = findChildContainingExactPosition ( info . languageService . getProgram ( ) ! . getSourceFile ( fileName ) ! , textSpan . start )
133130 let moduleDeclaration : ModuleDeclaration | undefined
134131 ts . findAncestor ( nodeAtDefinition , node => {
135132 if ( ts . isModuleDeclaration ( node ) ) {
@@ -138,19 +135,25 @@ export default (proxy: ts.LanguageService, info: ts.server.PluginCreateInfo, c:
138135 }
139136 return false
140137 } )
141- if ( moduleDeclaration ?. name . text === '*.module.css' ) return false
138+ const cssModules = [ '*.module.css' , '*.module.scss' , '*.module.sass' , '*.module.less' , '*.module.styl' ]
139+ if ( moduleDeclaration ?. name . text && cssModules . includes ( moduleDeclaration . name . text ) ) return false
142140 }
143141 return true
144142 } )
145143 }
146144
147- if (
148- c ( 'removeModuleFileDefinitions' ) &&
149- prior . definitions ?. length === 1 &&
150- firstDef . kind === ts . ScriptElementKind . moduleElement &&
151- firstDef . name . slice ( 1 , - 1 ) . startsWith ( '*.' )
152- ) {
153- return
145+ if ( c ( 'removeModuleFileDefinitions' ) ) {
146+ prior . definitions = prior . definitions ?. filter ( def => {
147+ if (
148+ def . kind === ts . ScriptElementKind . moduleElement &&
149+ def . name . slice ( 1 , - 1 ) . startsWith ( '*.' ) &&
150+ def . containerKind === undefined &&
151+ def [ 'isAmbient' ]
152+ ) {
153+ return false
154+ }
155+ return true
156+ } )
154157 }
155158
156159 return prior
0 commit comments