Skip to content

Commit 9d5b1bc

Browse files
Merge pull request #19 from EDAcation/add-yosys-stat-viewer
Add module statistics viewer
2 parents 054b8a9 + 5b62488 commit 9d5b1bc

50 files changed

Lines changed: 1938 additions & 319 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"root": true,
3-
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
3+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended-type-checked"],
44
"parser": "@typescript-eslint/parser",
55
"plugins": ["@typescript-eslint"],
6+
"parserOptions": {
7+
"project": true
8+
},
69
"rules": {
710
"@typescript-eslint/consistent-type-imports": [
811
"warn",
@@ -11,6 +14,7 @@
1114
"fixStyle": "inline-type-imports"
1215
}
1316
],
14-
"@typescript-eslint/no-unused-vars": ["warn", {"argsIgnorePattern": "^_"}]
17+
"@typescript-eslint/no-unused-vars": ["warn", {"argsIgnorePattern": "^_"}],
18+
"@typescript-eslint/require-await": "off"
1519
}
1620
}

.prettierignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
dist/
2-
3-
# TODO: un-ignore this file once we find a solution to the jquery import reordering situation
4-
views/digitaljs/src/main.ts

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@
280280
"compile-web": "npm run build-views && tsc && webpack",
281281
"package-web": "npm run build-views && tsc && webpack --mode production --devtool hidden-source-map",
282282
"vscode:prepublish": "npm run package-web",
283-
"lint": "eslint ./src ./workers/src --ext ts",
283+
"lint": "eslint ./src --ext ts",
284284
"test": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=. --extensionTestsPath=dist/extension/test/suite/index.js",
285285
"pretest": "npm run compile-web"
286286
},
@@ -301,7 +301,7 @@
301301
"process": "^0.11.10",
302302
"ts-loader": "^9.5.1",
303303
"ts-node": "^10.9.1",
304-
"typescript": "^5.3.2",
304+
"typescript": "5.2.2",
305305
"webpack": "^5.89.0",
306306
"webpack-cli": "^5.1.4"
307307
},

scripts/run-each-view.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
11
import {spawnSync} from 'child_process';
22
import {readdir} from 'fs/promises';
33
import path from 'path';
4-
import {fileURLToPath} from 'url';
54

