Skip to content

Commit 3873534

Browse files
Open user guide from Keil Studio pack extension folder or redirect to online version (#40)
* Open user guide from Keil Studio pack extension folder or redirect to online version * Fixup: Download tools script * Fixup: Unit tests * Fixup: Open README.md in preview mode * Fixup: Joining help path and unit test for Windows * Fixup: Copilot review feedback * Fixup: Unit tests
1 parent f1c83d6 commit 3873534

15 files changed

Lines changed: 99 additions & 106 deletions

.github/workflows/download-tools.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ function usage() {
1313

1414
function download_tools() {
1515
npm run download:uv2csolution -- --target "$1"
16-
npm run download:guide
1716
npm run download:toolbox -- --target "$1"
1817
npm run download:debug-adapters
1918
npm run download:node-pty -- --target "$1"

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"scripts": {
4343
"preprepare": "npm run download:rpc-interface",
44-
"prepare": "concurrently npm:download:uv2csolution npm:download:guide npm:download:debug-adapters npm:download:toolbox",
44+
"prepare": "concurrently npm:download:uv2csolution npm:download:debug-adapters npm:download:toolbox",
4545
"clean": "git clean -f -x ./dist ./out ./tools",
4646
"prebuild": "npm run font",
4747
"build": "webpack --mode production",
@@ -57,7 +57,6 @@
5757
"compile": "tsc -p .",
5858
"compile:watch": "tsc -p . -w",
5959
"download:uv2csolution": "tsx scripts/download-tools.ts uv2csolution",
60-
"download:guide": "tsx scripts/download-tools.ts guide",
6160
"download:debug-adapters": "tsx scripts/download-tools.ts debug-adapters",
6261
"download:toolbox": "tsx scripts/download-tools.ts toolbox",
6362
"download:rpc-interface": "tsx scripts/download-tools.ts rpc-interface",

scripts/download-tools.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ const uv2csolution : Downloadable = new Downloadable(
6060
},
6161
);
6262

63-
const guide : Downloadable = new Downloadable(
64-
'User Guide', ['..', 'guide'],
65-
async () => {
66-
return new GitHubRepoAsset('MDK-Packs', 'vscode-cmsis-solution-docs', { ref: 'heads/main', path: 'site', token: ghToken });
67-
},
68-
);
69-
7063
const debugAdapterRegistry = new Downloadable(
7164
'Debug Adapter Registry', ['..', 'templates', 'debug'],
7265
async () => {
@@ -153,7 +146,6 @@ const nodePty: Downloadable = new Downloadable(
153146

154147
const downloader = new Downloader({
155148
'uv2csolution': uv2csolution,
156-
'guide': guide,
157149
'debug-adapters': debugAdapterRegistry,
158150
'toolbox': toolbox,
159151
'rpc-interface': rpcInterface,

src/desktop/extension.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ export const activate = async (context: ExtensionContext): Promise<CsolutionExte
198198
commandsProvider,
199199
workspaceFoldersProvider,
200200
dataManager,
201-
externalFileOpener
202201
);
203202
const manageLayers = new ManageLayersWebviewMain(
204203
context,
@@ -223,7 +222,6 @@ export const activate = async (context: ExtensionContext): Promise<CsolutionExte
223222
context,
224223
solutionManager,
225224
commandsProvider,
226-
externalFileOpener,
227225
configurationProvider,
228226
csolutionService,
229227
);

src/manifest.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const CMSIS_SOLUTION_OUTPUT_CHANNEL = 'CMSIS Solution';
5555
export const TEMPLATES_FOLDER = path.join(__dirname, '..', 'templates');
5656
export const DEBUG_TEMPLATES_FOLDER = path.join(TEMPLATES_FOLDER, 'debug');
5757
export const UV2CSOLUTION_FOLDER = path.join(__dirname, '..', 'tools', 'uv2csolution');
58-
export const GUIDE_FOLDER = path.join(__dirname, '..', 'guide');
5958
export const DEBUG_ADAPTERS_YAML_FILE_PATH = path.resolve(DEBUG_TEMPLATES_FOLDER, 'debug-adapters.yml');
6059
export const CMSIS_TOOLBOX_FOLDER = path.join(__dirname, '..', 'tools', 'cmsis-toolbox');
60+
61+
export const README_FILE_PATH = path.join(__dirname, '..', 'README.md');

src/open-file-external.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,22 @@ import { tmpNameSync } from 'tmp';
2222

2323
import { backToForwardSlashes } from './utils/path-utils';
2424

25-
export const CMSIS_VSCODE_REDIRECTION_FILE_HTML = 'cmsis_vscode_redirectionFile.html';
26-
2725
/**
2826
* Class to call node_modules/open
2927
*/
3028
export class OpenFileExternal implements IOpenFileExternal {
29+
3130
public openFile(filePath: string) {
3231
const adjustedFilePath = this.adjustFilePath(filePath);
33-
const child = this.doOpenFile(this.getCommand(adjustedFilePath));
32+
this.doOpenFile(this.getCommand(adjustedFilePath));
3433
if (adjustedFilePath !== filePath) {
35-
child.on('exit', () => {
34+
setTimeout(() => {
3635
try {
3736
fs.unlinkSync(adjustedFilePath);
3837
} catch (error) {
3938
console.error(`Error deleting redirection file ${adjustedFilePath}:`, error);
4039
}
41-
});
40+
}, 10000);
4241
}
4342
return adjustedFilePath;
4443
}

src/solutions/solution-manager.factories.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ export type MockSolutionManager = jest.Mocked<StubEvents<SolutionManager>> & { f
2626

2727
export const idleSolutionLoadStateFactory = makeFactory<SolutionLoadState>({
2828
solutionPath: () => undefined,
29+
activated: () => false,
2930
loaded: () => undefined,
3031
converted: () => undefined,
3132
activated: () => undefined,
3233
});
3334

3435
export const activeSolutionLoadStateFactory = makeFactory<SolutionLoadState>({
3536
solutionPath: () => path.join(faker.system.filePath(), `${faker.word.noun()}.csolution.yml`),
37+
activated: () => true,
3638
loaded: () => undefined,
3739
converted: () => undefined,
3840
activated: () => true,

src/views/create-solutions/create-solution-webview-main.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import { PROJECT_SUFFIX } from '../../solutions/constants';
4343
import { dataManagerFactory, MockDataManager } from '../../data-manager/data-manager.factories';
4444
import { CreateSolutionFromDataManager } from '../../solutions/create-solution-from-data-manager';
4545
import { pathsEqual } from '../../utils/path-utils';
46-
import { MockOpenFileExternal } from '../../open-file-external.factories';
4746

4847
jest.mock('fs', () => ({
4948
existsSync: jest.fn(),
@@ -97,7 +96,6 @@ describe('CreateSolutionWebviewMain', () => {
9796
let commandsProvider: MockCommandsProvider;
9897
let mockReconcileSolutionFiles: jest.Mock;
9998
let mockSolutionInitialiser: MockSolutionInitialiser;
100-
let mockExternalFileOpener: MockOpenFileExternal;
10199
let mockCreateSolutionFromDataManager: jest.MockedFunction<CreateSolutionFromDataManager>;
102100
let mockOpenDialog: jest.Mock;
103101
let mockSolutionCreator: SolutionCreator;
@@ -123,12 +121,11 @@ describe('CreateSolutionWebviewMain', () => {
123121
mockReconcileSolutionFiles = jest.fn();
124122
mockCreateSolutionFromDataManager = jest.fn();
125123
mockSolutionInitialiser = SolutionInitialiserFactory();
126-
mockExternalFileOpener = new MockOpenFileExternal();
127124
mockOpenDialog = vscode.window.showOpenDialog as jest.Mock;
128125

129126
mockSolutionCreator = new SolutionCreatorImp(mockCreateSolutionFromDataManager, mockSolutionInitialiser, workspaceFsProvider, mockReconcileSolutionFiles);
130127

131-
webviewMain = new CreateSolutionWebviewMain(mockSolutionCreator, { extensionUri: EXTENSION_URI } as unknown as ExtensionContext, messageProvider, commandsProvider, workspaceFoldersProvider, dataManager, mockExternalFileOpener, webviewManager as unknown as WebviewManager<Messages.IncomingMessage, Messages.OutgoingMessage>);
128+
webviewMain = new CreateSolutionWebviewMain(mockSolutionCreator, { extensionUri: EXTENSION_URI } as unknown as ExtensionContext, messageProvider, commandsProvider, workspaceFoldersProvider, dataManager, webviewManager as unknown as WebviewManager<Messages.IncomingMessage, Messages.OutgoingMessage>);
132129

133130
await webviewMain.activate({ subscriptions: [] } as unknown as ExtensionContext);
134131

src/views/create-solutions/create-solution-webview-main.ts

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { WebviewManager, WebviewManagerOptions } from '../webview-manager';
2929
import { CreateSolutionData } from './create-solution-data';
3030
import * as Messages from './messages';
3131
import { NewSolutionMessage } from './messages';
32-
import { IOpenFileExternal } from '../../open-file-external-if';
32+
import { OpenCommand } from '../solution-outline/commands/open-command';
3333

3434
export const CREATE_SOLUTION_WEBVIEW_OPTIONS: Readonly<WebviewManagerOptions> =
3535
{
@@ -44,28 +44,23 @@ export const CREATE_SOLUTION_WEBVIEW_OPTIONS: Readonly<WebviewManagerOptions> =
4444
};
4545

4646
export class CreateSolutionWebviewMain {
47-
public static readonly HELP_URL = path.join(
48-
manifest.GUIDE_FOLDER,
49-
'create_app.html',
50-
);
5147
private readonly webviewManager: WebviewManager<
5248
Messages.IncomingMessage,
5349
Messages.OutgoingMessage
5450
>;
5551
private readonly dataModel: CreateSolutionData;
5652

5753
constructor(
58-
private readonly solutionCreator: SolutionCreator,
59-
private readonly context: vscode.ExtensionContext,
60-
private readonly messageProvider: MessageProvider,
61-
private readonly commandsProvider: CommandsProvider,
62-
private readonly workspaceFoldersProvider: WorkspaceFoldersProvider,
63-
private readonly dataManager: DataManager,
64-
private readonly openFileExternal: IOpenFileExternal,
65-
webviewManager?: WebviewManager<
66-
Messages.IncomingMessage,
67-
Messages.OutgoingMessage
68-
>,
54+
private readonly solutionCreator: SolutionCreator,
55+
private readonly context: vscode.ExtensionContext,
56+
private readonly messageProvider: MessageProvider,
57+
private readonly commandsProvider: CommandsProvider,
58+
private readonly workspaceFoldersProvider: WorkspaceFoldersProvider,
59+
private readonly dataManager: DataManager,
60+
webviewManager?: WebviewManager<
61+
Messages.IncomingMessage,
62+
Messages.OutgoingMessage
63+
>,
6964
) {
7065
this.webviewManager =
7166
webviewManager ||
@@ -90,17 +85,6 @@ export class CreateSolutionWebviewMain {
9085
this.webviewManager.onDidDispose(this.dataModel.reset.bind(this.dataModel));
9186
}
9287

93-
private openFile(path: string, openExternal?: boolean): void {
94-
if (openExternal) {
95-
this.openFileExternal.openFile(path);
96-
} else {
97-
this.commandsProvider.executeCommand(
98-
'vscode.open',
99-
vscode.Uri.file(path),
100-
);
101-
}
102-
}
103-
10488
private async handleMessage(
10589
message: Messages.OutgoingMessage,
10690
): Promise<void> {
@@ -176,7 +160,7 @@ export class CreateSolutionWebviewMain {
176160
await this.getDraftProjectInfo(message.id);
177161
break;
178162
case 'HELP_OPEN':
179-
this.openFile(CreateSolutionWebviewMain.HELP_URL, true);
163+
await this.commandsProvider.executeCommand(OpenCommand.openHelpCommandId, 'create_app.html');
180164
break;
181165
}
182166
this.webviewManager.sendMessage({

src/views/manage-solution/manage-solution-custom-editor.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { MANAGE_SOLUTION_WEBVIEW_OPTIONS } from './manage-solution-webview-main'
2222
import { IncomingMessage, OutgoingMessage } from './messages';
2323
import { SolutionManager } from '../../solutions/solution-manager';
2424
import { CommandsProvider } from '../../vscode-api/commands-provider';
25-
import { IOpenFileExternal } from '../../open-file-external-if';
2625
import { ConfigurationProvider } from '../../vscode-api/configuration-provider';
2726
import { CsolutionService } from '../../json-rpc/csolution-rpc-client';
2827
import { SolutionData } from './view/state/manage-solution-state';
@@ -117,7 +116,6 @@ export class ManageSolutionCustomEditorProvider implements vscode.CustomEditorPr
117116
private readonly context: vscode.ExtensionContext,
118117
private readonly solutionManager: SolutionManager,
119118
private readonly commandsProvider: CommandsProvider,
120-
private readonly openFileExternal: IOpenFileExternal,
121119
private readonly configurationProvider: ConfigurationProvider,
122120
private readonly csolutionService: CsolutionService,
123121
) { }
@@ -136,7 +134,6 @@ export class ManageSolutionCustomEditorProvider implements vscode.CustomEditorPr
136134
this.context,
137135
this.solutionManager,
138136
this.commandsProvider,
139-
this.openFileExternal,
140137
this.configurationProvider,
141138
this.csolutionService,
142139
(label, before, after) => this.activeDocument?.recordEdit(label, before, after),

0 commit comments

Comments
 (0)