Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
4 changes: 3 additions & 1 deletion src/debug/debug-adapters-yaml-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import { ITreeItem, CTreeItem } from '../generic/tree-item';
import { CTreeItemYamlFile, ITreeItemFile } from '../generic/tree-item-file';
import { Optional } from '../generic/type-helper';
import { DEBUG_ADAPTERS_YAML_FILE_PATH } from '../manifest';
import { PathType } from '../views/manage-solution/types';
Comment thread
arneschmid marked this conversation as resolved.
Outdated


export type UIOption<T extends string, V> = {
name: string; //Label text for the option in the user interface.
description?: string; //Hover over text.
'yml-node': string; //Name of the node in the csolution file under debugger: section.
type: T; //Type of the option [number, enum, string, file]
pname?: string; //If present, the option is pname based. Then the same property will be created for each pname instance.
pname?: string; //If present, the option is pname based. Then the same property will be created for each pname instance.
'path-type'?: PathType; //If the type is file, indicates if the path is absolute or relative to the solution file directory. Default is relative.
} & V;
Comment thread
arneschmid marked this conversation as resolved.

export type UIEnumValue = {
Expand Down
12 changes: 7 additions & 5 deletions src/views/manage-solution/manage-solution-webview-main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,13 @@ describe('ContextSelectionWebviewMain', () => {

const dialogOptions = showOpenDialogSpy.mock.calls[0][0];
expect(dialogOptions?.defaultUri?.toString()).toBe(URI.file(path.dirname(defaultPath)).toString());
expect(webviewManager.sendMessage).toHaveBeenCalledWith({
type: 'FILE_SELECTED',
data: ['images/app.axf'],
for: 'image-path'
});
expect(webviewManager.sendMessage).toHaveBeenCalledWith(
expect.objectContaining({
type: 'FILE_SELECTED',
data: ['images/app.axf'],
Comment thread
arneschmid marked this conversation as resolved.
for: 'image-path'
Comment thread
arneschmid marked this conversation as resolved.
})
);
});
});

Expand Down
8 changes: 6 additions & 2 deletions src/views/manage-solution/manage-solution-webview-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import { CommandsProvider } from '../../vscode-api/commands-provider';
import { ConfigurationProvider } from '../../vscode-api/configuration-provider';
import { WebviewManager, WebviewManagerOptions } from '../webview-manager';
import { ManageSolutionController } from './manage-solution-controller';
import { FileSelectorOptionsType, IncomingMessage, OutgoingMessage } from './messages';
import { IncomingMessage, OutgoingMessage } from './messages';
import { SolutionData } from './view/state/manage-solution-state';
import { initialState } from './view/state/reducer';
import debounce from 'lodash.debounce';
import { CsolutionService } from '../../json-rpc/csolution-rpc-client';
import { isDeepStrictEqual } from 'util';
import { FileSelectorOptionsType } from './types';

