Skip to content

Commit 55cb402

Browse files
chore: updated changelog and various other files
1 parent 8fcd2df commit 55cb402

20 files changed

Lines changed: 249 additions & 230 deletions

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## [Unreleased] – 2025-08-XX
5+
## [0.1.4] – 2025-11-07
66

77
### Added
88

@@ -117,7 +117,7 @@ All notable changes to this project will be documented in this file.
117117
- Go-to-Definition support for `styles.className` references.
118118
- Autocompletion of class names in JavaScript and TypeScript.
119119

120-
[unreleased]: https://github.com/Lokesh-Garg-22/CSS-Modules-IntelliSense/compare/v0.1.3...HEAD
120+
[0.1.4]: https://github.com/Lokesh-Garg-22/CSS-Modules-IntelliSense/compare/v0.1.3...v0.1.4
121121
[0.1.3]: https://github.com/Lokesh-Garg-22/CSS-Modules-IntelliSense/compare/v0.1.2...v0.1.3
122122
[0.1.2]: https://github.com/Lokesh-Garg-22/CSS-Modules-IntelliSense/compare/v0.1.1...v0.1.2
123123
[0.1.1]: https://github.com/Lokesh-Garg-22/CSS-Modules-IntelliSense/compare/v0.1.0...v0.1.1

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ export const CONFIGURATIONS = {
5353
PROCESS_ON_EDIT: "processOnEdit",
5454
PROCESS_ON_SAVE: "processOnSave",
5555
};
56+
57+
export const CSS_MODULES_CACHE_FILENAME = "cache.json";

src/extension.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import * as vscode from "vscode";
22
import { SUPPORTED_LANGS, SUPPORTED_MODULES } from "./config";
3-
import {
4-
ModulesRenameProvider,
5-
ScriptsRenameProvider,
6-
} from "./providers/renameProvider";
3+
import Cache from "./libs/cache";
4+
import loadCaches from "./libs/loadCaches";
5+
import CheckDocument from "./libs/checkDocument";
6+
import { registerTriggerOnEdit } from "./libs/processConfig";
7+
import CssModuleDependencyCache from "./libs/cssModuleDependencyCache";
78
import CompletionItemProvider from "./providers/completionProvider";
89
import {
910
ScriptDefinitionProvider,
1011
ModuleDefinitionProvider as ModuleDefinitionProvider,
1112
} from "./providers/definitionProvider";
12-
import Cache from "./libs/cache";
13-
import loadCaches from "./libs/loadCaches";
14-
import CheckDocument from "./libs/checkDocument";
15-
import CssModuleDependencyCache from "./libs/cssModuleDependencyCache";
16-
import { registerTriggerOnEdit } from "./libs/processConfig";
13+
import {
14+
ModulesRenameProvider,
15+
ScriptsRenameProvider,
16+
} from "./providers/renameProvider";
1717

