Skip to content

Commit e824e09

Browse files
Merge pull request #11 from Lokesh-Garg-22/dev
Dev
2 parents 72f09a5 + f7a2120 commit e824e09

14 files changed

Lines changed: 235 additions & 106 deletions

.github/workflows/tests.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: CI / Build & Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest # Or windows-latest, macos-latest
14+
15+
strategy:
16+
fail-fast: false # Don't cancel other jobs if one fails
17+
matrix:
18+
vscode_version:
19+
- 1.92.0
20+
- 1.93.0
21+
- 1.94.0
22+
- 1.95.0
23+
- 1.96.0
24+
- 1.97.0
25+
- 1.98.0
26+
- 1.99.0
27+
- 1.100.0
28+
- 1.101.0
29+
- 1.102.0
30+
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- name: Use Node.js
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version: "20" # Or your project's Node.js version
38+
39+
- name: Install dependencies
40+
run: npm ci
41+
42+
# Step to install xvfb
43+
- name: Install xvfb
44+
run: sudo apt-get update && sudo apt-get install -y xvfb
45+
46+
- name: Compile Extension
47+
run: npm run pretest
48+
49+
# Define your test workspace folder relative to the repository root
50+
# You can have multiple test workspaces and dynamically select them if needed
51+
- name: Set test workspace folder
52+
id: test_workspace
53+
run: echo "WORKSPACE_PATH=." >> $GITHUB_OUTPUT # Adjust this path to your actual test workspace folder
54+
55+
- name: Run VS Code Extension Tests
56+
run: |
57+
xvfb-run -a \
58+
./node_modules/.bin/vscode-test \
59+
--vscode-version ${{ matrix.vscode_version }} \
60+
--extensionDevelopmentPath ./ \
61+
--extensionTestsPath dist/test/extension.test.js \
62+
--launch-args "${{ steps.test_workspace.outputs.WORKSPACE_PATH }}" \
63+
--launch-args "--disable-extensions" \
64+
--launch-args "--skip-getting-started"
65+
env:
66+
CI: true # Indicate that we are in a CI environment

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

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

5+
## [0.1.3] – 2025-07-30
6+
7+
### Fixed
8+
9+
- Inefficiencies in `isPositionInComment` and `isPositionInString` that caused
10+
slow parsing in large files.
11+
512
## [0.1.2] – 2025-07-18
613

714
### Added
@@ -90,6 +97,7 @@ All notable changes to this project will be documented in this file.
9097
- Go-to-Definition support for `styles.className` references.
9198
- Autocompletion of class names in JavaScript and TypeScript.
9299

