-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca5dac0
commit 0e9286f
Showing
7 changed files
with
75 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { format as malva_fmt, initSync as malva_init } from "malva"; | ||
import malva_wasm from "malva/standalone_wasm_bg.wasm"; | ||
import * as vscode from "vscode"; | ||
import { Logger } from "../logger"; | ||
|
||
const logger = new Logger("malva-format"); | ||
|
||
export default async function init(context: vscode.ExtensionContext) { | ||
const wasm_uri = vscode.Uri.joinPath(context.extensionUri, malva_wasm); | ||
|
||
const bits = await vscode.workspace.fs.readFile(wasm_uri); | ||
malva_init(bits); | ||
} | ||
|
||
export function formattingSubscription() { | ||
return vscode.languages.registerDocumentFormattingEditProvider( | ||
["css", "scss", "sass", "less"], | ||
{ | ||
provideDocumentFormattingEdits(document, options, token) { | ||
const text = document.getText(); | ||
|
||
const useTabs = !options.insertSpaces; | ||
const indentWidth = options.tabSize; | ||
|
||
try { | ||
const formatted = malva_fmt(text, document.languageId, { | ||
useTabs, | ||
indentWidth, | ||
}); | ||
|
||
const range = document.validateRange( | ||
new vscode.Range( | ||
document.positionAt(0), | ||
document.positionAt(text.length) | ||
) | ||
); | ||
return [vscode.TextEdit.replace(range, formatted)]; | ||
} catch (error) { | ||
logger.error(error); | ||
return []; | ||
} | ||
}, | ||
} | ||
); | ||
} |