forked from damien122/Autoit-Visual-Studio-Extension
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathai_workspaceSymbols.js
55 lines (45 loc) · 1.45 KB
/
ai_workspaceSymbols.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { languages, workspace, window } from 'vscode';
import { provideDocumentSymbols } from './ai_symbols';
let symbolsCache = [];
/**
* Fetches symbols for all AutoIt scripts in the workspace.
*
* @returns {Promise<Array>} A promise that resolves to an array of document symbols.
*/
async function getWorkspaceSymbols() {
try {
const workspaceScripts = await workspace.findFiles('**/*.{au3,a3x}');
const symbols = await Promise.all(
workspaceScripts.map(async file => {
const document = await workspace.openTextDocument(file);
return provideDocumentSymbols(document);
}),
);
return symbols.flat();
} catch (error) {
window.showErrorMessage(error.message || 'Error fetching workspace symbols');
return null;
}
}
/**
* Provides symbols for the entire workspace, using a cached version if available.
*
* @returns {Promise<Array>} A promise that resolves to an array of workspace symbols.
*/
async function provideWorkspaceSymbols() {
if (symbolsCache.length === 0) {
symbolsCache = await getWorkspaceSymbols();
}
return symbolsCache;
}
const watcher = workspace.createFileSystemWatcher('**/*.{au3,a3x}');
const resetCache = () => {
symbolsCache = [];
};
watcher.onDidChange(resetCache);
watcher.onDidCreate(resetCache);
watcher.onDidDelete(resetCache);
const workspaceSymbolProvider = languages.registerWorkspaceSymbolProvider({
provideWorkspaceSymbols,
});
export default workspaceSymbolProvider;