Skip to content

Commit 232c28e

Browse files
Update API changes that add methods with command result information (#4518)
* Update api temp * update to execute clean, install, and reconfigure with results * implement listBuildTargets * implement run ctest with result api * add todo for the tests parameter * implemented ctestWithResult and listTests, may need additional testing but seems to work from an API perspective in a small test project and also CMake repo * add cancellation token support in api updates * slightly modify to old status for methods that were unchanged * add api telemetry * add version * enforce better lifetime for combinedCancellationTokens * add comment, no need for engine update, and remove unnecessary test change * missed @types/vscode update * update methods, add comments explaining, switch to exitCode * update comment * update vscode-cmake-tools npm package * some linter fixes * some more linter fixes * linter * linter * remove unused imports * fix test referencing result instead of exitCode * linter * update tests to reference exitCode rather than CommandResult return value * keep unofficial api the same
1 parent 97533d8 commit 232c28e

File tree

23 files changed

+452
-240
lines changed

23 files changed

+452
-240
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3848,7 +3848,7 @@
38483848
"tsconfig-paths": "^3.11.0",
38493849
"tslint": "^6.1.3",
38503850
"typescript": "^4.1.5",
3851-
"vscode-cmake-tools": "^1.2.0",
3851+
"vscode-cmake-tools": "^1.3.0",
38523852
"vscode-nls-dev": "^3.3.2",
38533853
"webpack": "^5.94.0",
38543854
"webpack-cli": "^4.5.0"

src/api.ts

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@ import * as api from 'vscode-cmake-tools';
88
import CMakeProject from '@cmt/cmakeProject';
99
import { ExtensionManager } from '@cmt/extension';
1010
import { assertNever } from '@cmt/util';
11+
import { CTestOutputLogger } from '@cmt/ctest';
12+
import { logEvent } from './telemetry';
1113

1214
export class CMakeToolsApiImpl implements api.CMakeToolsApi {
1315
constructor(private readonly manager: ExtensionManager) {}
1416

15-
version: api.Version = api.Version.v2;
17+
version: api.Version = api.Version.v4;
1618

1719
showUIElement(element: api.UIElement): Promise<void> {
20+
logApiTelemetry('showUIElement');
1821
return this.setUIElementVisibility(element, true);
1922
}
2023

2124
hideUIElement(element: api.UIElement): Promise<void> {
25+
logApiTelemetry('hideUIElement');
2226
return this.setUIElementVisibility(element, false);
2327
}
2428

@@ -35,11 +39,13 @@ export class CMakeToolsApiImpl implements api.CMakeToolsApi {
3539
}
3640

3741
async getProject(uri: vscode.Uri): Promise<CMakeProjectWrapper | undefined> {
42+
logApiTelemetry('getProject');
3843
const project: CMakeProject | undefined = await this.manager.projectController.getProjectForFolder(uri.fsPath);
3944
return project ? new CMakeProjectWrapper(project) : undefined;
4045
}
4146

4247
getActiveFolderPath(): string {
48+
logApiTelemetry('getActiveFolderPath');
4349
return this.manager.activeFolderPath();
4450
}
4551

@@ -57,10 +63,10 @@ export class CMakeToolsApiImpl implements api.CMakeToolsApi {
5763
}
5864
}
5965

60-
async function withErrorCheck(name: string, action: () => Promise<number>): Promise<void> {
66+
async function withErrorCheck(name: string, action: () => Promise<api.CommandResult>): Promise<void> {
6167
const code = await action();
62-
if (code !== 0) {
63-
throw new Error(`${name} failed with code ${code}`);
68+
if (code.exitCode !== 0) {
69+
throw new Error(`${name} failed with code ${code.exitCode}, stdout: ${code.stdout ?? ''}, stderr: ${code.stderr ?? ''}`);
6470
}
6571
}
6672

@@ -80,30 +86,83 @@ class CMakeProjectWrapper implements api.Project {
8086
}
8187

8288
configure(): Promise<void> {
83-
return withErrorCheck('configure', async () => (await this.project.configure()).result);
89+
logApiTelemetry('configure');
90+
return withErrorCheck('configure', async () => (this.project.configure()));
91+
}
92+
93+
async configureWithResult(cancellationToken?: vscode.CancellationToken): Promise<api.CommandResult> {
94+
logApiTelemetry('configureWithResult');
95+
return this.project.configure(undefined, cancellationToken);
8496
}
8597

8698
build(targets?: string[]): Promise<void> {
99+
logApiTelemetry('build');
87100
return withErrorCheck('build', () => this.project.build(targets));
88101
}
89102

103+
async buildWithResult(targets?: string[], cancellationToken?: vscode.CancellationToken): Promise<api.CommandResult> {
104+
logApiTelemetry('buildWithResult');
105+
return this.project.build(targets, undefined, undefined, cancellationToken);
106+
}
107+
108+
async ctestWithResult(tests?: string[], cancellationToken?: vscode.CancellationToken): Promise<api.CommandResult> {
109+
logApiTelemetry('ctestWithResult');
110+
return this.project.ctest(undefined, new CTestOutputLogger(), tests, cancellationToken);
111+
}
112+
90113
install(): Promise<void> {
114+
logApiTelemetry('install');
91115
return withErrorCheck('install', () => this.project.install());
92116
}
93117

118+
installWithResult(cancellationToken?: vscode.CancellationToken): Promise<api.CommandResult> {
119+
logApiTelemetry('installWithResult');
120+
return this.project.install(cancellationToken);
121+
}
122+
94123
clean(): Promise<void> {
124+
logApiTelemetry('clean');
95125
return withErrorCheck('clean', () => this.project.clean());
96126
}
97127

128+
async cleanWithResult(cancellationToken?: vscode.CancellationToken): Promise<api.CommandResult> {
129+
logApiTelemetry('cleanWithResult');
130+
return this.project.clean(cancellationToken);
131+
}
132+
98133
reconfigure(): Promise<void> {
99-
return withErrorCheck('reconfigure', async () => (await this.project.cleanConfigure()).result);
134+
logApiTelemetry('reconfigure');
135+
return withErrorCheck('reconfigure', async () => (this.project.cleanConfigure()));
136+
}
137+
138+
async reconfigureWithResult(cancellationToken?: vscode.CancellationToken): Promise<api.CommandResult> {
139+
logApiTelemetry('reconfigureWithResult');
140+
return this.project.cleanConfigure(undefined, cancellationToken);
100141
}
101142

102143
async getBuildDirectory(): Promise<string | undefined> {
144+
logApiTelemetry('getBuildDirectory');
103145
return (await this.project.buildDirectory()) ?? undefined;
104146
}
105147

106148
async getActiveBuildType(): Promise<string | undefined> {
149+
logApiTelemetry('getActiveBuildType');
107150
return (await this.project.currentBuildType()) ?? undefined;
108151
}
152+
153+
async listBuildTargets(): Promise<string[] | undefined> {
154+
logApiTelemetry('listBuildTargets');
155+
return (await this.project.targets).map(target => target.name);
156+
}
157+
158+
async listTests(): Promise<string[] | undefined> {
159+
logApiTelemetry('listTests');
160+
return this.project.cTestController.getTestNames();
161+
}
162+
}
163+
164+
function logApiTelemetry(method: string): void {
165+
logEvent("api", {
166+
method: method
167+
});
109168
}

0 commit comments

Comments
 (0)