From def730f32af2cca6a4faeed550e5b0c05c1ff9b7 Mon Sep 17 00:00:00 2001 From: Myriad-Dreamin <35292584+Myriad-Dreamin@users.noreply.github.com> Date: Sun, 15 Dec 2024 16:06:07 +0800 Subject: [PATCH] feat: update way and add config about word separator (#1002) --- editors/vscode/Configuration.md | 10 ++++++++++ editors/vscode/package.json | 14 ++++++++++++++ editors/vscode/src/config.ts | 2 +- editors/vscode/src/extension.ts | 15 ++++++++++----- editors/vscode/src/state.ts | 2 ++ 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/editors/vscode/Configuration.md b/editors/vscode/Configuration.md index b00942298..630d0467c 100644 --- a/editors/vscode/Configuration.md +++ b/editors/vscode/Configuration.md @@ -24,6 +24,16 @@ Configure the root for absolute paths in typst. Hint: you can set the rootPath t - **Type**: `string` or `null` +## `tinymist.configureDefaultWordSeparator` + +Whether to configure default word separators on startup + +- **Type**: `string` +- **Enum**: + - `enable`: Override the default word separators on startup + - `disable`: Do not override the default word separators on startup +- **Default**: `"enable"` + ## `tinymist.semanticTokens` Enable or disable semantic tokens (LSP syntax highlighting) diff --git a/editors/vscode/package.json b/editors/vscode/package.json index f701cbc3f..b1d5169e3 100644 --- a/editors/vscode/package.json +++ b/editors/vscode/package.json @@ -308,6 +308,20 @@ ], "default": null }, + "tinymist.configureDefaultWordSeparator": { + "title": "Configure default word separators", + "description": "Whether to configure default word separators on startup", + "type": "string", + "default": "enable", + "enum": [ + "enable", + "disable" + ], + "enumDescriptions": [ + "Override the default word separators on startup", + "Do not override the default word separators on startup" + ] + }, "tinymist.semanticTokens": { "title": "Semantic tokens mode", "description": "Enable or disable semantic tokens (LSP syntax highlighting)", diff --git a/editors/vscode/src/config.ts b/editors/vscode/src/config.ts index c313b483f..5122ae7d4 100644 --- a/editors/vscode/src/config.ts +++ b/editors/vscode/src/config.ts @@ -69,7 +69,7 @@ function substVscodeVars(str: string | null | undefined): string | undefined { } function determineVscodeTheme(): any { - console.log("determineVscodeTheme", vscode.window.activeColorTheme.kind); + // console.log("determineVscodeTheme", vscode.window.activeColorTheme.kind); switch (vscode.window.activeColorTheme.kind) { case vscode.ColorThemeKind.Dark: case vscode.ColorThemeKind.HighContrast: diff --git a/editors/vscode/src/extension.ts b/editors/vscode/src/extension.ts index fe12e2a8a..10257888b 100644 --- a/editors/vscode/src/extension.ts +++ b/editors/vscode/src/extension.ts @@ -69,6 +69,7 @@ export async function doActivate(context: ExtensionContext): Promise { config.supportHtmlInMarkdown = true; // Sets features extensionState.features.preview = config.previewFeature === "enable"; + extensionState.features.wordSeparator = config.configureDefaultWordSeparator !== "disable"; extensionState.features.devKit = isDevMode || config.devKit === "enable"; extensionState.features.dragAndDrop = config.dragAndDrop === "enable"; extensionState.features.onEnter = !!config.onEnterEvent; @@ -78,14 +79,18 @@ export async function doActivate(context: ExtensionContext): Promise { let configWordSeparators = async () => { const wordSeparators = "`~!@#$%^&*()=+[{]}\\|;:'\",.<>/?"; const config1 = vscode.workspace.getConfiguration("", { languageId: "typst" }); - await config1.update("editor.wordSeparators", wordSeparators, false, true); + await config1.update("editor.wordSeparators", wordSeparators, true, true); const config2 = vscode.workspace.getConfiguration("", { languageId: "typst-code" }); - await config2.update("editor.wordSeparators", wordSeparators, false, true); + await config2.update("editor.wordSeparators", wordSeparators, true, true); }; // Runs configuration asynchronously to avoid blocking the activation - configWordSeparators().catch((e) => - console.error("cannot change editor.wordSeparators for typst", e), - ); + if (extensionState.features.wordSeparator) { + configWordSeparators().catch((e) => + console.error("cannot change editor.wordSeparators for typst", e), + ); + } else { + // console.log("skip configuring word separator on startup"); + } // Configures advanced language configuration tinymist.configureLanguage(config["typingContinueCommentsOnNewline"]); diff --git a/editors/vscode/src/state.ts b/editors/vscode/src/state.ts index c9a7051eb..394032ad4 100644 --- a/editors/vscode/src/state.ts +++ b/editors/vscode/src/state.ts @@ -6,6 +6,7 @@ interface ExtensionState { features: { task: boolean; devKit: boolean; + wordSeparator: boolean; dragAndDrop: boolean; onEnter: boolean; preview: boolean; @@ -22,6 +23,7 @@ interface ExtensionState { export const extensionState: ExtensionState = { features: { task: true, + wordSeparator: true, devKit: false, dragAndDrop: false, onEnter: false,