From 6e9f4495fd070a23405e2f295f975b38c3da8799 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Wed, 3 Aug 2022 23:17:20 -0400 Subject: [PATCH] settings: write settings safely if they are unregistered (ie. vscode-icons) --- src/config/user-settings.ts | 33 +++++++++++++++++++++++---------- src/context.ts | 5 +++++ src/extension.ts | 9 +++++---- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/config/user-settings.ts b/src/config/user-settings.ts index c0bef94..59ee0df 100644 --- a/src/config/user-settings.ts +++ b/src/config/user-settings.ts @@ -1,4 +1,5 @@ import * as vscode from "vscode"; +import { getMainChannel } from "../context"; import { getConfig } from "./config"; // Settings defined in `configurationDefaults` are not merged with user settings @@ -58,11 +59,18 @@ export async function setVSIconAssociations() { } } } - await userConfig.update( - "vsicons.associations.files", - currentIconAssociations, - vscode.ConfigurationTarget.Global - ); + // Throws error if the user doesn't have these settings + try { + await userConfig.update( + "vsicons.associations.files", + currentIconAssociations, + vscode.ConfigurationTarget.Global + ); + } catch (err) { + getMainChannel().append( + `Failed to write icon configuration override - ${err}` + ); + } } // Could not use colors because of - https://github.com/Microsoft/vscode/issues/32813 @@ -275,9 +283,14 @@ export async function setTextmateColors() { currentTokenColorCustomizations.textMateRules = newRules; - await userConfig.update( - "editor.tokenColorCustomizations", - currentTokenColorCustomizations, - vscode.ConfigurationTarget.Global - ); + // Throws error if the user doesn't have these settings + try { + await userConfig.update( + "editor.tokenColorCustomizations", + currentTokenColorCustomizations, + vscode.ConfigurationTarget.Global + ); + } catch (err) { + getMainChannel().append(`Failed to write textmate rule override - ${err}`); + } } diff --git a/src/context.ts b/src/context.ts index 509b078..0825615 100644 --- a/src/context.ts +++ b/src/context.ts @@ -3,6 +3,7 @@ import * as vscode from "vscode"; import { RecentFiles } from "./RecentFiles"; +const channel = vscode.window.createOutputChannel("OpenGOAL"); let extensionContext: vscode.ExtensionContext; let recentFiles: RecentFiles; @@ -22,3 +23,7 @@ export function getRecentFiles() { export function getExtensionContext() { return extensionContext; } + +export function getMainChannel() { + return channel; +} diff --git a/src/extension.ts b/src/extension.ts index c1d4ba0..b0c4ec5 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -7,13 +7,11 @@ import { import { PdfCustomProvider } from "./vendor/vscode-pdfviewer/pdfProvider"; import { switchFile } from "./utils/file-utils"; import { activateDecompTools } from "./decomp/decomp-tools"; -import { initContext } from "./context"; +import { getMainChannel, initContext } from "./context"; import { IRFoldingRangeProvider } from "./languages/ir2-folder"; import { activateTypeCastTools } from "./decomp/type-caster"; import { IRInlayHintsProvider } from "./languages/ir2-inlay-hinter"; -const channel = vscode.window.createOutputChannel("OpenGOAL"); - export async function activate(context: vscode.ExtensionContext) { try { // Init Context @@ -66,7 +64,10 @@ export async function activate(context: vscode.ExtensionContext) { // Start the LSP lsp.activate(context); } catch (err) { - channel.append(`Failed to activate extension - ${err}`); + vscode.window.showErrorMessage( + "Failed to activate OpenGOAL extension, see logs for details" + ); + getMainChannel().append(`Failed to activate extension - ${err}`); } }