Skip to content

Commit 40a4cf5

Browse files
edrioukCopilot
andauthored
Update list of available solutions on demand (#212)
* Update list of available solutions on demand * Update src/solutions/active-solution-tracker.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Roll back copilot suggestion * lint errors --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent cbcb160 commit 40a4cf5

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/solutions/active-solution-tracker.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,26 @@ describe('ActiveSolutionTracker', () => {
117117
expect(workspaceFoldersProvider.findFiles).toHaveBeenCalledWith(ActiveSolutionTrackerImpl.GLOB_PATTERN, testGlobPattern);
118118
});
119119

120+
it('sets the given solution as active before the initial refresh completes', async () => {
121+
let resolveExtensionActivation: () => void;
122+
const extensionActivation = new Promise<void>(resolve => {
123+
resolveExtensionActivation = resolve;
124+
});
125+
126+
context.extension.activate.mockReturnValue(extensionActivation);
127+
128+
const activeSolutionChanged = waitForEvent(activeSolutionTracker.onDidChangeActiveSolution);
129+
130+
activeSolutionTracker.activate(context as unknown as vscode.ExtensionContext);
131+
await commandsProvider.mockRunRegistered(COMMAND_ACTIVATE_SOLUTION, SOLUTION_URI_FOO.fsPath);
132+
await activeSolutionChanged;
133+
134+
expect(activeSolutionTracker.activeSolution).toEqual(SOLUTION_URI_FOO.fsPath);
135+
expect(changeActiveListener).toHaveBeenCalledTimes(1);
136+
137+
resolveExtensionActivation!();
138+
});
139+
120140
it('updates when the configured glob pattern changes', async () => {
121141
activeSolutionTracker.activate(context as unknown as vscode.ExtensionContext);
122142
await waitForEvent(activeSolutionTracker.onDidChangeSolutions, undefined, 200);;

src/solutions/active-solution-tracker.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,13 @@ export class ActiveSolutionTrackerImpl implements ActiveSolutionTracker {
266266
return;
267267
}
268268
const inputFsPath = await this.getCsolutionFile(inputSolutionPath);
269+
270+
// A request can arrive before the debounced activation path triggers refresh.
271+
// Update the cached solutions list immediately
272+
// to prevent activation of default solution
273+
if (this._solutions.length === 0) {
274+
this._solutions = await this.getSolutionPaths();
275+
}
269276
return this.solutions.includes(inputFsPath) ? inputFsPath : undefined;
270277
}
271278

0 commit comments

Comments
 (0)