Skip to content

Commit 9c685b3

Browse files
authored
Merge pull request #11 from wkillerud/feat/find-all
feature: find all references
2 parents db21881 + 2ce8b73 commit 9c685b3

28 files changed

+1252
-108
lines changed

.editorconfig

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ root = true
33

44
[*]
55
indent_style = tab
6-
indent_size = 4
76
end_of_line = lf
87
charset = utf-8
98
trim_trailing_whitespace = true

.github/workflows/pull_request.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,10 @@ jobs:
3434
if: runner.os == 'Linux'
3535

3636
- name: Run e2e tests
37-
run: npm run test:e2e
3837
if: runner.os != 'Linux'
38+
uses: nick-fields/retry@e88a9994b039653512d697de1bce46b00bfe11b5
39+
with:
40+
timeout_minutes: 5
41+
max_attempts: 3
42+
command: npm run test:e2e
43+

.vscode/settings.json

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"somesass.scannerDepth": 30,
3-
"somesass.scannerExclude": [
4-
"**/.git",
5-
"**/node_modules",
6-
"**/bower_components"
7-
],
8-
"somesass.scanImportedFiles": true,
9-
"somesass.showErrors": false,
10-
"somesass.suggestAllFromOpenDocument": false,
11-
"somesass.suggestFromUseOnly": false,
12-
"somesass.suggestVariables": true,
13-
"somesass.suggestMixins": true,
14-
"somesass.suggestFunctions": true,
15-
"somesass.suggestFunctionsInStringContextAfterSymbols": " (+-*%"
2+
"somesass.scannerDepth": 30,
3+
"somesass.scannerExclude": [
4+
"**/.git/**",
5+
"**/node_modules/**",
6+
"**/bower_components/**"
7+
],
8+
"somesass.scanImportedFiles": true,
9+
"somesass.showErrors": false,
10+
"somesass.suggestAllFromOpenDocument": false,
11+
"somesass.suggestFromUseOnly": false,
12+
"somesass.suggestVariables": true,
13+
"somesass.suggestMixins": true,
14+
"somesass.suggestFunctions": true,
15+
"somesass.suggestFunctionsInStringContextAfterSymbols": " (+-*%"
1616
}

README.md

+25-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Supports standalone SCSS, as well as style blocks inside Vue and Svelte componen
1010

