Skip to content

Commit

Permalink
Add onSelectedConfigurationChanged api (#3671)
Browse files Browse the repository at this point in the history
* Add onSelectedKitChanged api

* needs package.json changes once api is shipped

* update the package.json

* Fix `notifyOnSelectedConfigurationChanged()` order

When `notifyOnSelectedConfigurationChanged()` is executed before
`setFolderActiveKit()`, `cmake.buildKit` returns the previous selected
kit. That's why `notifyOnSelectedConfigurationChanged()` should run
after `setFolderActiveKit()`.

---------

Co-authored-by: Garrett Campbell <[email protected]>
Co-authored-by: Garrett Campbell <[email protected]>
  • Loading branch information
3 people authored Apr 19, 2024
1 parent 25698e0 commit 1ed22b7
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Features:

- Add the possibility to open the current build directory in the Explorer [#1451](https://github.com/microsoft/vscode-cmake-tools/issues/1451)
- Add support for CMakePresets V7 and V8. [#3549](https://github.com/microsoft/vscode-cmake-tools/issues/3549)
- Update `api.ts` to add the `onSelectedConfigurationChanged` event. [#3671](https://github.com/microsoft/vscode-cmake-tools/pull/3671) [@OrkunTokdemir](https://github.com/OrkunTokdemir)
- Add support for CMake Language Support natively in this extension. [#3559](https://github.com/microsoft/vscode-cmake-tools/issues/3559)

Improvements:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3742,7 +3742,7 @@
"tslint": "^6.1.3",
"typescript": "^4.1.5",
"vsce": "^2.7.0",
"vscode-cmake-tools": "^1.1.0",
"vscode-cmake-tools": "^1.2.0",
"vscode-nls-dev": "^3.3.2",
"webpack": "^5.76.0",
"webpack-cli": "^4.5.0"
Expand Down
4 changes: 4 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class CMakeProjectWrapper implements api.Project {
return this.project.onCodeModelChangedApiEvent;
}

get onSelectedConfigurationChanged() {
return this.project.onSelectedConfigurationChangedApiEvent;
}

configure(): Promise<void> {
return withErrorCheck('configure', async () => (await this.project.configure()).result);
}
Expand Down
9 changes: 9 additions & 0 deletions src/cmakeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import paths from './paths';
import { ProjectController } from './projectController';
import { MessageItem } from 'vscode';
import { DebugTrackerFactory, DebuggerInformation, getDebuggerPipeName } from './debug/debuggerConfigureDriver';
import { ConfigurationType } from 'vscode-cmake-tools';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
Expand Down Expand Up @@ -718,6 +719,14 @@ export class CMakeProject {
}
private readonly _codeModelChangedApiEventEmitter = new vscode.EventEmitter<void>();

public notifyOnSelectedConfigurationChanged(configurationType: ConfigurationType) {
this._onSelectedConfigurationChangedApiEvent.fire(configurationType);
}
get onSelectedConfigurationChangedApiEvent() {
return this._onSelectedConfigurationChangedApiEvent.event;
}
private readonly _onSelectedConfigurationChangedApiEvent = new vscode.EventEmitter<ConfigurationType>();

private readonly communicationModeSub = this.workspaceContext.config.onChange('cmakeCommunicationMode', () => {
log.info(localize('communication.changed.restart.driver', "Restarting the CMake driver after a communication mode change."));
return this.shutDownCMakeDriver();
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,11 @@ export class ExtensionManager implements vscode.Disposable {
this.statusBar.setActiveKitName(cmakeProject.activeKit ? cmakeProject.activeKit.name : '');
this.activeConfigurePresetSub = cmakeProject.onActiveConfigurePresetChanged(FireNow, p => {
this.statusBar.setConfigurePresetName(p?.displayName || p?.name || '');
cmakeProject.notifyOnSelectedConfigurationChanged(api.ConfigurationType.ConfigurePreset);
});
this.activeBuildPresetSub = cmakeProject.onActiveBuildPresetChanged(FireNow, p => {
this.statusBar.setBuildPresetName(p?.displayName || p?.name || '');
cmakeProject.notifyOnSelectedConfigurationChanged(api.ConfigurationType.BuildPreset);
});
this.activeTestPresetSub = cmakeProject.onActiveTestPresetChanged(FireNow, p => {
this.statusBar.setTestPresetName(p?.displayName || p?.name || '');
Expand Down
2 changes: 2 additions & 0 deletions src/kitsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import paths from '@cmt/paths';
import { fs } from '@cmt/pr';
import rollbar from '@cmt/rollbar';
import { chokidarOnAnyChange, ProgressHandle, reportProgress } from '@cmt/util';
import { ConfigurationType } from 'vscode-cmake-tools';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
Expand Down Expand Up @@ -280,6 +281,7 @@ export class KitsController {
const kitChanged = chosen_kit.kit !== this.project.activeKit;
if (kitChanged) {
await this.setFolderActiveKit(chosen_kit.kit);
this.project.notifyOnSelectedConfigurationChanged(ConfigurationType.Kit);
}

if (chosen_kit.kit.name !== SpecialKits.Unspecified && kitChanged && this.project.workspaceContext.config.automaticReconfigure) {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6605,10 +6605,10 @@ vsce@^2.7.0:
yauzl "^2.3.1"
yazl "^2.2.2"

vscode-cmake-tools@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/vscode-cmake-tools/-/vscode-cmake-tools-1.1.0.tgz#415da0e18e7dc08500a0e748708290efdbb19485"
integrity sha512-LVOSGrY2aHZBYg0t8mbcAtoYLR+xP4FaXiUx2lNmpK6bs+mK7FA15LgGrjUvgOo34UL5av3ZuAsJ7SROKUDGug==
vscode-cmake-tools@^1.2.0:
version "1.2.0"
resolved "https://registry.npmjs.org/vscode-cmake-tools/-/vscode-cmake-tools-1.2.0.tgz#2dbdf515b0815a97607350f092812d8e01d81467"
integrity sha512-79K8i0l+AfPV28XPoCFCL1BgTVRTPrKZ7YY2KCPOJyy18G/CiriXVa1Gic7A2a16xOoIcsbZRRXoNO0BZTGp9w==

vscode-cpptools@^6.1.0:
version "6.1.0"
Expand Down

0 comments on commit 1ed22b7

Please sign in to comment.