Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/solutions/solution-manager.factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { faker } from '@faker-js/faker';
import path from 'path';
import { csolutionFactory } from './csolution.factory';
import { Severity } from './constants';
import { solutionRpcDataFactory } from './solution-rpc-data.factory';

export type MockSolutionManager = jest.Mocked<StubEvents<SolutionManager>> & { fireOnDidChangeLoadState: ReturnType<typeof fireOnDidChangeLoadState> };

Expand Down Expand Up @@ -50,6 +51,7 @@ const fireOnDidChangeLoadState = (emitter: vscode.EventEmitter<SolutionLoadState
export const solutionManagerFactory = makeFactory<MockSolutionManager>({
loadState: () => idleSolutionLoadStateFactory(),
getCsolution: () => jest.fn().mockReturnValue(csolutionFactory()),
getRpcData: () => jest.fn().mockReturnValue(solutionRpcDataFactory()),
onDidChangeLoadStateEmitter: () => new vscode.EventEmitter<SolutionLoadStateChangeEvent>(),
onDidChangeLoadState: (r) => jest.fn(r.onDidChangeLoadStateEmitter!.event),
onLoadedBuildFilesEmitter: () => new vscode.EventEmitter<[Severity, boolean]>(),
Expand Down
7 changes: 7 additions & 0 deletions src/solutions/solution-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export interface SolutionManager {

readonly getCsolution: () => CSolution | undefined;

readonly getRpcData: () => SolutionRpcData | undefined;

readonly onDidChangeLoadState: vscode.Event<SolutionLoadStateChangeEvent>;

readonly onLoadedBuildFiles: vscode.Event<[Severity, boolean]>;
Expand Down Expand Up @@ -119,6 +121,11 @@ export class SolutionManagerImpl implements SolutionManager {
return this.csolution;
}

public getRpcData(): SolutionRpcData | undefined {
return this.rpcData;
}


public get loadState(): SolutionLoadState {
return this._loadState;
}
Expand Down
53 changes: 53 additions & 0 deletions src/solutions/solution-rpc-data.factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright 2026 Arm Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { csolutionServiceFactory } from '../json-rpc/csolution-rpc-client.factory';
import { Board, Device, Variables } from '../json-rpc/csolution-rpc-client';
import { SolutionRpcData, SolutionRpcDataImpl } from './solution-rpc-data';


export class SolutionRpcDataMock extends SolutionRpcDataImpl {
constructor() {
super(csolutionServiceFactory());
}

public seedBoard(board?: Board): SolutionRpcDataMock {
this._board = board;
return this;
}

public seedDevice(device?: Device): SolutionRpcDataMock {
this._device = device;
return this;
}

public seedVariables(context: string, variables: Variables): SolutionRpcDataMock {
this.contextVariables.set(context, this.variablesFromRpcData(variables));
return this;
}
}

export function solutionRpcDataFactory(
options: Partial<SolutionRpcData> = {}
): SolutionRpcDataMock {
const solutionRpcDataMock = new SolutionRpcDataMock();

Object.assign(solutionRpcDataMock, options);

return solutionRpcDataMock;
}

export type SolutionRpcDataLike = SolutionRpcData | SolutionRpcDataMock;
33 changes: 22 additions & 11 deletions src/solutions/solution-rpc-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import { constructor } from '../generic/constructor';
import { Board, CsolutionService, Device, VariablesResult } from '../json-rpc/csolution-rpc-client';
import { Board, CsolutionService, Device, Variables } from '../json-rpc/csolution-rpc-client';
import { CSolution } from './csolution';


Expand All @@ -34,9 +34,16 @@ export interface SolutionRpcData {
*/
get device(): Device | undefined;

/**
* Returns variables for given context
* @param context resolving context
* @return ke-value map of variables, key is surrounded with '$'chars
*/
getVariables(context: string): Map<string, string> | undefined;

/** Resolves a single variable for a context
* @param context resolving context
* @param variable name without surrounding '$' chars
* @param variable name with surrounding '$' chars
* @return variable value if resolved, undefined otherwise
*/
resolveVariable(context: string, variable?: string): string | undefined;
Expand All @@ -52,13 +59,13 @@ export interface SolutionRpcData {
expandString(str: string, context: string): string
}

class SolutionRpcDataImpl implements SolutionRpcData {
private readonly contextVariables = new Map<string, Map<string, string>>();
private _board?: Board = undefined;
private _device?: Device = undefined;
export class SolutionRpcDataImpl implements SolutionRpcData {
protected readonly contextVariables = new Map<string, Map<string, string>>();
protected _board?: Board = undefined;
protected _device?: Device = undefined;

constructor(
private readonly csolutionService: CsolutionService,
protected readonly csolutionService: CsolutionService,
) {
}
clear() {
Expand Down Expand Up @@ -107,22 +114,26 @@ class SolutionRpcDataImpl implements SolutionRpcData {
for (const context of contexts) {
const data = await this.csolutionService.getVariables({ context: context });
if (data.success) {
this.contextVariables.set(context, this.variablesFromRpcData(data));
this.contextVariables.set(context, this.variablesFromRpcData(data.variables));
}
}
}

private variablesFromRpcData(data: VariablesResult) {
public getVariables(context: string): Map<string, string> | undefined {
return this.contextVariables.get(context);
}

protected variablesFromRpcData(variables: Variables) {
const vars = new Map<string, string>();
for (const [key, value] of Object.entries(data.variables)) {
for (const [key, value] of Object.entries(variables)) {
vars.set('$' + key + '$', value);
}
return vars;
}

public resolveVariable(context: string, variable?: string): string | undefined {
if (variable) {
const variables = this.contextVariables.get(context);
const variables = this.getVariables(context);
if (variables) {
return variables.get(variable);
}
Expand Down
4 changes: 2 additions & 2 deletions src/views/solution-outline/commands/delete-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('DeleteCommand', () => {
const groups = children?.[2];
const groupItems = groups?.getChildren();

const want: string[] = ['README.md', 'HID.c'];
const want: string[] = ['README.md', 'HID.c', '$OutDir()$/testOutput.test'];
const got: string[] = [];
if (groupItems) {
for (const gi of groupItems) {
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('DeleteCommand', () => {
const groups = children?.[2];
const groupItems = groups?.getChildren();

const want: string[] = ['Documentation'];
const want: string[] = ['Documentation', 'AccessSequencesTest'];
const got: string[] = [];
if (groupItems) {
for (const gi of groupItems) {
Expand Down
9 changes: 4 additions & 5 deletions src/views/solution-outline/solution-outline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { TreeViewProvider } from './treeview-provider';
import { CsolutionGlobalState, GlobalState } from '../../vscode-api/global-state';
import { SolutionOutlineTree } from './tree-structure/solution-outline-tree';
import { COutlineItem } from './tree-structure/solution-outline-item';
import { CSolution } from '../../solutions/csolution';
import { TreeViewFileDecorationProvider } from './treeview-decoration-provider';

export class SolutionOutlineView {
Expand All @@ -34,7 +33,6 @@ export class SolutionOutlineView {
private readonly treeViewProvider: TreeViewProvider<COutlineItem>,
private readonly globalStateProvider: GlobalState<CsolutionGlobalState>,
private readonly treeViewFileDecorationProvider: TreeViewFileDecorationProvider,
private readonly solutionOutlineTree = new SolutionOutlineTree()
) { }

public async activate(context: Pick<vscode.ExtensionContext, 'subscriptions' | 'globalState' | 'workspaceState'>): Promise<void> {
Expand Down Expand Up @@ -75,15 +73,16 @@ export class SolutionOutlineView {
this.treeViewProvider.setDescription('');
this.treeViewProvider.setTitle('');
}
this.createTree(loadState, csolution, thisTreeUpdateNumber);
this.createTree(loadState, thisTreeUpdateNumber);
}

private createTree(loadState: SolutionLoadState, csolution: CSolution | undefined, thisTreeUpdateNumber: number) {
private createTree(loadState: SolutionLoadState, thisTreeUpdateNumber: number) {
if (loadState.solutionPath) {
if (this.treeUpdateCount !== thisTreeUpdateNumber) {
return;
}
const tree = this.solutionOutlineTree.createTree(csolution);
const solutionOutlineTree = new SolutionOutlineTree(this.solutionManager.getCsolution(), this.solutionManager.getRpcData());
const tree = solutionOutlineTree.createTree();
this.treeViewProvider.updateTree(tree);
this.treeViewFileDecorationProvider.setTreeRoot(tree);
} else if (!loadState.solutionPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { FileItem } from './solution-outline-file-item';
import { FileItemBuilder } from './solution-outline-file-item';
import { parseYamlToCTreeItem } from '../../../generic/tree-item-yaml-parser';
import fs from 'fs';
import os from 'os';
Expand All @@ -23,19 +23,19 @@ import { COutlineItem } from './solution-outline-item';


describe('FileItem', () => {
let fileItem: FileItem;
let fileItem: FileItemBuilder;
let projectDir: string;
let cSolFile: string;
let componentNode: COutlineItem;

beforeEach(async () => {
fileItem = new FileItem();
fileItem = new FileItemBuilder();

const tmpDir = os.tmpdir();
projectDir = fs.mkdtempSync(path.join(tmpDir, 'myProject'));
cSolFile = `${projectDir}/Blinky.csolution.yml`;

fileItem = new FileItem();
fileItem = new FileItemBuilder();

componentNode = new COutlineItem('component');
componentNode.setTag('component');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import { COutlineItem } from './solution-outline-item';
import { getStatusTooltip, setContextMenuAttributes, setHeaderContext, setMergeDescription, setMergeFileContext } from './solution-outline-utils';
import { getCmsisPackRoot } from '../../../utils/path-utils';
import { matchesContext } from '../../../utils/context-utils';
import { SolutionOutlineItemBuilder } from './solution-outline-item-builder';

export class FileItem {
constructor(private readonly activeContext?: string) { }

export class FileItemBuilder extends SolutionOutlineItemBuilder {
public createFileNodes(cgroupItem: COutlineItem, files: ITreeItem<CTreeItem>[], docs?: ITreeItem<CTreeItem>[], isApi?: boolean, addContextMenu?: boolean) {
for (const f of files) {
const category = f.getValue('category');
Expand All @@ -45,15 +44,15 @@ export class FileItem {

const hasCmsisPackRoot = fileValue.indexOf('${CMSIS_PACK_ROOT}') !== -1;
const filePath = this.resolveFilePath(hasCmsisPackRoot, fileValue);
const fileBaseName = path.basename(filePath);
const fileBaseName = path.basename(fileValue);
const resourcePath = hasCmsisPackRoot ? filePath : f.resolvePath(filePath);
const description = isApi ? ' (API)' : undefined;
const rootFileName = f.rootFileName;

const cfileItem = this.createFileItem(cgroupItem, fileBaseName, resourcePath, description);

// Check if file is excluded based on context restrictions
if (this.activeContext && !matchesContext(f, this.activeContext)) {
if (this.context && !matchesContext(f, this.context)) {
cfileItem.setAttribute('excluded', '1');
}

Expand All @@ -74,12 +73,11 @@ export class FileItem {
if (hasCmsisPackRoot) {
return fileValue.replace('${CMSIS_PACK_ROOT}', getCmsisPackRoot());
}
return fileValue;
return this.expandAccessSequences(fileValue);
}

private createFileItem(cgroupItem: COutlineItem, fileBaseName: string, resourcePath: string, description?: string): COutlineItem {
const item = cgroupItem.createChild(fileBaseName);
item.setTag('file');
const item = cgroupItem.createChild('file');
item.setAttribute('label', fileBaseName);
item.setAttribute('expandable', '0');
item.setAttribute('resourcePath', resourcePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@ import { CTreeItem } from '../../../generic/tree-item';
import { ETextFileResult } from '../../../generic/text-file';
import { parseYamlToCTreeItem } from '../../../generic/tree-item-yaml-parser';
import { CSolution } from '../../../solutions/csolution';
import { HardwareItem } from './solution-outline-hardware-item';
import { HardwareItemBuilder } from './solution-outline-hardware-item';
import { TestDataHandler } from '../../../__test__/test-data';
import path from 'node:path';

describe('HardwareItem', () => {
let hwItem: HardwareItem;
describe('HardwareItemBuilder', () => {
let cSolFile: string;
let tmpSolutionDir: string;
const testDataHandler = new TestDataHandler();

beforeAll(async () => {
tmpSolutionDir = testDataHandler.copyTestDataToTmp('solutions');
hwItem = new HardwareItem();
cSolFile = path.join(tmpSolutionDir, 'USBD', 'USB_Device.csolution.yml');
});

Expand All @@ -54,7 +52,8 @@ describe('HardwareItem', () => {
expect(loadResult).toEqual(ETextFileResult.Success);

const want = 'Hello+CS300.dbgconf';
const hwNodes = hwItem.createHardwareNodes(csolution, topChild as CTreeItem);
const hwItemBuilder = new HardwareItemBuilder(csolution);
const hwNodes = hwItemBuilder.createHardwareNodes(csolution, topChild as CTreeItem);
const node = hwNodes.get('STM32U585AIIx');

let got: string = '';
Expand Down Expand Up @@ -84,7 +83,8 @@ describe('HardwareItem', () => {
const loadResult = await csolution.load(cSolFile);
expect(loadResult).toEqual(ETextFileResult.Success);

const hwNodes = hwItem.createHardwareNodes(csolution, topChild as CTreeItem);
const hwItemBuilder = new HardwareItemBuilder(csolution);
const hwNodes = hwItemBuilder.createHardwareNodes(csolution, topChild as CTreeItem);
const node = hwNodes.get('STM32U585AIIx');

// find dbgConfFile child node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import { COutlineItem } from './solution-outline-item';
import { buildDocFilePath, isWebAddress } from '../../../util';
import { CTreeItem, ITreeItem } from '../../../generic/tree-item';
import path from 'path';
import { FileItem } from './solution-outline-file-item';
import { FileItemBuilder } from './solution-outline-file-item';
import { CSolution } from '../../../solutions/csolution';
import { SolutionOutlineItemBuilder } from './solution-outline-item-builder';

export class HardwareItem {
constructor() { }
export class HardwareItemBuilder extends SolutionOutlineItemBuilder {

public createHardwareNodes(csolution: CSolution, cbuild?: CTreeItem): Map<string, COutlineItem> {
const hardwareTreeNodes = new Map<string, COutlineItem>();
Expand Down Expand Up @@ -98,8 +98,7 @@ export class HardwareItem {
return;
}

const cbookItem = chardwareItem.createChild(title);
cbookItem.setTag('book');
const cbookItem = chardwareItem.createChild('book');
cbookItem.setAttribute('label', title);
cbookItem.setAttribute('expandable', '0');
cbookItem.setAttribute('resourcePath', filePath);
Expand Down Expand Up @@ -137,8 +136,7 @@ export class HardwareItem {
const filePath = file.resolvePath(fileName);
const dbgConfFile = path.basename(fileName);

const dbgconfFileItem = chardwareItem.createChild('dbgConfFile');
dbgconfFileItem.setTag('file');
const dbgconfFileItem = chardwareItem.createChild('file');
dbgconfFileItem.setAttribute('label', dbgConfFile);
dbgconfFileItem.setAttribute('expandable', '0');
dbgconfFileItem.setAttribute('resourcePath', filePath);
Expand Down Expand Up @@ -173,7 +171,7 @@ export class HardwareItem {
// overwrite tootltip
dbgconfFileItem.setAttribute('tooltip', '');

const fileItem = new FileItem();
const fileItem = new FileItemBuilder();
fileItem.addMergeFeature(file, dbgconfFileItem, { skipValidation: true, localPathOverride: filePath });
}
}
Loading
Loading