Skip to content

Commit

Permalink
feat: configure word separator and pattern specific for typst (#990)
Browse files Browse the repository at this point in the history
* feat: configure word separator and pattern specific for typst

* dev: async and catch
  • Loading branch information
Myriad-Dreamin authored Dec 12, 2024
1 parent 382d73d commit 511ec2b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,14 @@
"configurationDefaults": {
"[typst]": {
"editor.wordWrap": "on",
"editor.wordSeparators": "`~!@#$%^&*()=+[{]}\\|;:'\",.<>/?",
"editor.semanticHighlighting.enabled": true,
"editor.tabSize": 2,
"editor.inlayHints.enabled": "off"
},
"[typst-code]": {
"editor.wordWrap": "on",
"editor.wordSeparators": "`~!@#$%^&*()=+[{]}\\|;:'\",.<>/?",
"editor.semanticHighlighting.enabled": true,
"editor.tabSize": 2,
"editor.inlayHints.enabled": "off"
Expand Down
13 changes: 13 additions & 0 deletions editors/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ export async function doActivate(context: ExtensionContext): Promise<void> {
extensionState.features.onEnter = !!config.onEnterEvent;
extensionState.features.renderDocs = config.renderDocs === "enable";

// Configures advanced editor settings to affect the host process
let configWordSeparators = async () => {
const wordSeparators = "`~!@#$%^&*()=+[{]}\\|;:'\",.<>/?";
const config1 = vscode.workspace.getConfiguration("", { languageId: "typst" });
await config1.update("editor.wordSeparators", wordSeparators, false, true);
const config2 = vscode.workspace.getConfiguration("", { languageId: "typst-code" });
await config2.update("editor.wordSeparators", wordSeparators, false, true);
};
// Runs configuration asynchronously to avoid blocking the activation
configWordSeparators().catch((e) =>
console.error("cannot change editor.wordSeparators for typst", e),
);

// Configures advanced language configuration
tinymist.configureLanguage(config["typingContinueCommentsOnNewline"]);
context.subscriptions.push(
Expand Down
4 changes: 4 additions & 0 deletions editors/vscode/src/lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,13 @@ class LanguageState {
];
}

const wordPattern =
/(-?\d*.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.<\>\/\?\s]+)/;

console.log("Setting up language configuration", typingContinueCommentsOnNewline);
this.configureLang = vscode.languages.setLanguageConfiguration("typst", {
onEnterRules,
wordPattern,
});
}
}
Expand Down

0 comments on commit 511ec2b

Please sign in to comment.