Skip to content

Commit b65fe45

Browse files
committed
Support reference lookups for unsupported symbol file types by defaulting to position zero
- it's been reported that users can find references of a .scss file └── apps └── editor └── src └── commands └── select-referencing-files-commands ├── index.ts ├── select-referencing-files-commands.ts └── utils ├── get-referencing-files-for-position.ts ├── get-referencing-files-for-uris.ts └── prompt-for-referencing-files.ts
1 parent a6711d9 commit b65fe45

1 file changed

Lines changed: 41 additions & 33 deletions

File tree

‎apps/editor/src/commands/select-referencing-files-commands/utils/get-referencing-files-for-uris.ts‎

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,57 @@ export const get_referencing_files_for_uris = async (params: {
1717
}
1818

1919
try {
20-
const symbols = await vscode.commands.executeCommand<
21-
vscode.DocumentSymbol[] | vscode.SymbolInformation[]
22-
>('vscode.executeDocumentSymbolProvider', uri)
20+
const positions: vscode.Position[] = []
2321

24-
if (!symbols) {
25-
continue
26-
}
22+
const is_unsupported_for_symbol_search =
23+
/\.(css|scss|sass|less|styl|json|yaml|yml|md|html|xml)$/i.test(
24+
uri.fsPath
25+
)
2726

28-
const positions: vscode.Position[] = []
29-
const top_level_containers = new Set<string>()
27+
if (is_unsupported_for_symbol_search) {
28+
positions.push(new vscode.Position(0, 0))
29+
} else {
30+
const symbols = await vscode.commands.executeCommand<
31+
vscode.DocumentSymbol[] | vscode.SymbolInformation[]
32+
>('vscode.executeDocumentSymbolProvider', uri)
3033

31-
const traverse = (syms: any[]) => {
32-
for (const sym of syms) {
33-
if (sym.selectionRange) {
34-
positions.push(sym.selectionRange.start)
35-
const is_container =
36-
sym.kind === vscode.SymbolKind.Module ||
37-
sym.kind === vscode.SymbolKind.Namespace ||
38-
sym.kind === vscode.SymbolKind.Package
34+
if (symbols) {
35+
const top_level_containers = new Set<string>()
3936

40-
if (is_container && sym.children && sym.children.length > 0) {
41-
traverse(sym.children)
42-
}
43-
} else if (sym.location) {
44-
const is_container =
45-
sym.kind === vscode.SymbolKind.Module ||
46-
sym.kind === vscode.SymbolKind.Namespace ||
47-
sym.kind === vscode.SymbolKind.Package
37+
const traverse = (syms: any[]) => {
38+
for (const sym of syms) {
39+
if (sym.selectionRange) {
40+
positions.push(sym.selectionRange.start)
41+
const is_container =
42+
sym.kind === vscode.SymbolKind.Module ||
43+
sym.kind === vscode.SymbolKind.Namespace ||
44+
sym.kind === vscode.SymbolKind.Package
4845

49-
if (is_container) {
50-
top_level_containers.add(sym.name)
51-
}
46+
if (is_container && sym.children && sym.children.length > 0) {
47+
traverse(sym.children)
48+
}
49+
} else if (sym.location) {
50+
const is_container =
51+
sym.kind === vscode.SymbolKind.Module ||
52+
sym.kind === vscode.SymbolKind.Namespace ||
53+
sym.kind === vscode.SymbolKind.Package
5254

53-
if (
54-
!sym.containerName ||
55-
top_level_containers.has(sym.containerName)
56-
) {
57-
positions.push(sym.location.range.start)
55+
if (is_container) {
56+
top_level_containers.add(sym.name)
57+
}
58+
59+
if (
60+
!sym.containerName ||
61+
top_level_containers.has(sym.containerName)
62+
) {
63+
positions.push(sym.location.range.start)
64+
}
65+
}
5866
}
5967
}
68+
traverse(symbols)
6069
}
6170
}
62-
traverse(symbols)
6371

6472
for (let i = 0; i < positions.length; i++) {
6573
if (params.token.isCancellationRequested) {

0 commit comments

Comments
 (0)