Skip to content

Commit 2a11b07

Browse files
arneschmidCopilot
andauthored
Fix/add relative path configuration debug adapters (#12)
* Enhance file selection functionality with relative/absolute path configuration and update copyright notices * Fix copyright formatting in manage-solution-custom-editor and manage-solution-webview-main files * Refactor test to use relative path for selected file in ContextSelectionWebviewMain * Update src/debug/debug-adapters-yaml-file.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/views/manage-solution/view/components/manage-solution.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor path type imports and create types file for better organization * Update src/debug/debug-adapters-yaml-file.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent f0c4c3c commit 2a11b07

6 files changed

Lines changed: 77 additions & 45 deletions

File tree

src/debug/debug-adapters-yaml-file.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ import { ITreeItem, CTreeItem } from '../generic/tree-item';
2020
import { CTreeItemYamlFile, ITreeItemFile } from '../generic/tree-item-file';
2121
import { Optional } from '../generic/type-helper';
2222
import { DEBUG_ADAPTERS_YAML_FILE_PATH } from '../manifest';
23+
import type { PathType } from '../views/manage-solution/types';
2324

2425

2526
export type UIOption<T extends string, V> = {
2627
name: string; //Label text for the option in the user interface.
2728
description?: string; //Hover over text.
2829
'yml-node': string; //Name of the node in the csolution file under debugger: section.
2930
type: T; //Type of the option [number, enum, string, file]
30-
pname?: string; //If present, the option is pname based. Then the same property will be created for each pname instance.
31+
pname?: string; //If present, the option is pname based. Then the same property will be created for each pname instance.
32+
'path-type'?: PathType; //If the type is file, indicates if the path is absolute or relative to the solution file directory. Default is relative.
3133
} & V;
3234

3335
export type UIEnumValue = {

src/views/manage-solution/manage-solution-webview-main.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -560,11 +560,13 @@ describe('ContextSelectionWebviewMain', () => {
560560

561561
const dialogOptions = showOpenDialogSpy.mock.calls[0][0];
562562
expect(dialogOptions?.defaultUri?.toString()).toBe(URI.file(path.dirname(defaultPath)).toString());
563-
expect(webviewManager.sendMessage).toHaveBeenCalledWith({
564-
type: 'FILE_SELECTED',
565-
data: ['images/app.axf'],
566-
for: 'image-path'
567-
});
563+
expect(webviewManager.sendMessage).toHaveBeenCalledWith(
564+
expect.objectContaining({
565+
type: 'FILE_SELECTED',
566+
data: ['images/app.axf'],
567+
for: 'image-path'
568+
})
569+
);
568570
});
569571
});
570572

src/views/manage-solution/manage-solution-webview-main.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ import { CommandsProvider } from '../../vscode-api/commands-provider';
2727
import { ConfigurationProvider } from '../../vscode-api/configuration-provider';
2828
import { WebviewManager, WebviewManagerOptions } from '../webview-manager';
2929
import { ManageSolutionController } from './manage-solution-controller';
30-
import { FileSelectorOptionsType, IncomingMessage, OutgoingMessage } from './messages';
30+
import { IncomingMessage, OutgoingMessage } from './messages';
3131
import { SolutionData } from './view/state/manage-solution-state';
3232
import { initialState } from './view/state/reducer';
3333
import debounce from 'lodash.debounce';
3434
import { CsolutionService } from '../../json-rpc/csolution-rpc-client';
3535
import { isDeepStrictEqual } from 'util';
36+
import { FileSelectorOptionsType } from './types';
3637

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

