Skip to content

Commit 58e9d3b

Browse files
committed
Move problems processing to dedicated module
1 parent 515af88 commit 58e9d3b

9 files changed

Lines changed: 516 additions & 301 deletions

src/desktop/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import { CsolutionService } from '../json-rpc/csolution-rpc-client';
8282
import { BuildStopCommand } from '../tasks/build/build-stop-command';
8383
import { ComponentsPacksWebviewMain } from '../views/manage-components-packs/components-packs-webview-main';
8484
import { SolutionConverterImpl } from '../solutions/solution-converter';
85+
import { SolutionProblemsImpl } from '../solutions/solution-problems';
8586
import { EnvironmentManager } from './env-manager';
8687
import { ExtensionApiWrapper } from '../vscode-api/extension-api-wrapper';
8788
import { SerialMonitorApi, Version } from '@microsoft/vscode-serial-monitor-api';
@@ -178,6 +179,7 @@ export const activate = async (context: ExtensionContext): Promise<CsolutionExte
178179
cmsisToolboxManager,
179180
compileCommandsGenerator,
180181
);
182+
const solutionProblems = new SolutionProblemsImpl(solutionManager, eventHub);
181183

182184
const themeProvider = new ThemeProviderImpl();
183185
const statusBar = new StatusBar(solutionManager, cmsisToolboxManager, themeProvider);
@@ -263,6 +265,7 @@ export const activate = async (context: ExtensionContext): Promise<CsolutionExte
263265
runGeneratorCommand.activate(context),
264266
convertMdkToCsolution.activate(context),
265267
solutionConverterImpl.activate(context),
268+
solutionProblems.activate(context),
266269
clangdManager.activate(context),
267270
componentsManager.activate(context),
268271
createSolution.activate(context),

src/solutions/csolution.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { ContextDescriptor, contextDescriptorFromString } from './descriptors/de
2828
import { CmsisSettingsJsonFile } from '../global/cmsis-settings-json-file';
2929
import { CSolutionYamlFile } from './files/csolution-yaml-file';
3030
import { CProjectYamlFile } from './files/cproject-yaml-file';
31-
import { VariablesConfiguration, LogMessages } from '../json-rpc/csolution-rpc-client';
31+
import { VariablesConfiguration } from '../json-rpc/csolution-rpc-client';
3232
import { CbuildPackFile } from './files/cbuild-pack-file';
3333

