@@ -9,10 +9,10 @@ import {
99 resolveWorkspaceRelativePath ,
1010} from "../utils/getPath" ;
1111import { sanitizeCssInput } from "../utils/sanitizeCssInput" ;
12- import isPositionInComment from "../utils/isPositionInComment " ;
12+ import { isPositionInComment } from "../utils/isPositionInScope " ;
1313import CssModuleDependencyCache from "./cssModuleDependencyCache" ;
1414import CheckDocument from "./checkDocument" ;
15- import { ClassNameRange , ClassNameRangeMap } from "../types/cache" ;
15+ import { type ClassNameRange , ClassNameRangeMap } from "../types/cache" ;
1616
1717/**
1818 * A utility class to extract and cache class names from CSS Module files.
@@ -34,23 +34,29 @@ export default class ClassNameCache {
3434 static async updateClassNameCache ( e : vscode . TextDocument ) {
3535 const importPath = getWorkspaceRelativeUriPath ( e . uri ) ;
3636 clearTimeout ( this . ClassNameCacheDebounceIdMap [ importPath ] ) ;
37- this . ClassNameCacheDebounceIdMap [ importPath ] = setTimeout ( async ( ) => {
38- await ClassNameCache . extractFromUri ( e . uri ) ;
37+ this . ClassNameCacheDebounceIdMap [ importPath ] = setTimeout ( ( ) => {
38+ ( async ( ) => {
39+ await ClassNameCache . extractFromUri ( e . uri ) ;
3940
40- if ( SUPPORTED_MODULES . includes ( e . languageId ) ) {
41- const dependents = CssModuleDependencyCache . getDependentsForDocument ( e ) ;
41+ if ( SUPPORTED_MODULES . includes ( e . languageId ) ) {
42+ const dependents =
43+ CssModuleDependencyCache . getDependentsForDocument ( e ) ;
4244
43- for ( const workspacePath of dependents ) {
44- const resolvedPath = resolveWorkspaceRelativePath ( workspacePath ) ;
45- if ( ! resolvedPath ) {
46- return ;
45+ for ( const workspacePath of dependents ) {
46+ const resolvedPath = resolveWorkspaceRelativePath ( workspacePath ) ;
47+ if ( ! resolvedPath ) {
48+ continue ;
49+ }
50+ const document =
51+ await vscode . workspace . openTextDocument ( resolvedPath ) ;
52+ CheckDocument . push ( document ) ;
4753 }
48- const document = await vscode . workspace . openTextDocument (
49- resolvedPath
50- ) ;
51- CheckDocument . push ( document ) ;
5254 }
53- }
55+ } ) ( )
56+ . catch ( console . error )
57+ . finally ( ( ) => {
58+ delete ClassNameCache . ClassNameCacheDebounceIdMap [ importPath ] ;
59+ } ) ;
5460 } , DEBOUNCE_TIMER . UPDATE_CLASS_NAME ) ;
5561 }
5662
@@ -182,11 +188,11 @@ export default class ClassNameCache {
182188 ) : Promise < string [ ] | undefined > {
183189 if ( Cache . classNameCache . hasByKey ( importPath ) ) {
184190 return Array . from (
185- Cache . classNameCache . getByKey ( importPath ) ?. keys ( ) || [ ]
191+ Cache . classNameCache . getByKey ( importPath ) ?. keys ( ) ?? [ ]
186192 ) ;
187193 } else {
188194 return Array . from (
189- ( await this . extractAndCacheClassNames ( importPath ) ) ?. keys ( ) || [ ]
195+ ( await this . extractAndCacheClassNames ( importPath ) ) ?. keys ( ) ?? [ ]
190196 ) ;
191197 }
192198 }
@@ -279,7 +285,7 @@ export default class ClassNameCache {
279285 }
280286
281287 Cache . classNameCache . setByKey ( importPath , classNames ) ;
282- Cache . saveCache ( ) ;
288+ Cache . saveCache ( ) . catch ( console . error ) ;
283289 return classNames ;
284290 }
285291}
0 commit comments