From 0d78983cef76f61276423c346269bafad2b398bf Mon Sep 17 00:00:00 2001 From: Joop van de Pol Date: Tue, 8 Oct 2024 16:13:57 +0200 Subject: [PATCH 1/2] Fix git config bug when updating through codemarker --- src/codeMarker.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/codeMarker.ts b/src/codeMarker.ts index 2fd267b..23f8f9c 100644 --- a/src/codeMarker.ts +++ b/src/codeMarker.ts @@ -249,7 +249,13 @@ class WARoot { * Saves the client's remote repository to the current user's file */ persistClientRemote(): void { - vscode.commands.executeCommand("weAudit.setGitConfigView", [this.rootPath, this.rootLabel], this.clientRemote, this.gitRemote, this.gitSha); + vscode.commands.executeCommand( + "weAudit.setGitConfigView", + { rootPath: this.rootPath, rootLabel: this.rootLabel } as RootPathAndLabel, + this.clientRemote, + this.gitRemote, + this.gitSha, + ); const vscodeFolder = path.join(this.rootPath, ".vscode"); // create .vscode folder if it doesn't exist if (!fs.existsSync(vscodeFolder)) { @@ -281,7 +287,13 @@ class WARoot { * Saves the audit remote repository to the current user's file */ persistAuditRemote(): void { - vscode.commands.executeCommand("weAudit.setGitConfigView", [this.rootPath, this.rootLabel], this.clientRemote, this.gitRemote, this.gitSha); + vscode.commands.executeCommand( + "weAudit.setGitConfigView", + { rootPath: this.rootPath, rootLabel: this.rootLabel } as RootPathAndLabel, + this.clientRemote, + this.gitRemote, + this.gitSha, + ); const vscodeFolder = path.join(this.rootPath, ".vscode"); // create .vscode folder if it doesn't exist if (!fs.existsSync(vscodeFolder)) { @@ -313,7 +325,13 @@ class WARoot { * Saves the relevant git hash to the current user's file */ persistGitHash(): void { - vscode.commands.executeCommand("weAudit.setGitConfigView", [this.rootPath, this.rootLabel], this.clientRemote, this.gitRemote, this.gitSha); + vscode.commands.executeCommand( + "weAudit.setGitConfigView", + { rootPath: this.rootPath, rootLabel: this.rootLabel } as RootPathAndLabel, + this.clientRemote, + this.gitRemote, + this.gitSha, + ); const vscodeFolder = path.join(this.rootPath, ".vscode"); // create .vscode folder if it doesn't exist if (!fs.existsSync(vscodeFolder)) { From 7e2c9a48727ee5fd187e6721784a7aa6f5029fe2 Mon Sep 17 00:00:00 2001 From: Joop van de Pol Date: Tue, 8 Oct 2024 16:19:52 +0200 Subject: [PATCH 2/2] Linter suddenly complains about function return types --- src/decorationManager.ts | 14 +++++++------- src/extension.ts | 2 +- src/multiConfigs.ts | 2 +- src/panels/findingDetailsPanel.ts | 10 +++++----- src/panels/gitConfigPanel.ts | 10 +++++----- src/utilities/getUri.ts | 2 +- src/webview/findingDetailsMain.ts | 2 +- src/webview/gitConfigMain.ts | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/decorationManager.ts b/src/decorationManager.ts index c38c472..c7b9418 100644 --- a/src/decorationManager.ts +++ b/src/decorationManager.ts @@ -26,7 +26,7 @@ export class DecorationManager { this.auditedFileDecorationType = this.loadAuditedDecorationConfiguration(); } - private createDecorationTypeWithString(color: string) { + private createDecorationTypeWithString(color: string): vscode.TextEditorDecorationType { return vscode.window.createTextEditorDecorationType({ isWholeLine: true, backgroundColor: color, @@ -37,31 +37,31 @@ export class DecorationManager { }); } - private loadOwnDecorationConfiguration() { + private loadOwnDecorationConfiguration(): vscode.TextEditorDecorationType { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const color: string = vscode.workspace.getConfiguration("weAudit").get("ownFindingColor")!; return this.createDecorationTypeWithString(color); } - private loadOtherDecorationConfiguration() { + private loadOtherDecorationConfiguration(): vscode.TextEditorDecorationType { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const color: string = vscode.workspace.getConfiguration("weAudit").get("otherFindingColor")!; return this.createDecorationTypeWithString(color); } - private loadOwnNoteDecorationConfiguration() { + private loadOwnNoteDecorationConfiguration(): vscode.TextEditorDecorationType { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const color: string = vscode.workspace.getConfiguration("weAudit").get("ownNoteColor")!; return this.createDecorationTypeWithString(color); } - private loadOtherNoteDecorationConfiguration() { + private loadOtherNoteDecorationConfiguration(): vscode.TextEditorDecorationType { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const color: string = vscode.workspace.getConfiguration("weAudit").get("otherNoteColor")!; return this.createDecorationTypeWithString(color); } - private loadAuditedDecorationConfiguration() { + private loadAuditedDecorationConfiguration(): vscode.TextEditorDecorationType { return vscode.window.createTextEditorDecorationType({ isWholeLine: true, backgroundColor: vscode.workspace.getConfiguration("weAudit").get("auditedColor"), @@ -72,7 +72,7 @@ export class DecorationManager { * Reload all decoration configurations. * TODO: make it possible to reload only one decoration type */ - public reloadAllDecorationConfigurations() { + public reloadAllDecorationConfigurations(): void { // dispose old decoration types. This is necessary to clean up old decoration types, // otherwise they would be left over and we wouldn't be able to remove them. this.ownFindingDecorationType.dispose(); diff --git a/src/extension.ts b/src/extension.ts index 7aef38d..9e2b907 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -7,7 +7,7 @@ import { MultipleSavedFindings } from "./multiConfigs"; import { activateFindingDetailsWebview } from "./panels/findingDetailsPanel"; import { activateGitConfigWebview } from "./panels/gitConfigPanel"; -export function activate(context: vscode.ExtensionContext) { +export function activate(context: vscode.ExtensionContext): void { // if there are no open folders, return // the extension will be reactivated when a folder is opened if (vscode.workspace.workspaceFolders === undefined) { diff --git a/src/multiConfigs.ts b/src/multiConfigs.ts index 347b5a8..2800512 100644 --- a/src/multiConfigs.ts +++ b/src/multiConfigs.ts @@ -54,7 +54,7 @@ export class MultipleSavedFindingsTree implements vscode.TreeDataProvider { const command = message.command; @@ -105,6 +105,6 @@ class FindingDetailsProvider implements vscode.WebviewViewProvider { } } -function getNonce() { +function getNonce(): string { return crypto.randomBytes(16).toString("base64"); } diff --git a/src/panels/gitConfigPanel.ts b/src/panels/gitConfigPanel.ts index 0928bc4..16d69b4 100644 --- a/src/panels/gitConfigPanel.ts +++ b/src/panels/gitConfigPanel.ts @@ -5,7 +5,7 @@ import { getUri } from "../utilities/getUri"; import { WebviewMessage, UpdateRepositoryMessage, SetWorkspaceRootsMessage } from "../webview/webviewMessageTypes"; import { RootPathAndLabel } from "../types"; -export function activateGitConfigWebview(context: vscode.ExtensionContext) { +export function activateGitConfigWebview(context: vscode.ExtensionContext): void { const provider = new GitConfigProvider(context.extensionUri); context.subscriptions.push(vscode.window.registerWebviewViewProvider(GitConfigProvider.viewType, provider)); @@ -77,7 +77,7 @@ class GitConfigProvider implements vscode.WebviewViewProvider { }); } - public resolveWebviewView(webviewView: vscode.WebviewView, _context: vscode.WebviewViewResolveContext, _token: vscode.CancellationToken) { + public resolveWebviewView(webviewView: vscode.WebviewView, _context: vscode.WebviewViewResolveContext, _token: vscode.CancellationToken): void { this._view = webviewView; webviewView.webview.options = { @@ -99,7 +99,7 @@ class GitConfigProvider implements vscode.WebviewViewProvider { }); } - private _getHtmlForWebview(webview: vscode.Webview) { + private _getHtmlForWebview(webview: vscode.Webview): string { // Get the local path to main script run in the webview, then convert it to a uri we can use in the webview. const styleUri = getUri(webview, this._extensionUri, ["media", "style.css"]); const webviewUri = getUri(webview, this._extensionUri, ["out", "gitConfigWebview.js"]); @@ -130,7 +130,7 @@ class GitConfigProvider implements vscode.WebviewViewProvider { `; } - private _setWebviewMessageListener(webview: vscode.Webview) { + private _setWebviewMessageListener(webview: vscode.Webview): void { webview.onDidReceiveMessage( (message: WebviewMessage) => { const command = message.command; @@ -169,6 +169,6 @@ class GitConfigProvider implements vscode.WebviewViewProvider { } } -function getNonce() { +function getNonce(): string { return crypto.randomBytes(16).toString("base64"); } diff --git a/src/utilities/getUri.ts b/src/utilities/getUri.ts index c50e623..3aaf889 100644 --- a/src/utilities/getUri.ts +++ b/src/utilities/getUri.ts @@ -11,6 +11,6 @@ import { Uri, Webview } from "vscode"; * @param pathList An array of strings representing the path to a file/resource * @returns A URI pointing to the file/resource */ -export function getUri(webview: Webview, extensionUri: Uri, pathList: string[]) { +export function getUri(webview: Webview, extensionUri: Uri, pathList: string[]): Uri { return webview.asWebviewUri(Uri.joinPath(extensionUri, ...pathList)); } diff --git a/src/webview/findingDetailsMain.ts b/src/webview/findingDetailsMain.ts index 6d94c57..545cb1b 100644 --- a/src/webview/findingDetailsMain.ts +++ b/src/webview/findingDetailsMain.ts @@ -15,7 +15,7 @@ const vscode = acquireVsCodeApi(); // or toolkit components window.addEventListener("load", main); -function main() { +function main(): void { const titleField = document.getElementById("label-area") as TextField; titleField?.addEventListener("change", handlePersistentFieldChange); diff --git a/src/webview/gitConfigMain.ts b/src/webview/gitConfigMain.ts index 66f69ce..18549e7 100644 --- a/src/webview/gitConfigMain.ts +++ b/src/webview/gitConfigMain.ts @@ -14,7 +14,7 @@ const vscode = acquireVsCodeApi(); // or toolkit components window.addEventListener("load", main); -function main() { +function main(): void { const rootDropdown = document.getElementById("workspace-root-list-dropdown") as Dropdown; rootDropdown?.addEventListener("change", handleDropdownChange);