Skip to content

Commit 758d0bd

Browse files
authored
fix(vscode): use editor resource for Qihe analysis (#109)
2 parents 8cc3465 + 02e59a7 commit 758d0bd

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

editors/vscode/src/extension.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -693,14 +693,14 @@ async function reloadWorkspace(): Promise<void> {
693693
}
694694
}
695695

696-
async function runQiheAnalysis(): Promise<void> {
697-
const editor = vscode.window.activeTextEditor;
698-
if (!editor) {
696+
async function runQiheAnalysis(resource: unknown): Promise<void> {
697+
const targetUri = qiheAnalysisTargetUri(resource);
698+
if (!targetUri) {
699699
vscode.window.showWarningMessage(vscode.l10n.t('Open a Verilog or SystemVerilog file first.'));
700700
return;
701701
}
702702

703-
if (!['verilog', 'systemverilog'].includes(editor.document.languageId)) {
703+
if (!isQiheSourceUri(targetUri)) {
704704
vscode.window.showWarningMessage(
705705
vscode.l10n.t('Qihe analysis is only available for Verilog files.'),
706706
);
@@ -712,15 +712,15 @@ async function runQiheAnalysis(): Promise<void> {
712712
return;
713713
}
714714

715-
const workspaceFolder = vscode.workspace.getWorkspaceFolder(editor.document.uri);
715+
const workspaceFolder = vscode.workspace.getWorkspaceFolder(targetUri);
716716
const payload = {
717-
uri: editor.document.uri.toString(),
717+
uri: targetUri.toString(),
718718
cwd: workspaceFolder?.uri.fsPath,
719719
};
720720

721721
const target = workspaceFolder
722722
? `workspace ${workspaceFolder.uri.fsPath}`
723-
: `file ${editor.document.uri.fsPath}`;
723+
: `file ${targetUri.fsPath}`;
724724
logQihe(`[INFO] Starting Qihe analysis for ${target}`);
725725

726726
try {
@@ -735,6 +735,20 @@ async function runQiheAnalysis(): Promise<void> {
735735
}
736736
}
737737

738+
function qiheAnalysisTargetUri(resource: unknown): vscode.Uri | undefined {
739+
if (resource instanceof vscode.Uri) {
740+
return resource;
741+
}
742+
return vscode.window.activeTextEditor?.document.uri;
743+
}
744+
745+
function isQiheSourceUri(uri: vscode.Uri): boolean {
746+
if (uri.scheme !== 'file') {
747+
return false;
748+
}
749+
return ['.v', '.vh', '.sv', '.svh', '.svi'].includes(path.extname(uri.fsPath).toLowerCase());
750+
}
751+
738752
function affectsServerLaunchConfiguration(event: vscode.ConfigurationChangeEvent): boolean {
739753
return (
740754
event.affectsConfiguration('vizsla.server.command') ||
@@ -792,8 +806,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
792806

793807
const runQiheRegistration = vscode.commands.registerCommand(
794808
runQiheAnalysisCommand,
795-
async () => {
796-
await runQiheAnalysis();
809+
async (resource) => {
810+
await runQiheAnalysis(resource);
797811
},
798812
);
799813
context.subscriptions.push(runQiheRegistration);

0 commit comments

Comments
 (0)