Skip to content

Commit f3d44c8

Browse files
fix: minor bugs
1 parent c9ec341 commit f3d44c8

10 files changed

Lines changed: 36 additions & 31 deletions

File tree

docs/PROJECT_STRUCTURE.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ css-modules-intellisense/
3333
│ │ ├── classNameCache.ts # Class name caching
3434
│ │ ├── cssModuleDependencyCache.ts
3535
│ │ ├── loadCaches.ts # Cache initialization
36-
│ │ └── processConfig.ts # Configuration processing
36+
│ │ ├── processConfig.ts # Configuration processing
37+
│ │ └── vsConfig.ts # VS Code configuration helpers
3738
│ ├── providers/ # Language feature providers
3839
│ │ ├── completionProvider.ts # Auto-completion
3940
│ │ ├── definitionProvider.ts # Go-to-definition
@@ -70,6 +71,7 @@ css-modules-intellisense/
7071
│ └── scss.tmLanguage.json
7172
├── .editorconfig # Editor configuration
7273
├── .gitignore # Git ignore rules
74+
├── .prettierrc # Prettier formatting rules
7375
├── .markdownlint.json # Markdown linting rules
7476
├── .vscode-test.mjs # VS Code test configuration
7577
├── .vscodeignore # Files to exclude from extension package
@@ -120,6 +122,7 @@ Static resources including test fixtures and extension icons
120122
## Configuration Files
121123

122124
- `.editorconfig` - Code style consistency
125+
- `.prettierrc` - Code formatting rules
123126
- `tsconfig.json` - TypeScript compiler settings
124127
- `eslint.config.mjs` - Linting rules
125128
- `package.json` - Extension metadata and dependencies

