Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,8 @@
"vscode-cpptools": "^6.1.0",
"vscode-nls": "^5.0.0",
"@vscode/extension-telemetry": "^0.9.6",
"vscode-jsonrpc": "^3.6.2"
"vscode-jsonrpc": "^3.6.2",
"vscode-makefile-tools-api": "file:../vscode-makefile-tools-api"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build and tests will fail until this is updated after api is published

},
"resolutions": {
"ansi-regex": "^5.0.1",
Expand Down
30 changes: 30 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as api from "vscode-makefile-tools-api";
import * as vscode from "vscode";
import * as make from "./make";
import { getTargets } from "./configuration";
import { logEvent } from "./telemetry";

export class MakefileToolsApiImpl implements api.MakefileToolsApi {
constructor(public version: api.Version = api.Version.v1) {
}

build(target?: string, clean?: boolean, cancellationToken?: vscode.CancellationToken): Promise<api.CommandResult> {
logApiTelemetry("build", this.version);
return make.buildTarget(make.TriggeredBy.api, target ?? "", clean ?? false, cancellationToken);
}
clean(cancellationToken: vscode.CancellationToken): Promise<api.CommandResult> {
logApiTelemetry("clean", this.version);
return make.buildTarget(make.TriggeredBy.api, "clean", false, cancellationToken);
}
async listBuildTargets(): Promise<string[] | undefined> {
logApiTelemetry("listBuildTargets", this.version);
return getTargets();
}
}

function logApiTelemetry(method: string, version: api.Version): void {
logEvent("api", {
method: method,
version: version.toString(),
});
}
74 changes: 74 additions & 0 deletions src/build/customBuildTask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import * as vscode from 'vscode';
import * as util from '../util';
import { getCurPID } from '../make';

abstract class CommandConsumer {
output(line: string): void {
this._stdout.push(line);
}
error(error: string): void {
this._stderr.push(error);
}
get stdout() {
return this._stdout.join('\n');
}
protected readonly _stdout = new Array<string>();

get stderr() {
return this._stderr.join('\n');
}
protected readonly _stderr = new Array<string>();
}

const endOfLine: string = "\r\n";

export class CustomBuildTaskTerminal extends CommandConsumer implements vscode.Pseudoterminal {

constructor(private command: string, private args: string[], private cwd: string, private env?: { [key: string]: string }) {
super();
}

private writeEmitter = new vscode.EventEmitter<string>();
private closeEmitter = new vscode.EventEmitter<number>();
public get onDidWrite(): vscode.Event<string> {
return this.writeEmitter.event;
}
public get onDidClose(): vscode.Event<number> {
return this.closeEmitter.event;
}

override output(line: string): void {
this.writeEmitter.fire(line + endOfLine);
super.output(line);
}

override error(error: string): void {
this.writeEmitter.fire(error + endOfLine);
super.error(error);
}

private _process: util.SpawnProcess | undefined;
async open(_initialDimensions: vscode.TerminalDimensions | undefined): Promise<void> {
this._process = util.spawnChildProcess(
this.command,
this.args,
{
workingDirectory: this.cwd,
stdoutCallback: (line: string) => this.output(line),
stderrCallback: (error: string) => this.error(error),
env: this.env
}
)
const res: util.SpawnProcessResult = await this._process.result;
this.closeEmitter.fire(res.returnCode);
}
async close(): Promise<void> {
if (this._process) {
if (this._process.child) {
await util.killTree(getCurPID());
}
this._process = undefined;
}
}

}
35 changes: 20 additions & 15 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2429,6 +2429,25 @@ export async function setTargetByName(targetName: string): Promise<void> {
extension._projectOutlineProvider.updateBuildTarget(targetName);
}

export function getTargets(): string[] {
// Ensure "all" is always available as a target to select.
// There are scenarios when "all" might not be present in the list of available targets,
// for example when the extension is using a build log or dryrun cache of a previous state
// when a particular target was selected and a dryrun applied on that is producing a subset of targets,
// making it impossible to select "all" back again without resetting the Makefile Tools state
// or switching to a different makefile configuration or implementing an editable target quick pick.
// Another situation where "all" would inconveniently miss from the quick pick is when the user is
// providing a build log without the required verbosity for parsing targets (-p or --print-data-base switches).
// When the extension is not reading from build log or dryrun cache, we have logic to prevent
// "all" from getting lost: make sure the target is not appended to the make invocation
// whose output is used to parse the targets (as opposed to parsing for IntelliSense or launch targets
// when the current target must be appended to the make command).
if (!buildTargets.includes("all")) {
buildTargets.push("all");
}
return buildTargets;
}

// Fill a drop-down with all the target names run by building the makefile for the current configuration
// Triggers a cpptools configuration provider update after selection.
// TODO: change the UI list to multiple selections mode and store an array of current active targets
Expand Down Expand Up @@ -2466,21 +2485,7 @@ export async function selectTarget(): Promise<void> {
}
}