3434
export const targetTypeSchema = new Schema({
@@ -81,9 +81,6 @@ export class CSolution {
8181
// layer configurations
8282
variablesConfigurations?: VariablesConfiguration[] = undefined;
8383

84-
// log messages
85-
logMessages?: LogMessages = undefined;
86-
8784
public get projects() {
8885
return this.csolutionYml.projects;
8986
}
@@ -488,10 +485,6 @@ export class CSolution {
488485
public setVariablesConfigurations(variablesConfigurations: VariablesConfiguration[] | undefined) {
489486
this.variablesConfigurations = variablesConfigurations;
490487
}
491-
492-
public setLogMessages(logMessages: LogMessages | undefined) {
493-
this.logMessages = logMessages;
494-
}
495488
};
496489

497490
export function expandPath(path: string, csolution?: CSolution, targetType?: string,): string {

src/solutions/solution-converter.test.ts

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { getWorkspaceFolder } from '../utils/vscode-utils';
3939
import * as fsUtils from '../utils/fs-utils';
4040
import { ConvertRequestData, SolutionEventHub } from './solution-event-hub';
4141
import { waitTimeout } from '../__test__/test-waits';
42+
import { SolutionProblemsImpl } from './solution-problems';
4243

4344
jest.mock('which', () => jest.fn((cmd) => Promise.resolve(path.join('path', 'to', cmd))));
4445

@@ -72,6 +73,7 @@ describe('SolutionConverter', () => {
7273
let mockCsolutionService: jest.Mocked<ReturnType<typeof csolutionServiceFactory>>;
7374
let convertRequestData: ConvertRequestData;
7475
let completedListener: jest.Mock;
76+
let solutionProblems: SolutionProblemsImpl;
7577

7678
/**
7779
* Helper to wait for N completion events from EventHub
@@ -143,9 +145,11 @@ describe('SolutionConverter', () => {
143145
cmsisToolboxManager,
144146
compileCommandsGenerator,
145147
);
148+
solutionProblems = new SolutionProblemsImpl(solutionManager, eventHub);
146149

147150
initUtils(mockConfigurationProvider, solutionManager);
148151
converter.activate({ subscriptions: [] } as unknown as ExtensionContext);
152+
await solutionProblems.activate({ subscriptions: [] } as unknown as ExtensionContext);
149153

150154
mockCsolutionService.listMissingPacks.mockResolvedValue({ success: true });
151155
mockCsolutionService.convertSolution.mockResolvedValue({ success: true });
@@ -304,9 +308,6 @@ describe('SolutionConverter', () => {
304308
});
305309

306310
it('get log messages and set diagnostics accordingly', async () => {
307-
const mockDiagnosticsCollectionSet = jest.spyOn(vscode.languages.createDiagnosticCollection(), 'set');
308-
const mockDiagnosticsCollectionClear = jest.spyOn(vscode.languages.createDiagnosticCollection(), 'clear');
309-
310311
mockCsolutionService.convertSolution.mockResolvedValue({ success: false });
311312
mockCsolutionService.getLogMessages.mockResolvedValue({
312313
success: true,
@@ -316,13 +317,10 @@ describe('SolutionConverter', () => {
316317
});
317318
await fireAndWaitForConversion();
318319

319-
expect(mockDiagnosticsCollectionClear).toHaveBeenCalled();
320-
expect(mockDiagnosticsCollectionSet).toHaveBeenCalledTimes(3);
321320
expect(completedListener).toHaveBeenCalledTimes(1);
322321
});
323322

324323
it('get cbuild west output and set diagnostics accordingly', async () => {
325-
const mockDiagnosticsCollectionSet = jest.spyOn(vscode.languages.createDiagnosticCollection(), 'set');
326324
mockCsolutionService.convertSolution.mockResolvedValue({ success: true });
327325
mockCsolutionService.getLogMessages.mockResolvedValue({ success: true });
328326
let mockRunCbuildSetup = jest.spyOn(compileCommandsGenerator, 'runCbuildSetup').mockResolvedValue([true, [
@@ -336,15 +334,22 @@ describe('SolutionConverter', () => {
336334
jest.spyOn(vscodeUtils, 'getWorkspaceFolder').mockReturnValue('workspace/folder');
337335

338336
await fireAndWaitForConversion();
337+
await waitTimeout();
339338
expect(mockRunCbuildSetup).toHaveBeenCalledTimes(1);
340-
expect(mockDiagnosticsCollectionSet).toHaveBeenCalledTimes(2);
341339
expect(completedListener).toHaveBeenCalledTimes(1);
340+
expect(completedListener).toHaveBeenLastCalledWith(
341+
expect.objectContaining({
342+
toolsOutputMessages: expect.arrayContaining([
343+
'warning cbuild: missing ZEPHYR_BASE environment variable',
344+
'error cbuild: exec: "west": executable file not found in $PATH',
345+
]),
346+
}),
347+
);
342348

343349
// Remove settings.json
344350
completedListener.mockClear();
345351
const settings = path.join(getWorkspaceFolder(), '.vscode', 'settings.json');
346352
mockRunCbuildSetup.mockClear();
347-
mockDiagnosticsCollectionSet.mockClear();
348353
fsUtils.deleteFileIfExists(settings);
349354
await fireAndWaitForConversion();
350355
expect(mockRunCbuildSetup).toHaveBeenCalledTimes(1);
@@ -354,7 +359,6 @@ describe('SolutionConverter', () => {
354359
completedListener.mockClear();
355360
mockRunCbuildSetup = jest.spyOn(compileCommandsGenerator, 'runCbuildSetup').mockResolvedValue([true, []]);
356361
mockRunCbuildSetup.mockClear();
357-
mockDiagnosticsCollectionSet.mockClear();
358362
await fireAndWaitForConversion();
359363
expect(mockRunCbuildSetup).toHaveBeenCalledTimes(1);
360364
expect(completedListener).toHaveBeenCalledTimes(1);
@@ -446,18 +450,4 @@ describe('SolutionConverter', () => {
446450
expect(diagnostics?.[0]?.message).toContain('retry failed');
447451
});
448452

449-
it('extracts warnings from cbuild2cmake and csolution tool output', async () => {
450-
const mockDiagnosticsCollectionSet = jest.spyOn(vscode.languages.createDiagnosticCollection(), 'set');
451-
mockCsolutionService.convertSolution.mockResolvedValue({ success: true });
452-
mockCsolutionService.getLogMessages.mockResolvedValue({ success: true });
453-
jest.spyOn(compileCommandsGenerator, 'runCbuildSetup').mockResolvedValue([true, [
454-
'warning cbuild2cmake: some warning',
455-
'error csolution: some error',
456-
]]);
457-
458-
await fireAndWaitForConversion();
459-
460-
// Expect two calls: one for cbuild2cmake warning, one for csolution error
461-
expect(mockDiagnosticsCollectionSet).toHaveBeenCalledTimes(2);
462-
});
463453
});

0 commit comments

Comments
 (0)