Skip to content

Commit

Permalink
Change displayBuildTarget to listBuildTargets
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthurm1 committed Feb 18, 2022
1 parent 4fb88f8 commit dd75362
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,43 @@ function launchMetals(
);
});

function displayBuildTarget(target: string): void {
const workspaceRoots = workspace.workspaceFolders;
if (workspaceRoots && workspaceRoots.length > 0) {
const uriStr = `metalsDecode:file:///${workspaceRoots[0].name}/${target}.metals-buildtarget`;
const uri = Uri.parse(uriStr);
workspace
.openTextDocument(uri)
.then((textDocument) => window.showTextDocument(textDocument));
}
}

registerCommand(`metals.target-info-display`, async (...args: any[]) => {
if (args.length > 0) {
// get build target name from treeview uri of the form "projects:file:/root/metals/.mtags/?id=mtags3!/_root_/,"
const treeViewUri = args[0] as string;
const buildTargetRegEx = new RegExp("projects:.*?id=(.*)!.*", "g");
const match = buildTargetRegEx.exec(treeViewUri);
if (match) {
displayBuildTarget(match[1]);
}
} else {
// pick from list of targets
client
.sendRequest(ExecuteCommandRequest.type, {
command: ServerCommands.ListBuildTargets,
})
.then(async (...args: any[]) => {
const targets = args?.[0] as string[];
window.showQuickPick(targets).then((target) => {
if (target) {
displayBuildTarget(target);
}
});
});
}
});

let channelOpen = false;

registerCommand(ClientCommands.FocusDiagnostics, () =>
Expand All @@ -577,16 +614,6 @@ function launchMetals(
commands.executeCommand(ClientCommands.RunDoctor)
);

registerCommand(
`metals.${ServerCommands.DisplayTargetInfo}`,
(...args) => {
client.sendRequest(ExecuteCommandRequest.type, {
command: ServerCommands.DisplayTargetInfo,
arguments: args,
});
}
);

registerCommand(ClientCommands.ToggleLogs, () => {
if (channelOpen) {
client.outputChannel.hide();
Expand Down

0 comments on commit dd75362

Please sign in to comment.