src/libs/classNameCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default class ClassNameCache {
4343
for (const workspacePath of dependents) {
4444
const resolvedPath = resolveWorkspaceRelativePath(workspacePath);
4545
if (!resolvedPath) {
46-
return;
46+
continue;
4747
}
4848
const document = await vscode.workspace.openTextDocument(
4949
resolvedPath

src/libs/processConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
22
import { CONFIGURATION_KEY, CONFIGURATIONS } from "../config";
3+
import { getVsConfig } from "./vsConfig";
34

45
function registerConditionalListener<T>(
56
event: vscode.Event<T>,
@@ -9,8 +10,7 @@ function registerConditionalListener<T>(
910
let disposable: vscode.Disposable | undefined;
1011

1112
const applyConfig = () => {
12-
const config = vscode.workspace.getConfiguration(CONFIGURATION_KEY);
13-
const enabled = config.get<boolean>(settingKey, true);
13+
const enabled = getVsConfig().get<boolean>(settingKey, true);
1414

1515
if (enabled && !disposable) {
1616
disposable = event(func);

src/libs/vsConfig.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as vscode from "vscode";
2+
import { CONFIGURATION_KEY, CONFIGURATIONS } from "../config";
3+
4+
export const getVsConfig = () =>
5+
vscode.workspace.getConfiguration(CONFIGURATION_KEY);
6+
7+
export const getAliasMap = (): Record<string, string> =>
8+
getVsConfig().get<Record<string, string>>(CONFIGURATIONS.ALIASES, {});
9+
10+
export const getBlacklistPatterns = (): string[] =>
11+
getVsConfig().get<string[]>(CONFIGURATIONS.BLACKLIST_PATTERNS, []);

src/providers/completionProvider.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from "vscode";
2-
import { CONFIGURATION_KEY, CONFIGURATIONS, MESSAGES } from "../config";
2+
import { MESSAGES } from "../config";
33
import ClassNameCache from "../libs/classNameCache";
44
import isPositionInString from "../utils/isPositionInString";
55
import getImportModulePath from "../utils/getImportModulePath";
@@ -9,11 +9,6 @@ import { getWorkspaceRelativeImportPath } from "../utils/getPath";
99
export default class CompletionItemProvider
1010
implements vscode.CompletionItemProvider
1111
{
12-
static config = vscode.workspace.getConfiguration(CONFIGURATION_KEY);
13-
static aliasMap = CompletionItemProvider.config.get<Record<string, string>>(
14-
CONFIGURATIONS.ALIASES,
15-
{}
16-
);
1712

1813
provideCompletionItems = async (
1914
document: vscode.TextDocument,

src/providers/definitionProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class ModuleDefinitionProvider implements vscode.DefinitionProvider {
9696
}
9797

9898
const className = cssDoc.getText(wordRange).slice(1); // remove leading dot
99-
const cssPath = resolveImportPathWithAliases(cssDoc, cssDoc.uri.path);
99+
const cssPath = resolveImportPathWithAliases(cssDoc, cssDoc.uri.fsPath);
100100
if (!fs.existsSync(cssPath)) {
101101
return;
102102
}

src/providers/renameProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const provideRenameEdits = async ({
4141
const resolvedPath = resolveImportPathWithAliases(doc, match[2]);
4242

4343
if (resolvedPath !== filePath) {
44-
return;
44+
continue;
4545
}
4646

4747
const classNamePositions = await getDataOfClassName(

src/types/cache.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export class PathMapCache extends Array<string> {
3939
});
4040
}
4141

42+
hasKey(key: string): boolean {
43+
return this.reverseMap.has(key);
44+
}
45+
4246
getKeyFormIndex(index: number) {
4347
return this[index];
4448
}
@@ -95,8 +99,11 @@ class BaseCache<V extends {}, FC = unknown> {
9599
}
96100

97101
hasByKey(key: string): boolean {
98-
const keyIndex = this.pathMapCache.getIndexFormKey(key);
99-
return this.has(keyIndex);
102+
if (!this.pathMapCache.hasKey(key)) {
103+
return false;
104+
}
105+
106+
return this.has(this.pathMapCache.getIndexFormKey(key));
100107
}
101108

102109
getByKey(key: string) {
@@ -110,7 +117,7 @@ class BaseCache<V extends {}, FC = unknown> {
110117
}
111118

112119
setMap(entries: readonly (readonly [string, V])[]) {
113-
this.clear;
120+
this.clear();
114121
entries.forEach((entry) => {
115122
this.setByKey(entry[0], entry[1]);
116123
});

src/utils/getAllFiles.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,11 @@ import {
33
getModuleFileRegex,
44
getScriptFileRegex,
55
} from "./getFileExtensionRegex";
6-
import { CONFIGURATION_KEY, CONFIGURATIONS } from "../config";
7-
8-
const config = vscode.workspace.getConfiguration(CONFIGURATION_KEY);
9-
const blacklistPatterns = config.get<string[]>(
10-
CONFIGURATIONS.BLACKLIST_PATTERNS,
11-
[]
12-
);
6+
import { getBlacklistPatterns } from "../libs/vsConfig";
137

148
export const getAllScriptFiles = async () => {
159
const includePattern = `**/*.{${getScriptFileRegex()}}`;
16-
17-
const excludePattern = `{${blacklistPatterns.join(",")}}`;
10+
const excludePattern = `{${getBlacklistPatterns().join(",")}}`;
1811

1912
const files = await vscode.workspace.findFiles(
2013
includePattern,
@@ -26,8 +19,7 @@ export const getAllScriptFiles = async () => {
2619

2720
export const getAllModuleFiles = async () => {
2821
const includePattern = `**/*.module.{${getModuleFileRegex(",")}}`;
29-
30-
const excludePattern = `{${blacklistPatterns.join(",")}}`;
22+
const excludePattern = `{${getBlacklistPatterns().join(",")}}`;
3123

3224
const files = await vscode.workspace.findFiles(
3325
includePattern,

src/utils/getPath.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import * as path from "path";
22
import * as vscode from "vscode";
3-
import { CONFIGURATION_KEY, CONFIGURATIONS } from "../config";
4-
5-
// Load alias configuration from workspace settings
6-
const config = vscode.workspace.getConfiguration(CONFIGURATION_KEY);
7-
const aliasMap = config.get<Record<string, string>>(CONFIGURATIONS.ALIASES, {});
3+
import { getAliasMap } from "../libs/vsConfig";
84

95
/**
106
* Resolves an import path by checking configured aliases and falling back to relative resolution from the current document.
@@ -24,6 +20,7 @@ export const resolveImportPathWithAliases = (
2420

2521
const workspaceRoot = workspaceFolders[0].uri.fsPath;
2622
let resolvedPath = importPath;
23+
const aliasMap = getAliasMap();
2724

2825
// Replace alias with absolute path if match is found
2926
for (const [alias, aliasRelativePath] of Object.entries(aliasMap)) {

0 commit comments

Comments
 (0)