Skip to content

Commit e92e315

Browse files
feat: added configurable class name cache size (#22)
1 parent ee36442 commit e92e315

6 files changed

Lines changed: 30 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- `cssModulesIntellisense.classNameCacheSize` setting to configure the LRU
10+
class name cache size (default: 5).
11+
712
### Fixed
813

914
- Minor Bugs

docs/TODO.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,4 @@
2020

2121
## Future Improvements
2222

23-
- Add an extension setting to configure the class name cache size (LRU max entries).
24-
Currently hardcoded to 3, which causes frequent cache evictions and re-parsing
25-
in projects with more than 3 CSS module files. Should be user-configurable via
26-
`cssModules.classNameCacheSize` in extension settings.
23+
<!-- Add future improvements here -->

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@
8383
"**/*.test.ts",
8484
"**/*.spec.tsx"
8585
]
86+
},
87+
"cssModulesIntellisense.classNameCacheSize": {
88+
"type": "number",
89+
"description": "Maximum number of CSS module files to keep in the class name cache (LRU). Increase for projects with many CSS module files.",
90+
"default": 5,
91+
"minimum": 1
8692
}
8793
}
8894
},

src/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export const CONFIGURATIONS = {
5252
BLACKLIST_PATTERNS: "blacklistPatterns",
5353
PROCESS_ON_EDIT: "processOnEdit",
5454
PROCESS_ON_SAVE: "processOnSave",
55+
CLASS_NAME_CACHE_SIZE: "classNameCacheSize",
5556
};
5657

58+
export const DEFAULT_CLASS_NAME_CACHE_SIZE = 5;
59+
5760
export const CSS_MODULES_CACHE_FILENAME = "cache.json";

src/libs/cache.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as fs from "fs";
22
import * as path from "path";
33
import type * as vscode from "vscode";
44
import { CSS_MODULES_CACHE_FILENAME, DEBOUNCE_TIMER } from "../config";
5+
import { getClassNameCacheSize } from "./vsConfig";
56
import {
67
type CacheJsonObject,
78
ClassNameCache,
@@ -24,7 +25,9 @@ export default class Cache {
2425
* Cache mapping from imported CSS module paths (relative to workspace)
2526
* to the set of document paths that import them.
2627
*/
27-
static classNameCache = new ClassNameCache(this.pathMapCache, { max: 3 });
28+
static classNameCache = new ClassNameCache(this.pathMapCache, {
29+
max: getClassNameCacheSize(),
30+
});
2831

2932
private static _context: vscode.ExtensionContext;
3033
/**

src/libs/vsConfig.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import * as vscode from "vscode";
2-
import { CONFIGURATION_KEY, CONFIGURATIONS } from "../config";
2+
import {
3+
CONFIGURATION_KEY,
4+
CONFIGURATIONS,
5+
DEFAULT_CLASS_NAME_CACHE_SIZE,
6+
} from "../config";
37

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

1014
export const getBlacklistPatterns = (): string[] =>
1115
getVsConfig().get<string[]>(CONFIGURATIONS.BLACKLIST_PATTERNS, []);
16+
17+
export const getClassNameCacheSize = (): number =>
18+
getVsConfig().get<number>(
19+
CONFIGURATIONS.CLASS_NAME_CACHE_SIZE,
20+
DEFAULT_CLASS_NAME_CACHE_SIZE
21+
);

0 commit comments

Comments
 (0)