// Ensure "all" is always available as a target to select.
// There are scenarios when "all" might not be present in the list of available targets,
// for example when the extension is using a build log or dryrun cache of a previous state
// when a particular target was selected and a dryrun applied on that is producing a subset of targets,
// making it impossible to select "all" back again without resetting the Makefile Tools state
// or switching to a different makefile configuration or implementing an editable target quick pick.
// Another situation where "all" would inconveniently miss from the quick pick is when the user is
// providing a build log without the required verbosity for parsing targets (-p or --print-data-base switches).
// When the extension is not reading from build log or dryrun cache, we have logic to prevent
// "all" from getting lost: make sure the target is not appended to the make invocation
// whose output is used to parse the targets (as opposed to parsing for IntelliSense or launch targets
// when the current target must be appended to the make command).
if (!buildTargets.includes("all")) {
buildTargets.push("all");
}
getTargets();

const chosen: string | undefined = await vscode.window.showQuickPick(
buildTargets
Expand Down
23 changes: 19 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import * as cpp from "vscode-cpptools";

import * as nls from "vscode-nls";
import { TelemetryEventProperties } from "@vscode/extension-telemetry";
import { Version, MakefileToolsApi, MakefileToolsExtensionExports } from "vscode-makefile-tools-api";
import { MakefileToolsApiImpl } from "./api";
nls.config({
messageFormat: nls.MessageFormat.bundle,
bundleFormat: nls.BundleFormat.standalone,
Expand All @@ -31,7 +33,7 @@ let launcher: launch.Launcher = launch.getLauncher();

export let extension: MakefileToolsExtension;

export class MakefileToolsExtension {
export class MakefileToolsExtension implements MakefileToolsExtensionExports {
public readonly _projectOutlineProvider = new tree.ProjectOutlineProvider();
private readonly _projectOutlineTreeView = vscode.window.createTreeView(
"makefile.outline",
Expand All @@ -51,10 +53,18 @@ export class MakefileToolsExtension {
private cppToolsAPI?: cpp.CppToolsApi;
private cppConfigurationProviderRegister?: Promise<void>;
private compilerFullPath?: string;
public api: MakefileToolsApiImpl;

public constructor(
public readonly extensionContext: vscode.ExtensionContext
) {}
public readonly extensionContext: vscode.ExtensionContext,
apiVersion: Version = Version.v1
) {
this.api = new MakefileToolsApiImpl(apiVersion);
}

getApi(version: Version): MakefileToolsApi {
return new MakefileToolsApiImpl(version);
}

public updateBuildLogPresent(newValue: boolean): void {
vscode.commands.executeCommand(
Expand Down Expand Up @@ -258,7 +268,7 @@ export class MakefileToolsExtension {

export async function activate(
context: vscode.ExtensionContext
): Promise<void> {
): Promise<MakefileToolsExtensionExports> {
if (process.env["MAKEFILE_TOOLS_TESTING"] === "1") {
await vscode.commands.executeCommand(
"setContext",
Expand Down Expand Up @@ -858,6 +868,11 @@ export async function activate(
if (telemetryProperties && util.hasProperties(telemetryProperties)) {
telemetry.logEvent("settings", telemetryProperties);
}

return { getApi: (_version: Version) => {
return extension.api;
}
};
}

export async function deactivate(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export class Launcher implements vscode.Disposable {
make.TriggeredBy.buildTarget,
currentBuildTarget,
false
)) === make.ConfigureBuildReturnCodeTypes.success;
)).exitCode === make.ConfigureBuildReturnCodeTypes.success;
if (!buildSuccess) {
logger.message(
localize(
Expand Down
Loading
Loading