extension specific config for formatOnSave feature
This commit is contained in:
1 parent
44be89ff38
commit
bc29cf4d28
2 files changed
+35
-4
No files matched your search
+27
-1
@@ -42,7 +42,33 @@
|
|||||||
"command": "extension.formatRsxDocument",
|
"command": "extension.formatRsxDocument",
|
||||||
"title": "Dioxus: Format RSX Document"
|
"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": {
|
"scripts": {
|
||||||
"vscode:prepublish": "npm run build-base -- --minify",
|
"vscode:prepublish": "npm run build-base -- --minify",
|
||||||
|
|||||||
@@ -117,11 +117,16 @@ function fmtSelection() {
|
|||||||
|
|
||||||
function fmtDocumentOnSave(e: vscode.TextDocumentWillSaveEvent) {
|
function fmtDocumentOnSave(e: vscode.TextDocumentWillSaveEvent) {
|
||||||
// check the settings to make sure format on save is configured
|
// check the settings to make sure format on save is configured
|
||||||
if (!vscode.workspace.getConfiguration('editor', e.document).get('formatOnSave')) {
|
const dioxusConfig = vscode.workspace.getConfiguration('dioxus', e.document).get('formatOnSave');
|
||||||
return;
|
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) {
|
function fmtDocument(document: vscode.TextDocument) {
|
||||||
try {
|
try {
|
||||||
if (document.languageId !== "rust" || document.uri.scheme !== "file") {
|
if (document.languageId !== "rust" || document.uri.scheme !== "file") {
|
||||||
|
|||||||
Reference in new issue
Block a user