settings: write settings safely if they are unregistered (ie. vscode-icons)

This commit is contained in:
Tyler Wilding 2022-08-03 23:17:20 -04:00
parent c9c1a36f13
commit 6e9f4495fd
No known key found for this signature in database
GPG key ID: A89403EB356ED106
3 changed files with 33 additions and 14 deletions

View file

@ -1,4 +1,5 @@
import * as vscode from "vscode"; import * as vscode from "vscode";
import { getMainChannel } from "../context";
import { getConfig } from "./config"; import { getConfig } from "./config";
// Settings defined in `configurationDefaults` are not merged with user settings // Settings defined in `configurationDefaults` are not merged with user settings
@ -58,11 +59,18 @@ export async function setVSIconAssociations() {
} }
} }
} }
await userConfig.update( // Throws error if the user doesn't have these settings
"vsicons.associations.files", try {
currentIconAssociations, await userConfig.update(
vscode.ConfigurationTarget.Global "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 // Could not use colors because of - https://github.com/Microsoft/vscode/issues/32813
@ -275,9 +283,14 @@ export async function setTextmateColors() {
currentTokenColorCustomizations.textMateRules = newRules; currentTokenColorCustomizations.textMateRules = newRules;
await userConfig.update( // Throws error if the user doesn't have these settings
"editor.tokenColorCustomizations", try {
currentTokenColorCustomizations, await userConfig.update(
vscode.ConfigurationTarget.Global "editor.tokenColorCustomizations",
); currentTokenColorCustomizations,
vscode.ConfigurationTarget.Global
);
} catch (err) {
getMainChannel().append(`Failed to write textmate rule override - ${err}`);
}
} }

View file

@ -3,6 +3,7 @@
import * as vscode from "vscode"; import * as vscode from "vscode";
import { RecentFiles } from "./RecentFiles"; import { RecentFiles } from "./RecentFiles";
const channel = vscode.window.createOutputChannel("OpenGOAL");
let extensionContext: vscode.ExtensionContext; let extensionContext: vscode.ExtensionContext;
let recentFiles: RecentFiles; let recentFiles: RecentFiles;
@ -22,3 +23,7 @@ export function getRecentFiles() {
export function getExtensionContext() { export function getExtensionContext() {
return extensionContext; return extensionContext;
} }
export function getMainChannel() {
return channel;
}

View file

@ -7,13 +7,11 @@ import {
import { PdfCustomProvider } from "./vendor/vscode-pdfviewer/pdfProvider"; import { PdfCustomProvider } from "./vendor/vscode-pdfviewer/pdfProvider";
import { switchFile } from "./utils/file-utils"; import { switchFile } from "./utils/file-utils";
import { activateDecompTools } from "./decomp/decomp-tools"; import { activateDecompTools } from "./decomp/decomp-tools";
import { initContext } from "./context"; import { getMainChannel, initContext } from "./context";
import { IRFoldingRangeProvider } from "./languages/ir2-folder"; import { IRFoldingRangeProvider } from "./languages/ir2-folder";
import { activateTypeCastTools } from "./decomp/type-caster"; import { activateTypeCastTools } from "./decomp/type-caster";
import { IRInlayHintsProvider } from "./languages/ir2-inlay-hinter"; import { IRInlayHintsProvider } from "./languages/ir2-inlay-hinter";
const channel = vscode.window.createOutputChannel("OpenGOAL");
export async function activate(context: vscode.ExtensionContext) { export async function activate(context: vscode.ExtensionContext) {
try { try {
// Init Context // Init Context
@ -66,7 +64,10 @@ export async function activate(context: vscode.ExtensionContext) {
// Start the LSP // Start the LSP
lsp.activate(context); lsp.activate(context);
} catch (err) { } 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}`);
} }
} }