From bc29cf4d28816fa602edd0dbcebb73281c953713 Mon Sep 17 00:00:00 2001 From: Lej77 <31554212+Lej77@users.noreply.github.com> Date: Thu, 6 Apr 2023 02:55:53 +0200 Subject: [PATCH] extension specific config for formatOnSave feature --- extension/package.json | 30 ++++++++++++++++++++++++++++-- extension/src/main.ts | 11 ++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/extension/package.json b/extension/package.json index 3e4ca4b83..11b32ec88 100644 --- a/extension/package.json +++ b/extension/package.json @@ -42,7 +42,33 @@ "command": "extension.formatRsxDocument", "title": "Dioxus: Format RSX Document" } - ] + ], + "configuration": { + "properties": { + "dioxus.formatOnSave": { + "type": [ + "string" + ], + "default": "followFormatOnSave", + "enum": [ + "followFormatOnSave", + "enabled", + "disabled" + ], + "enumItemLabels": [ + "Follow the normal formatOnSave config", + "Enabled", + "Disabled" + ], + "enumDescriptions": [ + "Only format Rsx when saving files if the editor.formatOnSave config is enabled", + "Always format Rsx when a Rust file is saved", + "Never format Rsx when a file is saved" + ], + "description": "Format RSX when a file is saved." + } + } + } }, "scripts": { "vscode:prepublish": "npm run build-base -- --minify", @@ -73,4 +99,4 @@ "dependencies": { "vsce": "^2.9.2" } -} +} \ No newline at end of file diff --git a/extension/src/main.ts b/extension/src/main.ts index 989220456..be3740c7d 100644 --- a/extension/src/main.ts +++ b/extension/src/main.ts @@ -117,11 +117,16 @@ function fmtSelection() { function fmtDocumentOnSave(e: vscode.TextDocumentWillSaveEvent) { // check the settings to make sure format on save is configured - if (!vscode.workspace.getConfiguration('editor', e.document).get('formatOnSave')) { - return; + const dioxusConfig = vscode.workspace.getConfiguration('dioxus', e.document).get('formatOnSave'); + const globalConfig = vscode.workspace.getConfiguration('editor', e.document).get('formatOnSave'); + if ( + (dioxusConfig === 'enabled') || + (dioxusConfig !== 'disabled' && globalConfig) + ) { + fmtDocument(e.document); } - fmtDocument(e.document); } + function fmtDocument(document: vscode.TextDocument) { try { if (document.languageId !== "rust" || document.uri.scheme !== "file") {