6-
const command = process.argv.slice(2);
7-
const commandName = ['npm'].concat(command).join(' ');
5+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
6+
(async () => {
7+
const command = process.argv.slice(2);
8+
const commandName = ['npm'].concat(command).join(' ');
89

9-
const currentDirectory = path.dirname(fileURLToPath(import.meta.url));
10-
const viewsDirectory = path.resolve(currentDirectory, '..', 'views');
11-
const failedDirectories: string[] = [];
10+
const currentDirectory = path.dirname(__filename);
11+
const viewsDirectory = path.resolve(currentDirectory, '..', 'views');
12+
const failedDirectories: string[] = [];
1213

13-
console.log(`Executing command "${commandName}" for all views.`);
14-
console.log();
14+
console.log(`Executing command "${commandName}" for all views.`);
15+
console.log();
1516

16-
for (const directory of await readdir(viewsDirectory)) {
17-
const directoryName = `./views/${directory}`;
17+
for (const directory of await readdir(viewsDirectory)) {
18+
const directoryName = `./views/${directory}`;
1819

19-
console.log(`Executing command "${commandName}" in views "${directoryName}"`);
20+
console.log(`Executing command "${commandName}" in views "${directoryName}"`);
2021

21-
const {status} = spawnSync('npm', command, {
22-
cwd: path.resolve(viewsDirectory, directory),
23-
stdio: ['inherit', 'inherit', 'inherit']
24-
});
25-
console.log();
22+
const {status} = spawnSync('npm', command, {
23+
cwd: path.resolve(viewsDirectory, directory),
24+
stdio: ['inherit', 'inherit', 'inherit']
25+
});
26+
console.log();
27+
28+
if (status !== 0) {
29+
failedDirectories.push(directoryName);
30+
}
31+
}
2632

27-
if (status !== 0) {
28-
failedDirectories.push(directoryName);
33+
if (failedDirectories.length === 0) {
34+
console.log(`Executing command "${commandName}" was successful for all views.`);
35+
} else {
36+
console.log(`Executing command "${commandName}" failed for these views:`);
37+
console.log(failedDirectories.map((directory) => ` - ${directory}`).join('\n'));
38+
console.log('See the logs above for more details.');
2939
}
30-
}
31-
32-
if (failedDirectories.length === 0) {
33-
console.log(`Executing command "${commandName}" was successful for all views.`);
34-
} else {
35-
console.log(`Executing command "${commandName}" failed for these views:`);
36-
console.log(failedDirectories.map((directory) => ` - ${directory}`).join('\n'));
37-
console.log('See the logs above for more details.');
38-
}
40+
})();

src/common/universal-worker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ type WorkerThreadsModule = typeof import('worker_threads');
77
type WorkerThreadsWorker = import('worker_threads').Worker;
88
/* eslint-enable @typescript-eslint/consistent-type-imports */
99

10+
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call */
1011
const module: WorkerThreadsModule | undefined =
1112
typeof Worker === 'undefined' ? __non_webpack_require__('worker_threads') : undefined;
13+
/* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call */
1214

1315
type InternalNodeWorker = {
1416
type: 'node';
@@ -40,6 +42,7 @@ export const onEvent = <E extends keyof EventCallbacks>(event: E, callback: Even
4042
if (module) {
4143
module.parentPort?.on(event, callback);
4244
} else {
45+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
4346
addEventListener(event, (event) => callback(extractData(event)));
4447
}
4548
};
@@ -77,6 +80,7 @@ export class UniversalWorker {
7780

7881
public onEvent<E extends keyof EventCallbacks>(event: E, callback: EventCallbacks[E]): void {
7982
if (this.worker.type === 'web') {
83+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
8084
this.worker.worker.addEventListener(event, (event) => callback(extractData(event)));
8185
} else {
8286
this.worker.worker.on(event, callback);

src/extension/commands/actions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class OpenProjectConfigurationCommand extends CurrentProjectCommand {
1313

1414
async executeForCurrentProject(project: Project) {
1515
// Open project file
16-
vscode.commands.executeCommand('vscode.openWith', project.getUri(), ProjectEditor.getViewType());
16+
await vscode.commands.executeCommand('vscode.openWith', project.getUri(), ProjectEditor.getViewType());
1717
}
1818
}
1919

@@ -31,14 +31,14 @@ abstract class RunTaskCommand extends CurrentProjectCommand {
3131
return false;
3232
}
3333

34-
const uri = vscode.Uri.joinPath(task.scope.uri, task.definition.project);
34+
const uri = vscode.Uri.joinPath(task.scope.uri, task.definition.project as string);
3535
return uri.toString() === project.getUri().toString();
3636
});
3737

3838
if (task) {
39-
vscode.tasks.executeTask(task);
39+
await vscode.tasks.executeTask(task);
4040
} else {
41-
vscode.window.showErrorMessage('No task could be found for the current EDA project.');
41+
await vscode.window.showErrorMessage('No task could be found for the current EDA project.');
4242
}
4343
}
4444
}

src/extension/commands/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export abstract class CurrentProjectCommand extends BaseCommand {
2424
async execute(...args: unknown[]) {
2525
const project = this.projects.getCurrent();
2626
if (!project) {
27-
vscode.window.showWarningMessage('No EDA project selected.');
27+
await vscode.window.showWarningMessage('No EDA project selected.');
2828
return;
2929
}
3030

src/extension/commands/project.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,13 @@ export class NewProjectCommand extends BaseCommand {
112112
// Check if the project is within the workspace folder
113113
const [workspaceRelativePath] = getWorkspaceRelativePath(projectWorkspace, projectUri);
114114
if (!workspaceRelativePath) {
115-
vscode.window.showErrorMessage('Selected project location must be within the selected workspace folder.', {
116-
detail: `File "${projectUri.path}" is not in folder "${projectWorkspace.path}".`,
117-
modal: true
118-
});
115+
await vscode.window.showErrorMessage(
116+
'Selected project location must be within the selected workspace folder.',
117+
{
118+
detail: `File "${projectUri.path}" is not in folder "${projectWorkspace.path}".`,
119+
modal: true
120+
}
121+
);
119122
return;
120123
}
121124

@@ -126,7 +129,7 @@ export class NewProjectCommand extends BaseCommand {
126129
await this.projects.add(projectUri, true, true);
127130

128131
// Open project file
129-
vscode.commands.executeCommand('vscode.openWith', projectUri, ProjectEditor.getViewType());
132+
await vscode.commands.executeCommand('vscode.openWith', projectUri, ProjectEditor.getViewType());
130133
}
131134
}
132135

@@ -187,18 +190,21 @@ export class OpenProjectCommand extends BaseCommand {
187190
// Check if the project is within the workspace folder
188191
const [workspaceRelativePath] = getWorkspaceRelativePath(projectWorkspace, projectUri);
189192
if (!workspaceRelativePath) {
190-
vscode.window.showErrorMessage('Selected project location must be within the selected workspace folder.', {
191-
detail: `File "${projectUri.path}" is not in folder "${projectWorkspace.path}".`,
192-
modal: true
193-
});
193+
await vscode.window.showErrorMessage(
194+
'Selected project location must be within the selected workspace folder.',
195+
{
196+
detail: `File "${projectUri.path}" is not in folder "${projectWorkspace.path}".`,
197+
modal: true
198+
}
199+
);
194200
return;
195201
}
196202

197203
// Add project
198204
await this.projects.add(projectUri, true, false);
199205

200206
// Open project file
201-
vscode.commands.executeCommand('vscode.openWith', projectUri, ProjectEditor.getViewType());
207+
await vscode.commands.executeCommand('vscode.openWith', projectUri, ProjectEditor.getViewType());
202208
}
203209
}
204210

@@ -218,6 +224,6 @@ export class SelectProject extends BaseCommand {
218224
}
219225

220226
async execute(project: Project) {
221-
await this.projects.setCurrent(project);
227+
this.projects.setCurrent(project);
222228
}
223229
}

src/extension/editors/base.ts

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from 'vscode';
22

33
import type {Projects} from '../projects/index.js';
4-
import {type ViewMessage} from '../types.js';
4+
import type {GlobalStoreMessage, ViewMessage} from '../types.js';
55
import {BaseWebview} from '../webview.js';
66

77
export interface EditorWebviewArgs {
@@ -26,57 +26,89 @@ export abstract class BaseEditor extends BaseWebview<EditorWebviewArgs> implemen
2626
_token: vscode.CancellationToken
2727
): void | Thenable<void> {
2828
const disposables: vscode.Disposable[] = [];
29+
const webview = webviewPanel.webview;
2930

3031
// Render webview
31-
webviewPanel.webview.options = {
32+
webview.options = {
3233
enableScripts: true
3334
};
34-
webviewPanel.webview.html = this.getHtmlForWebview(webviewPanel.webview, {document});
35+
webview.html = this.getHtmlForWebview(webview, {document});
3536

3637
// Add message listener
37-
webviewPanel.webview.onDidReceiveMessage(this.onDidReceiveMessage.bind(this, document, webviewPanel.webview));
38+
webview.onDidReceiveMessage(this.onDidReceiveMessage.bind(this, document, webview));
3839

3940
// Add text document listener
4041
disposables.push(
4142
vscode.workspace.onDidChangeTextDocument((event) => {
4243
if (event.document.uri.toString() === document.uri.toString()) {
43-
this.update(document, webviewPanel.webview, true);
44+
this.update(document, webview, true);
4445
}
4546
})
4647
);
4748
disposables.push(
4849
vscode.workspace.onDidSaveTextDocument((event) => {
4950
if (event.uri.toString() === document.uri.toString()) {
50-
this.onSave(document, webviewPanel.webview);
51+
this.onSave(document, webview);
5152
}
5253
})
5354
);
5455

5556
// Create file system watcher
5657
const watcher = vscode.workspace.createFileSystemWatcher(document.uri.fsPath);
57-
watcher.onDidCreate(() => this.update(document, webviewPanel.webview, true));
58-
watcher.onDidChange(() => this.update(document, webviewPanel.webview, true));
59-
watcher.onDidDelete(() => this.update(document, webviewPanel.webview, true));
58+
watcher.onDidCreate(() => this.update(document, webview, true));
59+
watcher.onDidChange(() => this.update(document, webview, true));
60+
watcher.onDidDelete(() => this.update(document, webview, true));
6061
disposables.push(watcher);
6162

6263
// Add dispose listener
6364
webviewPanel.onDidDispose(() => {
65+
this.onClose(document, webview);
66+
6467
for (const disposable of disposables) {
6568
disposable.dispose();
6669
}
6770
});
6871

6972
// Update document
70-
this.update(document, webviewPanel.webview, false);
73+
this.update(document, webview, false);
7174
}
7275

73-
protected abstract onDidReceiveMessage(
74-
document: vscode.TextDocument,
76+
protected async onDidReceiveMessage(
77+
_document: vscode.TextDocument,
7578
webview: vscode.Webview,
76-
message: ViewMessage
77-
): void;
79+
message: ViewMessage | GlobalStoreMessage
80+
): Promise<boolean> {
81+
if (message.type === 'globalStore') {
82+
if (message.action === 'set') {
83+
await this.context.globalState.update(message.name, message.value);
84+
const response: GlobalStoreMessage = {
85+
type: 'globalStore',
86+
action: 'result',
87+
transaction: message.transaction
88+
};
89+
await webview.postMessage(response);
90+
91+
return true;
92+
} else if (message.action === 'get') {
93+
const value = this.context.globalState.get(message.name) || ({} as object);
94+
const response: GlobalStoreMessage = {
95+
type: 'globalStore',
96+
action: 'result',
97+
transaction: message.transaction,
98+
result: value
99+
};
100+
await webview.postMessage(response);
101+
102+
return true;
103+
}
104+
}
105+
106+
return false;
107+
}
78108

79109
protected abstract onSave(document: vscode.TextDocument, webview: vscode.Webview): void;
80110

111+
protected abstract onClose(document: vscode.TextDocument, webview: vscode.Webview): void;
112+
81113
protected abstract update(document: vscode.TextDocument, webview: vscode.Webview, isDocumentChange: boolean): void;
82114
}

0 commit comments

Comments
 (0)