Skip to content

Commit 61741bb

Browse files
authored
Merge branch 'main' into dependabot/github_actions/EndBug/add-and-commit-10.0.0
2 parents 135ceaf + a873728 commit 61741bb

5 files changed

Lines changed: 94 additions & 13 deletions

File tree

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,11 @@
13511351
"default": true,
13521352
"markdownDescription": "Create or update `launch.json` and `tasks.json` with the Debug Adapter configuration of the CMSIS solution project. When disabled, the files `launch.json` and `tasks.json` are no longer modified. (Note: also available in Manage Solution Settings dialog)."
13531353
},
1354+
"cmsis-csolution.autoRevealSolutionOutline": {
1355+
"type": "boolean",
1356+
"default": true,
1357+
"description": "Automatically reveal the CMSIS Solution Outline view when a solution is loaded."
1358+
},
13541359
"cmsis-csolution.probe-id": {
13551360
"type": "string",
13561361
"default": "",

src/desktop/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export const activate = async (context: ExtensionContext): Promise<CsolutionExte
248248
const targetPackCommand = new TargetPackCommandImpl(commandsProvider, solutionManager);
249249
const debugHardwareCommands = new DebugHardwareCommands(commandsProvider, solutionManager);
250250
const csolutionExtension = new CsolutionExtensionImpl(solutionCreator, buildTaskProvider, dataManager);
251-
const solutionOutline = new SolutionOutlineView(solutionManager, treeViewProviderImpl, globalStateProvider, treeViewFileDecorationProvider);
251+
const solutionOutline = new SolutionOutlineView(solutionManager, treeViewProviderImpl, globalStateProvider, treeViewFileDecorationProvider, configurationProvider);
252252
const cmsisCommands = new CmsisCommands(configurationProvider, commandsProvider, solutionManager, debugProvider, serialMonitorExtension);
253253
const buildStopCommand = new BuildStopCommand(commandsProvider, buildTaskProvider);
254254
const configurationWizardView = new ConfWizWebview(context);

src/manifest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const UV2CSOLUTION_PATH_ENV_VAR = 'UV2CSOLUTION_PATH';
4242
export const CONFIG_DOWNLOAD_MISSING_PACKS = 'downloadPacks';
4343
export const OUTPUT_DIRECTORY = 'outputDirectory';
4444
export const CONFIG_AUTO_DEBUG_LAUNCH = 'autoDebugLaunch';
45+
export const CONFIG_AUTO_REVEAL_SOLUTION_OUTLINE = 'autoRevealSolutionOutline';
4546
export const CONFIG_BUILD_OUTPUT_VERBOSITY = 'buildOutputVerbosity';
4647
export const MANAGE_COMPONENTS_PACKS_COMMAND_ID = `${PACKAGE_NAME}.manageComponentsPacks`;
4748
export const MERGE_FILE_COMMAND_ID = `${PACKAGE_NAME}.mergeFile`;

src/views/solution-outline/solution-outline.test.ts

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { EventEmitter } from 'vscode';
17+
import * as vscode from 'vscode';
1818
import { TreeViewProvider } from './treeview-provider';
1919
import { SolutionOutlineView } from './solution-outline';
2020
import { SolutionLoadState } from '../../solutions/solution-manager';
@@ -26,15 +26,18 @@ import { globalStateFactory } from '../../vscode-api/global-state.factories';
2626
import { COutlineItem } from './tree-structure/solution-outline-item';
2727
import { csolutionFactory } from '../../solutions/csolution.factory';
2828
import { TreeViewFileDecorationProvider } from './treeview-decoration-provider';
29+
import { configurationProviderFactory, MockConfigurationProvider } from '../../vscode-api/configuration-provider.factories';
30+
import { CONFIG_AUTO_REVEAL_SOLUTION_OUTLINE } from '../../manifest';
2931

3032
describe('SolutionOutlineView', () => {
3133
let mockTreeViewProvider: TreeViewProvider<COutlineItem>;
3234
let mockTreeViewFileDecorationProvider: TreeViewFileDecorationProvider;
33-
let visibilityChangeEmitter: EventEmitter<Event>;
35+
let visibilityChangeEmitter: vscode.EventEmitter<Event>;
3436
let globalStateProvider: GlobalState<CsolutionGlobalState>;
37+
let configurationProvider: MockConfigurationProvider;
3538

3639
beforeEach(async () => {
37-
visibilityChangeEmitter = new EventEmitter();
40+
visibilityChangeEmitter = new vscode.EventEmitter();
3841

3942
mockTreeViewProvider = {
4043
updateTree: jest.fn(),
@@ -50,6 +53,7 @@ describe('SolutionOutlineView', () => {
5053
} as unknown as TreeViewFileDecorationProvider;
5154

5255
globalStateProvider = globalStateFactory();
56+
configurationProvider = configurationProviderFactory();
5357
});
5458

5559

@@ -58,7 +62,8 @@ describe('SolutionOutlineView', () => {
5862
solutionManagerFactory(),
5963
mockTreeViewProvider,
6064
globalStateProvider,
61-
mockTreeViewFileDecorationProvider
65+
mockTreeViewFileDecorationProvider,
66+
configurationProvider
6267
);
6368
const context = extensionContextFactory();
6469

@@ -73,7 +78,8 @@ describe('SolutionOutlineView', () => {
7378
solutionManagerFactory(),
7479
mockTreeViewProvider,
7580
globalStateProvider,
76-
mockTreeViewFileDecorationProvider
81+
mockTreeViewFileDecorationProvider,
82+
configurationProvider
7783
);
7884
const context = extensionContextFactory();
7985

@@ -95,7 +101,8 @@ describe('SolutionOutlineView', () => {
95101
mockSolutionManager,
96102
mockTreeViewProvider,
97103
globalStateProvider,
98-
mockTreeViewFileDecorationProvider
104+
mockTreeViewFileDecorationProvider,
105+
configurationProvider
99106
);
100107
await view.activate(extensionContextFactory());
101108

@@ -119,7 +126,8 @@ describe('SolutionOutlineView', () => {
119126
mockSolutionManager,
120127
mockTreeViewProvider,
121128
globalStateProvider,
122-
mockTreeViewFileDecorationProvider
129+
mockTreeViewFileDecorationProvider,
130+
configurationProvider
123131
);
124132
await view.activate(extensionContextFactory());
125133

@@ -143,7 +151,8 @@ describe('SolutionOutlineView', () => {
143151
mockSolutionManager,
144152
mockTreeViewProvider,
145153
globalStateProvider,
146-
mockTreeViewFileDecorationProvider
154+
mockTreeViewFileDecorationProvider,
155+
configurationProvider
147156
);
148157
await view.activate(extensionContextFactory());
149158

@@ -165,7 +174,8 @@ describe('SolutionOutlineView', () => {
165174
mockSolutionManager,
166175
mockTreeViewProvider,
167176
globalStateProvider,
168-
mockTreeViewFileDecorationProvider
177+
mockTreeViewFileDecorationProvider,
178+
configurationProvider
169179
);
170180
await view.activate(extensionContextFactory());
171181

@@ -188,7 +198,8 @@ describe('SolutionOutlineView', () => {
188198
mockSolutionManager,
189199
mockTreeViewProvider,
190200
globalStateProvider,
191-
mockTreeViewFileDecorationProvider
201+
mockTreeViewFileDecorationProvider,
202+
configurationProvider
192203
);
193204
await view.activate(extensionContextFactory());
194205

@@ -202,4 +213,61 @@ describe('SolutionOutlineView', () => {
202213
expect(mockTreeViewProvider.updateTree).toHaveBeenCalled();
203214
});
204215

216+
it('reveals the solution outline when a new solution is loaded and auto reveal is enabled', async () => {
217+
const executeCommandSpy = jest.spyOn(vscode.commands, 'executeCommand').mockResolvedValue(undefined);
218+
const solutionLoadedState = activeSolutionLoadStateFactory();
219+
const mockSolutionManager = solutionManagerFactory({
220+
loadState: solutionLoadedState,
221+
getCsolution: jest.fn().mockReturnValue(csolutionFactory()),
222+
});
223+
const view = new SolutionOutlineView(
224+
mockSolutionManager,
225+
mockTreeViewProvider,
226+
globalStateProvider,
227+
mockTreeViewFileDecorationProvider,
228+
configurationProvider
229+
);
230+
231+
await view.activate(extensionContextFactory());
232+
mockSolutionManager.onDidChangeLoadStateEmitter.fire({
233+
previousState: { solutionPath: undefined },
234+
newState: solutionLoadedState,
235+
});
236+
await waitForPromises();
237+
238+
expect(executeCommandSpy).toHaveBeenCalledWith(`${SolutionOutlineView.treeViewId}.open`, { preserveFocus: true });
239+
240+
executeCommandSpy.mockRestore();
241+
});
242+
243+
it('does not reveal the solution outline when auto reveal is disabled', async () => {
244+
const executeCommandSpy = jest.spyOn(vscode.commands, 'executeCommand').mockResolvedValue(undefined);
245+
const solutionLoadedState = activeSolutionLoadStateFactory();
246+
const mockSolutionManager = solutionManagerFactory({
247+
loadState: solutionLoadedState,
248+
getCsolution: jest.fn().mockReturnValue(csolutionFactory()),
249+
});
250+
configurationProvider = configurationProviderFactory({
251+
[CONFIG_AUTO_REVEAL_SOLUTION_OUTLINE]: false,
252+
});
253+
const view = new SolutionOutlineView(
254+
mockSolutionManager,
255+
mockTreeViewProvider,
256+
globalStateProvider,
257+
mockTreeViewFileDecorationProvider,
258+
configurationProvider
259+
);
260+
261+
await view.activate(extensionContextFactory());
262+
mockSolutionManager.onDidChangeLoadStateEmitter.fire({
263+
previousState: { solutionPath: undefined },
264+
newState: solutionLoadedState,
265+
});
266+
await waitForPromises();
267+
268+
expect(executeCommandSpy).not.toHaveBeenCalledWith(`${SolutionOutlineView.treeViewId}.open`, { preserveFocus: true });
269+
270+
executeCommandSpy.mockRestore();
271+
});
272+
205273
});

src/views/solution-outline/solution-outline.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
*/
1616

1717
import * as vscode from 'vscode';
18-
import { PACKAGE_NAME } from '../../manifest';
18+
import { CONFIG_AUTO_REVEAL_SOLUTION_OUTLINE, PACKAGE_NAME } from '../../manifest';
1919
import { SolutionLoadState, SolutionLoadStateChangeEvent, SolutionManager } from '../../solutions/solution-manager';
2020
import { TreeViewProvider } from './treeview-provider';
2121
import { CsolutionGlobalState, GlobalState } from '../../vscode-api/global-state';
2222
import { SolutionOutlineTree } from './tree-structure/solution-outline-tree';
2323
import { COutlineItem } from './tree-structure/solution-outline-item';
2424
import { TreeViewFileDecorationProvider } from './treeview-decoration-provider';
25+
import { ConfigurationProvider } from '../../vscode-api/configuration-provider';
2526

2627

2728
export class SolutionOutlineView {
@@ -34,6 +35,7 @@ export class SolutionOutlineView {
3435
private readonly treeViewProvider: TreeViewProvider<COutlineItem>,
3536
private readonly globalStateProvider: GlobalState<CsolutionGlobalState>,
3637
private readonly treeViewFileDecorationProvider: TreeViewFileDecorationProvider,
38+
private readonly configurationProvider: ConfigurationProvider,
3739
) { }
3840

3941
public async activate(context: Pick<vscode.ExtensionContext, 'subscriptions' | 'globalState' | 'workspaceState'>): Promise<void> {
@@ -58,7 +60,12 @@ export class SolutionOutlineView {
5860
await this.updateTree(e.newState);
5961
if (this.solutionPath !== e.newState.solutionPath) {
6062
this.solutionPath = e.newState.solutionPath;
61-
vscode.commands.executeCommand(`${SolutionOutlineView.treeViewId}.open`, { preserveFocus: true });
63+
if (
64+
e.newState.solutionPath &&
65+
this.configurationProvider.getConfigVariableOrDefault<boolean>(CONFIG_AUTO_REVEAL_SOLUTION_OUTLINE, true)
66+
) {
67+
vscode.commands.executeCommand(`${SolutionOutlineView.treeViewId}.open`, { preserveFocus: true });
68+
}
6269
}
6370
}
6471

0 commit comments

Comments
 (0)