Skip to content

Commit 77e11b6

Browse files
committed
Some code refactoring
Signed-off-by: paulober <[email protected]>
1 parent cefe28c commit 77e11b6

File tree

3 files changed

+41
-44
lines changed

3 files changed

+41
-44
lines changed

src/commands/launchTargetPath.mts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
99
}
1010

1111
private async readProjectNameFromCMakeLists(
12-
filename: string): Promise<string | null> {
12+
filename: string
13+
): Promise<string | null> {
1314
// Read the file
1415
const fileContent = readFileSync(filename, "utf-8");
1516

@@ -26,7 +27,7 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
2627
// Extract the project name from the matched result
2728
if (match && match[1]) {
2829
const projectName = match[1].trim();
29-
30+
3031
if (matchBg && matchPoll) {
3132
// For examples with both background and poll, let user pick which to run
3233
const quickPickItems = ["Threadsafe Background", "Poll"];
@@ -36,7 +37,7 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
3637
if (backgroundOrPoll === undefined) {
3738
return projectName;
3839
}
39-
40+
4041
switch (backgroundOrPoll) {
4142
case quickPickItems[0]:
4243
return projectName + "_background";
@@ -69,7 +70,9 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
6970
return "";
7071
}
7172

72-
return join(fsPathFolder, "build", projectName + ".elf")
73-
.replaceAll("\\", "/");
73+
return join(fsPathFolder, "build", projectName + ".elf").replaceAll(
74+
"\\",
75+
"/"
76+
);
7477
}
7578
}

src/commands/openSdkDocumentation.mts

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/* eslint-disable max-len */
22
import { CommandWithArgs } from "./command.mjs";
33
import Logger from "../logger.mjs";
4-
import { type QuickPickItem, ViewColumn, window, Uri, type WebviewPanel } from "vscode";
4+
import {
5+
type QuickPickItem,
6+
ViewColumn,
7+
window,
8+
Uri,
9+
type WebviewPanel,
10+
} from "vscode";
511
import { readFileSync } from "fs";
612

713
export enum DocumentationId {
@@ -38,7 +44,7 @@ export default class OpenSdkDocumentationCommand extends CommandWithArgs {
3844
private _logger: Logger = new Logger("OpenSdkDocumentationCommand");
3945

4046
public static readonly id = "openSdkDocumentation";
41-
private _panel: WebviewPanel|undefined = undefined;
47+
private _panel: WebviewPanel | undefined = undefined;
4248

4349
constructor(private readonly _extensionUri: Uri) {
4450
super(OpenSdkDocumentationCommand.id);
@@ -73,7 +79,7 @@ export default class OpenSdkDocumentationCommand extends CommandWithArgs {
7379

7480
// show webview
7581
this._logger.info("Opening SDK documentation in browser...");
76-
if (this._panel === undefined){
82+
if (this._panel === undefined) {
7783
Logger.log("New panel");
7884
this._panel = window.createWebviewPanel(
7985
"pico-sdk-documentation",
@@ -100,11 +106,9 @@ export default class OpenSdkDocumentationCommand extends CommandWithArgs {
100106
panel.reveal();
101107

102108
// dispose when hidden
103-
panel.onDidDispose(
104-
event => {
105-
this._panel = undefined;
106-
}, this
107-
);
109+
panel.onDidDispose(() => {
110+
this._panel = undefined;
111+
}, this);
108112
}
109113

110114
private _getHtmlForWebview(
@@ -133,49 +137,39 @@ export default class OpenSdkDocumentationCommand extends CommandWithArgs {
133137
if (space === undefined) {
134138
space = "";
135139
}
136-
if (file.match('#') || file.match('https')) {
137-
if (file.match('#')) {
138-
file = `#${file.split('#')[1]}`;
140+
if (file.match("#") || file.match("https")) {
141+
if (file.match("#")) {
142+
file = `#${file.split("#")[1]}`;
139143
}
140144
const ret = `<a ${space}href="${file}"`;
141145

142146
return ret;
143147
}
144-
const command = Uri.parse(`command:raspberry-pi-pico.openSdkDocumentation?${
145-
encodeURIComponent(JSON.stringify([undefined, file]))
146-
}`).toString();
148+
const command = Uri.parse(
149+
`command:raspberry-pi-pico.openSdkDocumentation?${encodeURIComponent(
150+
JSON.stringify([undefined, file])
151+
)}`
152+
).toString();
147153
const ret = `<a ${space}href="${command}"`;
148154

149155
return ret;
150156
})
151157
.replace(regexsrc, function (match, file: string) {
152-
const ret = `src="${
153-
panel.webview
154-
.asWebviewUri(
155-
Uri.joinPath(extensionUri, "web", "docs", file)
156-
)
157-
.toString()}"`;
158+
const ret = `src="${panel.webview
159+
.asWebviewUri(Uri.joinPath(extensionUri, "web", "docs", file))
160+
.toString()}"`;
158161

159162
return ret;
160163
})
161164
.replace(regexcss, function (match, file: string) {
162-
const ret = `<link href="${
163-
panel.webview
164-
.asWebviewUri(
165-
Uri.joinPath(extensionUri, "web", "docs", file)
166-
)
167-
.toString()}" rel="stylesheet"`;
165+
const ret = `<link href="${panel.webview
166+
.asWebviewUri(Uri.joinPath(extensionUri, "web", "docs", file))
167+
.toString()}" rel="stylesheet"`;
168168

169169
return ret;
170170
})
171-
.replace(
172-
'<div class="navigation-toggle">',
173-
'<div hidden>'
174-
)
175-
.replace(
176-
'<div id="main-nav">',
177-
'<div id="main-nav" hidden>'
178-
)
171+
.replace('<div class="navigation-toggle">', "<div hidden>")
172+
.replace('<div id="main-nav">', '<div id="main-nav" hidden>')
179173
);
180174
}
181175
}

src/settings.mts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,28 @@ const LAST_PROJECT_ROOT_STATE_KEY = "lastProjectRoot";
3636
export default class Settings {
3737
private static instance?: Settings;
3838
private config: WorkspaceConfiguration;
39-
public context: Memento;
39+
public workspaceState: Memento;
4040
public globalState: GlobalStateType;
4141
private pkg: PackageJSON;
4242

4343
private constructor(
44-
context: Memento,
44+
workspaceState: Memento,
4545
globalState: GlobalStateType,
4646
packageJSON: PackageJSON
4747
) {
48-
this.context = context;
48+
this.workspaceState = workspaceState;
4949
this.globalState = globalState;
5050
this.pkg = packageJSON;
5151

5252
this.config = workspace.getConfiguration(packageJSON.name);
5353
}
5454

5555
public static createInstance(
56-
context: Memento,
56+
workspaceState: Memento,
5757
globalState: GlobalStateType,
5858
packageJSON: PackageJSON
5959
): Settings {
60-
Settings.instance = new Settings(context, globalState, packageJSON);
60+
Settings.instance = new Settings(workspaceState, globalState, packageJSON);
6161

6262
return Settings.instance;
6363
}

0 commit comments

Comments
 (0)