100+
[0.1.3]: https://github.com/Lokesh-Garg-22/CSS-Modules-IntelliSense/compare/v0.1.2...v0.1.3
93101
[0.1.2]: https://github.com/Lokesh-Garg-22/CSS-Modules-IntelliSense/compare/v0.1.1...v0.1.2
94102
[0.1.1]: https://github.com/Lokesh-Garg-22/CSS-Modules-IntelliSense/compare/v0.1.0...v0.1.1
95103
[0.1.0]: https://github.com/Lokesh-Garg-22/CSS-Modules-IntelliSense/compare/v0.0.5...v0.1.0

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "css-scss-modules-intellisense",
33
"displayName": "CSS/SCSS Modules IntelliSense",
44
"description": "Linter and tooling for CSS Modules with support for SCSS, LESS, Go-to-Definition, and Rename in JS/TS files.",
5-
"version": "0.1.2",
5+
"version": "0.1.3",
66
"publisher": "lokesh-garg",
77
"repository": {
88
"type": "git",

src/providers/completionProvider.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ export default class CompletionItemProvider
1919
document: vscode.TextDocument,
2020
position: vscode.Position
2121
) => {
22-
if (
23-
(await isPositionInString(document, position)) ||
24-
(await isPositionInComment(document, position))
25-
) {
26-
return;
27-
}
28-
2922
const importModulePath = getImportModulePath(document, position);
3023
if (!importModulePath) {
3124
return;
@@ -37,6 +30,14 @@ export default class CompletionItemProvider
3730
if (!classNames) {
3831
return;
3932
}
33+
34+
if (
35+
(await isPositionInString(document, position)) ||
36+
(await isPositionInComment(document, position))
37+
) {
38+
return;
39+
}
40+
4041
return new vscode.CompletionList(
4142
classNames.map((name) => {
4243
const item = new vscode.CompletionItem(

src/providers/definitionProvider.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ export class ScriptDefinitionProvider implements vscode.DefinitionProvider {
4747
document: vscode.TextDocument,
4848
position: vscode.Position
4949
): Promise<vscode.LocationLink[] | undefined> => {
50-
// Skip strings and comments early
51-
if (
52-
(await isPositionInString(document, position)) ||
53-
(await isPositionInComment(document, position))
54-
) {
55-
return;
56-
}
57-
5850
const wordRange = document.getWordRangeAtPosition(position, /\w+/);
5951
if (!wordRange) {
6052
return;
@@ -71,6 +63,14 @@ export class ScriptDefinitionProvider implements vscode.DefinitionProvider {
7163
return;
7264
}
7365

66+
// Skip strings and comments
67+
if (
68+
(await isPositionInString(document, position)) ||
69+
(await isPositionInComment(document, position))
70+
) {
71+
return;
72+
}
73+
7474
const cssDoc = await vscode.workspace.openTextDocument(cssPath);
7575
const locations: vscode.LocationLink[] = [];
7676

@@ -90,14 +90,6 @@ export class ModuleDefinitionProvider implements vscode.DefinitionProvider {
9090
cssDoc: vscode.TextDocument,
9191
position: vscode.Position
9292
): Promise<vscode.LocationLink[] | undefined> => {
93-
if (
94-
(await isPositionInString(cssDoc, position)) ||
95-
(await isPositionInComment(cssDoc, position)) ||
96-
!isDocumentModule(cssDoc)
97-
) {
98-
return;
99-
}
100-
10193
const wordRange = cssDoc.getWordRangeAtPosition(position, /\.[\w-]+/);
10294
if (!wordRange) {
10395
return;
@@ -109,6 +101,14 @@ export class ModuleDefinitionProvider implements vscode.DefinitionProvider {
109101
return;
110102
}
111103

104+
if (
105+
(await isPositionInString(cssDoc, position)) ||
106+
(await isPositionInComment(cssDoc, position)) ||
107+
!isDocumentModule(cssDoc)
108+
) {
109+
return;
110+
}
111+
112112
const locations: vscode.LocationLink[] = [];
113113

114114
// Add definitions in the current CSS module

src/providers/renameProvider.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const provideRenameEdits = async ({
3636
);
3737
const matches = await getAllImportModulePaths(doc);
3838

39-
matches.forEach(async (match) => {
39+
for (const match of matches) {
4040
const varName = match[1];
4141
const resolvedPath = resolveImportPathWithAliases(doc, match[2]);
4242

@@ -53,7 +53,7 @@ const provideRenameEdits = async ({
5353
classNamePositions.forEach((classNamePosition) => {
5454
edit.replace(doc.uri, classNamePosition.range, newName);
5555
});
56-
});
56+
}
5757
}
5858

5959
// Update the Css Module File
@@ -80,13 +80,6 @@ export class ScriptsRenameProvider implements vscode.RenameProvider {
8080
position: vscode.Position,
8181
newName: string
8282
) => {
83-
if (
84-
(await isPositionInString(document, position)) ||
85-
(await isPositionInComment(document, position))
86-
) {
87-
return;
88-
}
89-
9083
const wordRange = document.getWordRangeAtPosition(position, /\w+/);
9184
if (!wordRange) {
9285
return;
@@ -106,6 +99,13 @@ export class ScriptsRenameProvider implements vscode.RenameProvider {
10699
return;
107100
}
108101

102+
if (
103+
(await isPositionInString(document, position)) ||
104+
(await isPositionInComment(document, position))
105+
) {
106+
return;
107+
}
108+
109109
const cssDoc = await vscode.workspace.openTextDocument(cssFilePath);
110110

111111
return await provideRenameEdits({
@@ -119,13 +119,6 @@ export class ScriptsRenameProvider implements vscode.RenameProvider {
119119
document: vscode.TextDocument,
120120
position: vscode.Position
121121
) => {
122-
if (
123-
(await isPositionInString(document, position)) ||
124-
(await isPositionInComment(document, position))
125-
) {
126-
return;
127-
}
128-
129122
const wordRange = document.getWordRangeAtPosition(position, /\w+/);
130123
if (!wordRange) {
131124
return;
@@ -137,6 +130,13 @@ export class ScriptsRenameProvider implements vscode.RenameProvider {
137130
return;
138131
}
139132

133+
if (
134+
(await isPositionInString(document, position)) ||
135+
(await isPositionInComment(document, position))
136+
) {
137+
return;
138+
}
139+
140140
return (await ClassNameCache.hasClassNameFromImportPath(
141141
className,
142142
getWorkspaceRelativeImportPath(document, importModulePath)
@@ -152,14 +152,6 @@ export class ModulesRenameProvider implements vscode.RenameProvider {
152152
position: vscode.Position,
153153
newName: string
154154
) => {
155-
if (
156-
(await isPositionInString(document, position)) ||
157-
(await isPositionInComment(document, position)) ||
158-
!isDocumentModule(document)
159-
) {
160-
return;
161-
}
162-
163155
const wordRange = document.getWordRangeAtPosition(
164156
position,
165157
/\.[a-zA-Z0-9_-]+/
@@ -168,6 +160,14 @@ export class ModulesRenameProvider implements vscode.RenameProvider {
168160
return;
169161
}
170162

163+
if (
164+
(await isPositionInString(document, position)) ||
165+
(await isPositionInComment(document, position)) ||
166+
!isDocumentModule(document)
167+
) {
168+
return;
169+
}
170+
171171
const oldClassName = document.getText(wordRange).replace(/^\./, "");
172172

173173
return await provideRenameEdits({ document, oldClassName, newName });

src/test/extension.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ suite("Extension Tests", () => {
99
assert.ok(ext?.isActive);
1010
});
1111

12-
test("Run Command Reset Cache", async () => {
12+
test("Run Command Reset Cache", async function () {
13+
this.timeout(10000);
1314
const result = await vscode.commands.executeCommand(
1415
"css-scss-modules-intellisense.resetCache"
1516
);

src/test/providers/renameProvider.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ suite("Rename Provider Tests", function () {
8080
for (const expectedPath of expectedPaths) {
8181
assert.ok(
8282
seenPaths.has(expectedPath),
83-
`Expected rename to edit file: ${expectedPath}`
83+
`Expected rename provider to edit file: ${expectedPath}`
8484
);
8585
}
8686
});
@@ -145,7 +145,7 @@ suite("Rename Provider Tests", function () {
145145
for (const expectedPath of expectedPaths) {
146146
assert.ok(
147147
seenPaths.has(expectedPath),
148-
`Expected rename to edit file: ${expectedPath}`
148+
`Expected rename provider to edit file: ${expectedPath}`
149149
);
150150
}
151151
});

src/utils/getAllClassNames.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ const getAllClassNames = async (
2727
const className = match[1];
2828
const pos = document.positionAt(match.index);
2929

30-
// Skip matches inside strings or comments
30+
// Reject nested usage like temp.styles.class
3131
if (
32-
(await isPositionInString(document, pos)) ||
33-
(await isPositionInComment(document, pos))
32+
pos.character > 0 &&
33+
document.lineAt(pos.line).text[pos.character - 1].match(/[.\w]$/)
3434
) {
3535
continue;
3636
}
3737

38-
// Reject nested usage like temp.styles.class
38+
// Skip matches inside strings or comments
3939
if (
40-
pos.character > 0 &&
41-
document.lineAt(pos.line).text[pos.character - 1].match(/[.\w]$/)
40+
(await isPositionInString(document, pos)) ||
41+
(await isPositionInComment(document, pos))
4242
) {
4343
continue;
4444
}

0 commit comments

Comments
 (0)