441442
if (fileUri && fileUri[0]) {
442443
const paths = fileUri.map(u =>
443-
backToForwardSlashes(path.relative(solutionDir, u.fsPath))
444+
backToForwardSlashes(options?.pathType === 'absolute'
445+
? u.fsPath
446+
: path.relative(solutionDir, u.fsPath)
447+
)
444448
);
445449

446450
await this.webviewManager.sendMessage({ type: 'FILE_SELECTED', data: paths, for: targetElementId });

src/views/manage-solution/messages.ts

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,43 @@
1515
*/
1616

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

20-
export type FileSelectorOptionsType = {
21-
canSelectMany?: boolean,
22-
defaultUri?: string,
23-
openLabel?: string,
24-
title?: string,
25-
filters?: { [key: string]: string[] }
26-
};
27-
2821
/**
2922
* Messages that the context selection view can pass to the extension.
3023
*/
3124
export type OutgoingMessage
32-
= { type: 'GET_CONTEXT_SELECTION_DATA' }
33-
| { type: 'SET_SELECTED_TARGET', target: string, set: string | undefined }
34-
| { type: 'OPEN_FILE', path: string }
35-
| { type: 'SET_SELECTED_CONTEXTS', data: SolutionData }
36-
| { type: 'GET_DEBUG_ADAPTERS' }
37-
| { type: 'SET_DEBUGGER', name: string }
38-
| { type: 'ADD_NEW_CONTEXT' }
39-
| { type: 'ADD_NEW_PROJECT' }
40-
| { type: 'ADD_NEW_IMAGE' }
41-
| { type: 'UNLINK_IMAGE', image: string }
42-
| { type: 'SET_START_PROCESSOR', value: string }
43-
| { type: 'SAVE_CONTEXT_SELECTION' }
44-
| { type: 'OPEN_HELP' }
45-
| { type: 'SET_DEBUG_ADAPTER_PROPERTY', service: string | undefined, key: string, value: string | number, pname?: string }
46-
| { type: 'SELECT_FILE', targetElementId: string, options?: FileSelectorOptionsType }
47-
| { type: 'SET_AUTO_UPDATE', value: boolean }
48-
| { type: 'TOGGLE_DEBUGGER', value: boolean }
49-
| { type: 'TOGGLE_DEBUG_ADAPTER_SECTION', section: string }
50-
;
25+
= { type: 'GET_CONTEXT_SELECTION_DATA' }
26+
| { type: 'SET_SELECTED_TARGET', target: string, set: string | undefined }
27+
| { type: 'OPEN_FILE', path: string }
28+
| { type: 'SET_SELECTED_CONTEXTS', data: SolutionData }
29+
| { type: 'GET_DEBUG_ADAPTERS' }
30+
| { type: 'SET_DEBUGGER', name: string }
31+
| { type: 'ADD_NEW_CONTEXT' }
32+
| { type: 'ADD_NEW_PROJECT' }
33+
| { type: 'ADD_NEW_IMAGE' }
34+
| { type: 'UNLINK_IMAGE', image: string }
35+
| { type: 'SET_START_PROCESSOR', value: string }
36+
| { type: 'SAVE_CONTEXT_SELECTION' }
37+
| { type: 'OPEN_HELP' }
38+
| { type: 'SET_DEBUG_ADAPTER_PROPERTY', service: string | undefined, key: string, value: string | number, pname?: string }
39+
| { type: 'SELECT_FILE', targetElementId: string, options?: FileSelectorOptionsType }
40+
| { type: 'SET_AUTO_UPDATE', value: boolean }
41+
| { type: 'TOGGLE_DEBUGGER', value: boolean }
42+
| { type: 'TOGGLE_DEBUG_ADAPTER_SECTION', section: string }
43+
;
5144

5245
/**
5346
* Messages that the extension can pass to the context selection view.
5447
*/
5548
export type IncomingMessage
56-
= { type: 'DATA_CONTEXT_SELECTION', data: SolutionData }
57-
| { type: 'DEBUG_ADAPTERS', data: DebugAdapter[], sectionsInUse: string[] }
58-
| { type: 'DEBUGGER', data: string }
59-
| { type: 'ACTIVE_TARGET_SET', data: ActiveTargetSet }
60-
| { type: 'IS_DIRTY', data: boolean }
61-
| { type: 'IS_BUSY', data: boolean }
62-
| { type: 'FILE_SELECTED', data: string[], for: string }
63-
| { type: 'AUTO_UPDATE', data: boolean }
64-
;
49+
= { type: 'DATA_CONTEXT_SELECTION', data: SolutionData }
50+
| { type: 'DEBUG_ADAPTERS', data: DebugAdapter[], sectionsInUse: string[] }
51+
| { type: 'DEBUGGER', data: string }
52+
| { type: 'ACTIVE_TARGET_SET', data: ActiveTargetSet }
53+
| { type: 'IS_DIRTY', data: boolean }
54+
| { type: 'IS_BUSY', data: boolean }
55+
| { type: 'FILE_SELECTED', data: string[], for: string }
56+
| { type: 'AUTO_UPDATE', data: boolean }
57+
;

src/views/manage-solution/types.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright 2024-2026 Arm Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export type PathType = 'absolute' | 'relative';
18+
19+
export type FileSelectorOptionsType = {
20+
canSelectMany?: boolean,
21+
defaultUri?: string,
22+
openLabel?: string,
23+
title?: string,
24+
pathType?: PathType,
25+
filters?: { [key: string]: string[] }
26+
};

src/views/manage-solution/view/components/manage-solution.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { SolutionUpdateAction, contextUpdateReducer, initialState, manageSolutio
2929
import './manage-solution.css';
3030
import { ProjectsTable } from './projects-table';
3131
import { TargetsTable } from './targets-table';
32+
import { PathType } from '../../types';
3233

3334
export interface ManageSolutionProps {
3435
messageHandler: MessageHandler<IncomingMessage, OutgoingMessage>;
@@ -212,6 +213,8 @@ export const ManageSolution = (props: ManageSolutionProps) => {
212213
input?.setAttribute('id', id);
213214
}
214215
const title = input?.getAttribute('title') || 'Select File';
216+
const dataOptionPathType = input?.getAttribute('data-option-path-type');
217+
const optionPathType: PathType = dataOptionPathType === 'absolute' ? 'absolute' : 'relative';
215218
const currentValue = input?.value || '';
216219
props.messageHandler.push({
217220
type: 'SELECT_FILE',
@@ -221,7 +224,8 @@ export const ManageSolution = (props: ManageSolutionProps) => {
221224
defaultUri: currentValue,
222225
openLabel: 'Select File', // title of the dialog button to choose the file
223226
title: title, // dialog title
224-
filters: { 'All Files': ['*'] }
227+
filters: { 'All Files': ['*'] },
228+
pathType: optionPathType
225229
}
226230
});
227231
};
@@ -433,6 +437,7 @@ export const ManageSolution = (props: ManageSolutionProps) => {
433437
addonAfter={<Button type="primary" className='file-button' onClick={selectFile}> Browse</Button>}
434438
value={(localValues[k] as string) ?? ''}
435439
data-yml-node={o['yml-node']}
440+
data-option-path-type={o['path-type']}
436441
onPressEnter={blurOnEnter}
437442
onChange={(e) => {
438443
setLocalValues(prev => ({ ...prev, [k]: e.target.value }));

0 commit comments

Comments
 (0)