export const MANAGE_SOLUTION_WEBVIEW_OPTIONS: Readonly<WebviewManagerOptions> = {
title: 'Manage Solution',
Expand Down Expand Up @@ -440,7 +441,10 @@ export class ManageSolutionWebviewMain {

if (fileUri && fileUri[0]) {
const paths = fileUri.map(u =>
backToForwardSlashes(path.relative(solutionDir, u.fsPath))
backToForwardSlashes(options?.pathType === 'absolute'
? u.fsPath
: path.relative(solutionDir, u.fsPath)
)
Comment thread
arneschmid marked this conversation as resolved.
);

await this.webviewManager.sendMessage({ type: 'FILE_SELECTED', data: paths, for: targetElementId });
Expand Down
65 changes: 29 additions & 36 deletions src/views/manage-solution/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,43 @@
*/

import { DebugAdapter } from '../../debug/debug-adapters-yaml-file';
import { FileSelectorOptionsType } from './types';
import { ActiveTargetSet, SolutionData } from './view/state/manage-solution-state';

export type FileSelectorOptionsType = {
canSelectMany?: boolean,
defaultUri?: string,
openLabel?: string,
title?: string,
filters?: { [key: string]: string[] }
};

/**
* Messages that the context selection view can pass to the extension.
*/
export type OutgoingMessage
= { type: 'GET_CONTEXT_SELECTION_DATA' }
| { type: 'SET_SELECTED_TARGET', target: string, set: string | undefined }
| { type: 'OPEN_FILE', path: string }
| { type: 'SET_SELECTED_CONTEXTS', data: SolutionData }
| { type: 'GET_DEBUG_ADAPTERS' }
| { type: 'SET_DEBUGGER', name: string }
| { type: 'ADD_NEW_CONTEXT' }
| { type: 'ADD_NEW_PROJECT' }
| { type: 'ADD_NEW_IMAGE' }
| { type: 'UNLINK_IMAGE', image: string }
| { type: 'SET_START_PROCESSOR', value: string }
| { type: 'SAVE_CONTEXT_SELECTION' }
| { type: 'OPEN_HELP' }
| { type: 'SET_DEBUG_ADAPTER_PROPERTY', service: string | undefined, key: string, value: string | number, pname?: string }
| { type: 'SELECT_FILE', targetElementId: string, options?: FileSelectorOptionsType }
| { type: 'SET_AUTO_UPDATE', value: boolean }
| { type: 'TOGGLE_DEBUGGER', value: boolean }
| { type: 'TOGGLE_DEBUG_ADAPTER_SECTION', section: string }
;
= { type: 'GET_CONTEXT_SELECTION_DATA' }
| { type: 'SET_SELECTED_TARGET', target: string, set: string | undefined }
| { type: 'OPEN_FILE', path: string }
| { type: 'SET_SELECTED_CONTEXTS', data: SolutionData }
| { type: 'GET_DEBUG_ADAPTERS' }
| { type: 'SET_DEBUGGER', name: string }
| { type: 'ADD_NEW_CONTEXT' }
| { type: 'ADD_NEW_PROJECT' }
| { type: 'ADD_NEW_IMAGE' }
| { type: 'UNLINK_IMAGE', image: string }
| { type: 'SET_START_PROCESSOR', value: string }
| { type: 'SAVE_CONTEXT_SELECTION' }
| { type: 'OPEN_HELP' }
| { type: 'SET_DEBUG_ADAPTER_PROPERTY', service: string | undefined, key: string, value: string | number, pname?: string }
| { type: 'SELECT_FILE', targetElementId: string, options?: FileSelectorOptionsType }
| { type: 'SET_AUTO_UPDATE', value: boolean }
| { type: 'TOGGLE_DEBUGGER', value: boolean }
| { type: 'TOGGLE_DEBUG_ADAPTER_SECTION', section: string }
;

/**
* Messages that the extension can pass to the context selection view.
*/
export type IncomingMessage
= { type: 'DATA_CONTEXT_SELECTION', data: SolutionData }
| { type: 'DEBUG_ADAPTERS', data: DebugAdapter[], sectionsInUse: string[] }
| { type: 'DEBUGGER', data: string }
| { type: 'ACTIVE_TARGET_SET', data: ActiveTargetSet }
| { type: 'IS_DIRTY', data: boolean }
| { type: 'IS_BUSY', data: boolean }
| { type: 'FILE_SELECTED', data: string[], for: string }
| { type: 'AUTO_UPDATE', data: boolean }
;
= { type: 'DATA_CONTEXT_SELECTION', data: SolutionData }
| { type: 'DEBUG_ADAPTERS', data: DebugAdapter[], sectionsInUse: string[] }
| { type: 'DEBUGGER', data: string }
| { type: 'ACTIVE_TARGET_SET', data: ActiveTargetSet }
| { type: 'IS_DIRTY', data: boolean }
| { type: 'IS_BUSY', data: boolean }
| { type: 'FILE_SELECTED', data: string[], for: string }
| { type: 'AUTO_UPDATE', data: boolean }
;
26 changes: 26 additions & 0 deletions src/views/manage-solution/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright 2024-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.
*/

export type PathType = 'absolute' | 'relative';

export type FileSelectorOptionsType = {
canSelectMany?: boolean,
defaultUri?: string,
openLabel?: string,
title?: string,
pathType?: PathType,
filters?: { [key: string]: string[] }
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { SolutionUpdateAction, contextUpdateReducer, initialState, manageSolutio
import './manage-solution.css';
import { ProjectsTable } from './projects-table';
import { TargetsTable } from './targets-table';
import { PathType } from '../../types';

export interface ManageSolutionProps {
messageHandler: MessageHandler<IncomingMessage, OutgoingMessage>;
Expand Down Expand Up @@ -212,6 +213,8 @@ export const ManageSolution = (props: ManageSolutionProps) => {
input?.setAttribute('id', id);
}
const title = input?.getAttribute('title') || 'Select File';
const dataOptionPathType = input?.getAttribute('data-option-path-type');
const optionPathType: PathType = dataOptionPathType === 'absolute' ? 'absolute' : 'relative';
const currentValue = input?.value || '';
props.messageHandler.push({
type: 'SELECT_FILE',
Expand All @@ -221,7 +224,8 @@ export const ManageSolution = (props: ManageSolutionProps) => {
defaultUri: currentValue,
openLabel: 'Select File', // title of the dialog button to choose the file
title: title, // dialog title
filters: { 'All Files': ['*'] }
filters: { 'All Files': ['*'] },
pathType: optionPathType
}
});
};
Expand Down Expand Up @@ -433,6 +437,7 @@ export const ManageSolution = (props: ManageSolutionProps) => {
addonAfter={<Button type="primary" className='file-button' onClick={selectFile}> Browse</Button>}
value={(localValues[k] as string) ?? ''}
data-yml-node={o['yml-node']}
data-option-path-type={o['path-type']}
onPressEnter={blurOnEnter}
onChange={(e) => {
setLocalValues(prev => ({ ...prev, [k]: e.target.value }));
Expand Down