Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added

- `cssModulesIntellisense.classNameCacheSize` setting to configure the LRU
class name cache size (default: 5).

### Fixed

- Minor Bugs
Expand Down
5 changes: 1 addition & 4 deletions docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,4 @@

## Future Improvements

- Add an extension setting to configure the class name cache size (LRU max entries).
Currently hardcoded to 3, which causes frequent cache evictions and re-parsing
in projects with more than 3 CSS module files. Should be user-configurable via
`cssModules.classNameCacheSize` in extension settings.
<!-- Add future improvements here -->
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@
"**/*.test.ts",
"**/*.spec.tsx"
]
},
"cssModulesIntellisense.classNameCacheSize": {
"type": "number",
"description": "Maximum number of CSS module files to keep in the class name cache (LRU). Increase for projects with many CSS module files.",
"default": 5,
"minimum": 1
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export const CONFIGURATIONS = {
BLACKLIST_PATTERNS: "blacklistPatterns",
PROCESS_ON_EDIT: "processOnEdit",
PROCESS_ON_SAVE: "processOnSave",
CLASS_NAME_CACHE_SIZE: "classNameCacheSize",
};

export const DEFAULT_CLASS_NAME_CACHE_SIZE = 5;

export const CSS_MODULES_CACHE_FILENAME = "cache.json";
5 changes: 4 additions & 1 deletion src/libs/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import * as path from "path";
import type * as vscode from "vscode";
import { CSS_MODULES_CACHE_FILENAME, DEBOUNCE_TIMER } from "../config";
import { getClassNameCacheSize } from "./vsConfig";
import {
type CacheJsonObject,
ClassNameCache,
Expand All @@ -24,7 +25,9 @@
* Cache mapping from imported CSS module paths (relative to workspace)
* to the set of document paths that import them.
*/
static classNameCache = new ClassNameCache(this.pathMapCache, { max: 3 });
static classNameCache = new ClassNameCache(this.pathMapCache, {
max: getClassNameCacheSize(),
});

private static _context: vscode.ExtensionContext;
/**
Expand Down Expand Up @@ -139,7 +142,7 @@

try {
const raw = fs.readFileSync(cacheFilePath, "utf-8");
const parsed: { [K in keyof CacheJsonObject]?: CacheJsonObject[K] } =

Check warning on line 145 in src/libs/cache.ts

View workflow job for this annotation

GitHub Actions / test (1.98.0)

Unsafe assignment of an `any` value

Check warning on line 145 in src/libs/cache.ts

View workflow job for this annotation

GitHub Actions / test (1.94.0)

Unsafe assignment of an `any` value

Check warning on line 145 in src/libs/cache.ts

View workflow job for this annotation

GitHub Actions / test (1.95.0)

Unsafe assignment of an `any` value

Check warning on line 145 in src/libs/cache.ts

View workflow job for this annotation

GitHub Actions / test (1.92.0)

Unsafe assignment of an `any` value

Check warning on line 145 in src/libs/cache.ts

View workflow job for this annotation

GitHub Actions / test (1.99.0)

Unsafe assignment of an `any` value

Check warning on line 145 in src/libs/cache.ts

View workflow job for this annotation

GitHub Actions / test (1.97.0)

Unsafe assignment of an `any` value

Check warning on line 145 in src/libs/cache.ts

View workflow job for this annotation

GitHub Actions / test (1.96.0)

Unsafe assignment of an `any` value

Check warning on line 145 in src/libs/cache.ts

View workflow job for this annotation

GitHub Actions / test (1.100.0)

Unsafe assignment of an `any` value

Check warning on line 145 in src/libs/cache.ts

View workflow job for this annotation

GitHub Actions / test (1.101.0)

Unsafe assignment of an `any` value

Check warning on line 145 in src/libs/cache.ts

View workflow job for this annotation

GitHub Actions / test (1.102.0)

Unsafe assignment of an `any` value

Check warning on line 145 in src/libs/cache.ts

View workflow job for this annotation

GitHub Actions / test (1.104.0)

Unsafe assignment of an `any` value

Check warning on line 145 in src/libs/cache.ts

View workflow job for this annotation

GitHub Actions / test (1.103.0)

Unsafe assignment of an `any` value

Check warning on line 145 in src/libs/cache.ts

View workflow job for this annotation

GitHub Actions / test (1.93.0)

Unsafe assignment of an `any` value

Check warning on line 145 in src/libs/cache.ts

View workflow job for this annotation

GitHub Actions / test (1.105.0)

Unsafe assignment of an `any` value
JSON.parse(raw);

this.pathMapCache.setArray(parsed.pathMapCache ?? []);
Expand Down
12 changes: 11 additions & 1 deletion src/libs/vsConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as vscode from "vscode";
import { CONFIGURATION_KEY, CONFIGURATIONS } from "../config";
import {
CONFIGURATION_KEY,
CONFIGURATIONS,
DEFAULT_CLASS_NAME_CACHE_SIZE,
} from "../config";

export const getVsConfig = () =>
vscode.workspace.getConfiguration(CONFIGURATION_KEY);
Expand All @@ -9,3 +13,9 @@ export const getAliasMap = (): Record<string, string> =>

export const getBlacklistPatterns = (): string[] =>
getVsConfig().get<string[]>(CONFIGURATIONS.BLACKLIST_PATTERNS, []);

export const getClassNameCacheSize = (): number =>
getVsConfig().get<number>(
CONFIGURATIONS.CLASS_NAME_CACHE_SIZE,
DEFAULT_CLASS_NAME_CACHE_SIZE
);
Loading