1111
Based on SCSS Intellisense by [Denis Malinochkin and contributors](https://github.com/mrmlnc/vscode-scss). Uses the built-in VS Code language server for SCSS.
1212

13+
Visit the [release section on GitHub](https://github.com/wkillerud/vscode-scss/releases) to see what has changed between versions.
14+
1315
## Setup
1416

1517
Search for Some Sass (`SomewhatStationery.some-sass`) from the extension installer within VS Code or install from [the Marketplace](https://marketplace.visualstudio.com/items?itemName=SomewhatStationery.some-sass).
@@ -41,7 +43,9 @@ Documentation written with SassDoc will be included in the hover information. Ad
4143

4244
![](images/sassdoc-hover.gif)
4345

44-
### Go to definition
46+
### Code navigation
47+
48+
#### Go to Definition
4549

4650
To use this feature, either:
4751

@@ -55,6 +59,24 @@ To use this feature – in the `Go` menu – choose [Go to Symbol](https://code.
5559

5660
![](images/workspace-symbols.gif)
5761

62+
#### Go to References
63+
64+
Shows an inline view of all references to the variable, mixin or function designed
65+
for quick navigation.
66+
67+
To use this feature, either:
68+
69+
- Right-click a variable, mixin or function and choose `Go to References`.
70+
- Place the cursor on the variable, moxin or function, open the `Go` menu and choose `Go to References`
71+
72+
#### Find All References
73+
74+
Opens a pane in your workbench with a list of all references to the variable,
75+
mixin or function.
76+
77+
To use this feature, right-click a variable, mixin or function and choose
78+
`Find All References`.
79+
5880
## Recommended settings for Visual Studio Code
5981

6082
**Improved code suggestions for variables under namespaces**
@@ -121,10 +143,10 @@ could suggest a `hello()` function (`|` in this case indicates cursor position).
121143

122144
#### Exclude files or folders
123145

124-
List of [glob](https://github.com/mrmlnc/fast-glob) patterns for directories that are excluded when scanning.
146+
List of [micromatch](https://github.com/micromatch/micromatch) patterns for directories that are excluded when scanning.
125147

126148
- JSON key: `somesass.scannerExclude`.
127-
- Default value: `["**/.git", "**/node_modules", "**/bower_components"]`.
149+
- Default value: `["**/.git/**", "**/node_modules/**", "**/bower_components/**"]`.
128150

129151
#### Adjust scanner depth
130152

fixtures/e2e/.vscode/settings.json

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"somesass.scannerDepth": 30,
3-
"somesass.scannerExclude": [
4-
"**/.git",
5-
"**/node_modules",
6-
"**/bower_components"
7-
],
8-
"somesass.scanImportedFiles": true,
9-
"somesass.showErrors": false,
10-
"somesass.suggestAllFromOpenDocument": false,
11-
"somesass.suggestFromUseOnly": false,
12-
"somesass.suggestVariables": true,
13-
"somesass.suggestMixins": true,
14-
"somesass.suggestFunctions": true,
15-
"somesass.suggestFunctionsInStringContextAfterSymbols": " (+-*%"
2+
"somesass.scannerDepth": 30,
3+
"somesass.scannerExclude": [
4+
"**/.git/**",
5+
"**/node_modules/**",
6+
"**/bower_components/**"
7+
],
8+
"somesass.scanImportedFiles": true,
9+
"somesass.showErrors": false,
10+
"somesass.suggestAllFromOpenDocument": false,
11+
"somesass.suggestFromUseOnly": false,
12+
"somesass.suggestVariables": true,
13+
"somesass.suggestMixins": true,
14+
"somesass.suggestFunctions": true,
15+
"somesass.suggestFunctionsInStringContextAfterSymbols": " (+-*%"
1616
}

fixtures/e2e/references/_dev.scss

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@forward "fun" as fun-*;

fixtures/e2e/references/_fun.scss

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@function hello($var) {
2+
@return $var;
3+
}
4+
5+
$name: "there";
6+
$reply: "general";

fixtures/e2e/references/_one.scss

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@use "dev";
2+
3+
.a {
4+
// Here it comes!
5+
content: dev.fun-hello(dev.$fun-name);
6+
}

package-lock.json

+39-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "some-sass",
33
"displayName": "Some Sass",
44
"description": "Provides code suggestions, documentation and code navigation for modern SCSS",
5-
"version": "2.3.0",
5+
"version": "2.4.0",
66
"publisher": "SomewhatStationery",
77
"license": "MIT",
88
"engines": {
@@ -44,9 +44,9 @@
4444
"type": "string"
4545
},
4646
"default": [
47-
"**/.git",
48-
"**/node_modules",
49-
"**/bower_components"
47+
"**/.git/**",
48+
"**/node_modules/**",
49+
"**/bower_components/**"
5050
],
5151
"description": "List of glob patterns for directories that are excluded when scanning."
5252
},
@@ -97,6 +97,7 @@
9797
"@nodelib/fs.macchiato": "1.0.4",
9898
"@types/color": "3.0.3",
9999
"@types/color-name": "1.1.1",
100+
"@types/micromatch": "^2.3.31",
100101
"@types/mocha": "9.1.1",
101102
"@types/node": "16.11.43",
102103
"@types/sinon": "10.0.12",

src/unsafe/document.ts

+23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Range } from 'vscode-languageserver-types';
2+
import { URI } from 'vscode-uri';
23

34
import { getLanguageService } from './language-service';
45
import { getNodeAtOffset } from './utils/ast';
@@ -7,6 +8,7 @@ import { getLinesFromText } from './utils/document';
78
import type { IScssDocument, IScssSymbols, ScssForward, ScssFunction, ScssImport, ScssLink, ScssMixin, ScssSymbol, ScssUse, ScssVariable } from './types/symbols';
89
import type { Position, TextDocument } from 'vscode-languageserver-textdocument';
910
import type { INode } from './types/nodes';
11+
import { realPath } from './utils/fs';
1012

1113
const ls = getLanguageService();
1214

@@ -22,6 +24,8 @@ export class ScssDocument implements IScssDocument {
2224
public mixins: Map<string, ScssMixin> = new Map();
2325
public functions: Map<string, ScssFunction> = new Map();
2426

27+
private _realPath: string | null = null;
28+
2529
constructor(document: TextDocument, symbols: IScssSymbols, ast?: INode) {
2630
this.textDocument = document;
2731
this.ast = ast ?? ls.parseStylesheet(document) as INode;
@@ -38,6 +42,25 @@ export class ScssDocument implements IScssDocument {
3842
return this.textDocument.uri;
3943
}
4044

45+
public get filePath(): string {
46+
return URI.parse(this.textDocument.uri).fsPath;
47+
}
48+
49+
public async getRealPath(): Promise<string | null> {
50+
if (this._realPath) {
51+
return this._realPath;
52+
}
53+
54+
try {
55+
const path = await realPath(this.filePath);
56+
this._realPath = path;
57+
} catch (e) {
58+
// Do nothing
59+
}
60+
61+
return this._realPath;
62+
}
63+
4164
private getFileName(): string {
4265
const uri = this.textDocument.uri;
4366
let lastSlash = uri.lastIndexOf('/');

src/unsafe/providers/completion/completion.ts

+23-6
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,6 @@ function createMixinCompletionItems(
375375
};
376376
}
377377

378-
// Not all mixins have @content, but when they do, be smart about adding brackets
379-
// and move the cursor to be ready to add said contents.
380-
if (mixin.sassdoc?.content) {
381-
insertText += " {\n\t$0\n}"
382-
}
383-
384378
const detail = `Mixin declared in ${scssDocument.fileName}`;
385379

386380
completions.push({
@@ -398,6 +392,29 @@ function createMixinCompletionItems(
398392
value: documentation,
399393
}
400394
});
395+
396+
// Not all mixins have @content, but when they do, be smart about adding brackets
397+
// and move the cursor to be ready to add said contents.
398+
// Include as separate suggestion since content may not always be needed or wanted.
399+
if (mixin.sassdoc?.content) {
400+
const details = { ...labelDetails };
401+
details.detail = details.detail ? details.detail + ' { }' : ' { }';
402+
completions.push({
403+
label,
404+
labelDetails: details,
405+
filterText,
406+
sortText,
407+
kind: CompletionItemKind.Snippet,
408+
detail,
409+
insertTextFormat: InsertTextFormat.Snippet,
410+
insertText: insertText += " {\n\t$0\n}",
411+
tags: Boolean(mixin.sassdoc?.deprecated) ? [CompletionItemTag.Deprecated] : [],
412+
documentation: {
413+
kind: MarkupKind.Markdown,
414+
value: documentation,
415+
}
416+
});
417+
}
401418
}
402419

403420
return completions;

0 commit comments

Comments
 (0)