1818
export async function activate(context: vscode.ExtensionContext) {
1919
const diagnosticCollection =

src/libs/cache.ts

Lines changed: 23 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -1,189 +1,15 @@
1-
import * as vscode from "vscode";
21
import * as fs from "fs";
32
import * as path from "path";
4-
import { DEBOUNCE_TIMER } from "../config";
5-
import { LRUCache } from "lru-cache";
6-
7-
type CacheJsonObject = {
8-
pathMapCache: Array<string>;
9-
modulePathCache: Record<number, number[]>;
10-
classNameCache: Record<number, Record<string, ClassNameData[]>>;
11-
};
12-
13-
export type ClassNameData = { range: vscode.Range };
14-
15-
const cacheFile = "cache.json";
16-
17-
export const isLRUCache = <K extends {}, V extends {}, FC = unknown>(
18-
cache: Map<K, V> | LRUCache<K, V, FC>
19-
): cache is LRUCache<K, V, FC> => Object.keys(cache).includes("fetch");
20-
21-
class PathMapCache extends Array<string> {
22-
protected reverseMap = new Map<string, number>();
23-
24-
clear() {
25-
while (this.length) {
26-
this.pop();
27-
}
28-
this.reverseMap.clear();
29-
return this;
30-
}
31-
32-
push(...items: string[]): number {
33-
const length = super.push(...items);
34-
items.forEach((item) => {
35-
this.reverseMap.set(item, this.indexOf(item));
36-
});
37-
return length;
38-
}
39-
40-
setArray(entries: readonly string[]) {
41-
this.clear();
42-
entries.forEach((entry) => {
43-
this.push(entry);
44-
});
45-
}
46-
47-
getKeyFormIndex(index: number) {
48-
return this[index];
49-
}
50-
51-
getIndexFormKey(key: string) {
52-
if (this.reverseMap.has(key)) {
53-
return this.reverseMap.get(key) as NonNullable<
54-
ReturnType<typeof this.reverseMap.get>
55-
>;
56-
}
57-
this.push(key);
58-
return this.reverseMap.get(key) as NonNullable<
59-
ReturnType<typeof this.reverseMap.get>
60-
>;
61-
}
62-
}
63-
64-
class BaseCache<V extends {}, FC = unknown> {
65-
protected cache: Map<number, V> | LRUCache<number, V, FC>;
66-
protected pathMapCache: PathMapCache;
67-
68-
constructor(pathMapCache: PathMapCache, cache: typeof this.cache) {
69-
this.cache = cache;
70-
this.pathMapCache = pathMapCache;
71-
}
72-
73-
clear() {
74-
return this.cache.clear();
75-
}
76-
delete(key: number) {
77-
return this.cache.delete(key);
78-
}
79-
get(key: number) {
80-
return this.cache.get(key);
81-
}
82-
has(key: number) {
83-
return this.cache.has(key);
84-
}
85-
set(key: number, value: V) {
86-
this.cache.set(key, value);
87-
return this;
88-
}
89-
entries() {
90-
return this.cache.entries();
91-
}
92-
keys() {
93-
return this.cache.keys();
94-
}
95-
values() {
96-
return this.cache.values();
97-
}
98-
[Symbol.iterator]() {
99-
return this.cache[Symbol.iterator]();
100-
}
101-
102-
hasByKey(key: string): boolean {
103-
const keyIndex = this.pathMapCache.getIndexFormKey(key);
104-
return this.has(keyIndex);
105-
}
106-
107-
getByKey(key: string) {
108-
const keyIndex = this.pathMapCache.getIndexFormKey(key);
109-
return this.get(keyIndex);
110-
}
111-
112-
setByKey(key: string, value: V): this {
113-
const keyIndex = this.pathMapCache.getIndexFormKey(key);
114-
return this.set(keyIndex, value);
115-
}
116-
117-
setMap(entries: readonly (readonly [string, V])[]) {
118-
this.clear;
119-
entries.forEach((entry) => {
120-
this.setByKey(entry[0], entry[1]);
121-
});
122-
}
123-
124-
deleteByKey(key: string): boolean {
125-
const keyIndex = this.pathMapCache.getIndexFormKey(key);
126-
return this.delete(keyIndex);
127-
}
128-
}
129-
130-
class ModulePathCacheSet extends Set<number> {
131-
protected pathMapCache: PathMapCache;
132-
133-
constructor(pathMapCache: PathMapCache, values?: readonly number[] | null) {
134-
super(values ?? undefined);
135-
this.pathMapCache = pathMapCache;
136-
}
137-
138-
addByKey(value: string): this {
139-
const valueIndex = this.pathMapCache.getIndexFormKey(value);
140-
return this.add(valueIndex);
141-
}
142-
143-
toKeyArray() {
144-
const arr = [...this];
145-
return arr.map((ele) => this.pathMapCache.getKeyFormIndex(ele));
146-
}
147-
}
148-
149-
class ModulePathCache extends BaseCache<ModulePathCacheSet> {
150-
constructor(pathMap: PathMapCache) {
151-
super(pathMap, new Map<number, ModulePathCacheSet>());
152-
}
153-
154-
createKey(key: string) {
155-
const set = new ModulePathCacheSet(this.pathMapCache);
156-
this.setByKey(key, set);
157-
return set;
158-
}
159-
}
160-
161-
export class ClassNameDataMap extends Map<string, ClassNameData[]> {
162-
add(key: string, value: ClassNameData) {
163-
if (this.has(key)) {
164-
const arr = this.get(key)!;
165-
arr.push(value);
166-
} else {
167-
const arr = [value];
168-
this.set(key, arr);
169-
}
170-
return this;
171-
}
172-
}
173-
174-
class ClassNameCache extends BaseCache<ClassNameDataMap> {
175-
constructor(
176-
pathMap: PathMapCache,
177-
options:
178-
| LRUCache<number, ClassNameDataMap>
179-
| LRUCache.Options<number, ClassNameDataMap, unknown>
180-
) {
181-
const lruCache: ConstructorParameters<
182-
typeof BaseCache<ClassNameDataMap>
183-
>[1] = new LRUCache(options);
184-
super(pathMap, lruCache);
185-
}
186-
}
3+
import * as vscode from "vscode";
4+
import { CSS_MODULES_CACHE_FILENAME, DEBOUNCE_TIMER } from "../config";
5+
import {
6+
CacheJsonObject,
7+
ClassNameCache,
8+
ClassNameRangeMap,
9+
ModulePathCache,
10+
ModulePathCacheSet,
11+
PathMapCache,
12+
} from "../types/cache";
18713

18814
export default class Cache {
18915
static pathMapCache = new PathMapCache();
@@ -220,7 +46,10 @@ export default class Cache {
22046
this.classNameCache.clear();
22147
this.pathMapCache.clear();
22248

223-
const cacheFilePath = path.join(this.context.storageUri.fsPath, cacheFile);
49+
const cacheFilePath = path.join(
50+
this.context.storageUri.fsPath,
51+
CSS_MODULES_CACHE_FILENAME
52+
);
22453
const cacheAsObject: CacheJsonObject = {
22554
pathMapCache: [],
22655
modulePathCache: {},
@@ -259,7 +88,10 @@ export default class Cache {
25988
return false;
26089
}
26190

262-
const cacheFilePath = path.join(this.context.storageUri.fsPath, cacheFile);
91+
const cacheFilePath = path.join(
92+
this.context.storageUri.fsPath,
93+
CSS_MODULES_CACHE_FILENAME
94+
);
26395
const cacheAsObject: CacheJsonObject = {
26496
pathMapCache: [],
26597
modulePathCache: {},
@@ -297,7 +129,10 @@ export default class Cache {
297129
return false;
298130
}
299131

300-
const cacheFilePath = path.join(this.context.storageUri.fsPath, cacheFile);
132+
const cacheFilePath = path.join(
133+
this.context.storageUri.fsPath,
134+
CSS_MODULES_CACHE_FILENAME
135+
);
301136
if (!fs.existsSync(cacheFilePath)) {
302137
return false;
303138
}
@@ -321,7 +156,7 @@ export default class Cache {
321156
this.classNameCache.setMap(
322157
Object.entries(parsed.classNameCache || {}).map(([key, value]) => [
323158
key,
324-
new ClassNameDataMap(Object.entries(value)),
159+
new ClassNameRangeMap(Object.entries(value)),
325160
])
326161
);
327162
} catch (error) {

src/libs/checkDocument.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import {
66
MESSAGES,
77
SUPPORTED_LANGS,
88
} from "../config";
9-
import ClassNameCache from "./classNameCache";
109
import {
1110
getWorkspaceRelativeImportPath,
1211
resolveImportPathWithAliases,
1312
} from "../utils/getPath";
14-
import getAllImportModulePaths from "../utils/getAllImportModulePaths";
1513
import getAllClassNames from "../utils/getAllClassNames";
14+
import getAllImportModulePaths from "../utils/getAllImportModulePaths";
15+
import ClassNameCache from "./classNameCache";
1616

1717
/**
1818
* Class responsible for analyzing script documents to validate usage of CSS Modules.

src/libs/classNameCache.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import * as fs from "fs";
22
import * as vscode from "vscode";
33
import safeParser from "postcss-safe-parser";
44
import selectorParser from "postcss-selector-parser";
5-
import Cache, { ClassNameData, ClassNameDataMap } from "./cache";
5+
import { DEBOUNCE_TIMER, SUPPORTED_MODULES } from "../config";
6+
import Cache from "./cache";
67
import {
78
getWorkspaceRelativeUriPath,
89
resolveWorkspaceRelativePath,
910
} from "../utils/getPath";
10-
import { DEBOUNCE_TIMER, SUPPORTED_MODULES } from "../config";
11+
import { sanitizeCssInput } from "../utils/sanitizeCssInput";
1112
import isPositionInComment from "../utils/isPositionInComment";
1213
import CssModuleDependencyCache from "./cssModuleDependencyCache";
1314
import CheckDocument from "./checkDocument";
14-
import { sanitizeCssInput } from "../utils/sanitizeCssInput";
15+
import { ClassNameRange, ClassNameRangeMap } from "../types/cache";
1516

1617
/**
1718
* A utility class to extract and cache class names from CSS Module files.
@@ -137,7 +138,7 @@ export default class ClassNameCache {
137138
static async getClassNameDataFromImportPath(
138139
className: string,
139140
importPath: string
140-
): Promise<ClassNameData[] | undefined> {
141+
): Promise<ClassNameRange[] | undefined> {
141142
if (Cache.classNameCache.hasByKey(importPath)) {
142143
return Cache.classNameCache.getByKey(importPath)?.get(className);
143144
} else {
@@ -209,7 +210,7 @@ export default class ClassNameCache {
209210
*/
210211
static async extractAndCacheClassNames(
211212
importPath: string
212-
): Promise<ClassNameDataMap | undefined> {
213+
): Promise<ClassNameRangeMap | undefined> {
213214
const filePath = resolveWorkspaceRelativePath(importPath);
214215
if (!fs.existsSync(filePath)) {
215216
Cache.classNameCache.deleteByKey(importPath); // Clean up stale entries
@@ -224,7 +225,7 @@ export default class ClassNameCache {
224225
const content = document.getText();
225226
const sanitizedContent = sanitizeCssInput(content);
226227
const root = safeParser(sanitizedContent);
227-
const classNames = new ClassNameDataMap();
228+
const classNames = new ClassNameRangeMap();
228229
const rules: Parameters<Parameters<(typeof root)["walkRules"]>[0]>[0][] =
229230
[];
230231

@@ -257,7 +258,7 @@ export default class ClassNameCache {
257258
new vscode.Position(ruleStart.line - 1, ruleStart.column - 1)
258259
) + sourceIndex;
259260

260-
const data: ClassNameData = {
261+
const data: ClassNameRange = {
261262
range: new vscode.Range(
262263
document.positionAt(selectorOffsetInDoc),
263264
document.positionAt(selectorOffsetInDoc + value.length + 1) // +1 for "."

src/libs/cssModuleDependencyCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as fs from "fs";
22
import * as vscode from "vscode";
33
import Cache from "./cache";
4+
import { SUPPORTED_LANGS } from "../config";
45
import {
56
getWorkspaceRelativeImportPath,
67
getWorkspaceRelativeUriPath,
78
resolveImportPathWithAliases,
89
} from "../utils/getPath";
9-
import { SUPPORTED_LANGS } from "../config";
1010
import { getAllScriptFiles } from "../utils/getAllFiles";
1111
import { getModuleFileRegex } from "../utils/getFileExtensionRegex";
1212

src/libs/loadCaches.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from "vscode";
2-
import CssModuleDependencyCache from "./cssModuleDependencyCache";
32
import ClassNameCache from "./classNameCache";
3+
import CssModuleDependencyCache from "./cssModuleDependencyCache";
44
import { registerTriggerOnEdit, registerTriggerOnSave } from "./processConfig";
55

66
const loadCaches = () => {

0 commit comments

Comments
 (0)