-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
0 parents
commit d1c72cc
Showing
16 changed files
with
4,118 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
|
||
[*.js] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.json] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.{yml,yaml}] | ||
indent_size = 2 |
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,25 @@ | ||
{ | ||
"env": { | ||
"browser": false, | ||
"commonjs": true, | ||
"es6": true, | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"no-const-assign": "warn", | ||
"no-this-before-super": "warn", | ||
"no-undef": "warn", | ||
"no-unreachable": "warn", | ||
"no-unused-vars": "warn", | ||
"constructor-super": "warn", | ||
"valid-typeof": "warn" | ||
} | ||
} |
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,3 @@ | ||
node_modules | ||
.vscode-test/ | ||
*.vsix |
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,7 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the extensions.json format | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint" | ||
] | ||
} |
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,28 @@ | ||
// A launch configuration that launches the extension inside a new window | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Run Extension", | ||
"type": "extensionHost", | ||
"request": "launch", | ||
"runtimeExecutable": "${execPath}", | ||
"args": [ | ||
"--extensionDevelopmentPath=${workspaceFolder}" | ||
] | ||
}, | ||
{ | ||
"name": "Extension Tests", | ||
"type": "extensionHost", | ||
"request": "launch", | ||
"runtimeExecutable": "${execPath}", | ||
"args": [ | ||
"--extensionDevelopmentPath=${workspaceFolder}", | ||
"--extensionTestsPath=${workspaceFolder}/test/suite/index" | ||
] | ||
} | ||
] | ||
} |
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,8 @@ | ||
.vscode/** | ||
.vscode-test/** | ||
test/** | ||
.gitignore | ||
vsc-extension-quickstart.md | ||
**/jsconfig.json | ||
**/*.map | ||
**/.eslintrc.json |
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,4 @@ | ||
# 0.1.0 (2020-07-21) | ||
|
||
|
||
|
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,13 @@ | ||
# vscode-blade-formatter | ||
|
||
A Blade file formatter for VSCode | ||
|
||
## Extension Settings | ||
|
||
- `Blade Formatter: format Enabled`: Whether it enables or not | ||
- `Blade Formatter: format Indent Size`: An indent size | ||
|
||
|
||
## Release Notes | ||
|
||
see [CHANGELOG.md](https://github.com/shufo/vscode-blade-formatter/CHANGELOG.md) |
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,74 @@ | ||
const vscode = require("vscode"); | ||
const { Range, Position } = vscode; | ||
const vsctmModule = getCoreNodeModule("vscode-textmate"); | ||
const onigurumaModule = getCoreNodeModule("vscode-oniguruma"); | ||
|
||
require = require("esm")(module); | ||
const { default: Formatter } = require("blade-formatter/src/formatter"); | ||
|
||
let wasmInitialized = false; | ||
|
||
/** | ||
* @param {vscode.ExtensionContext} context | ||
*/ | ||
function activate(context) { | ||
context.subscriptions.push( | ||
vscode.languages.registerDocumentFormattingEditProvider("blade", { | ||
provideDocumentFormattingEdits(document) { | ||
const extConfig = vscode.workspace.getConfiguration( | ||
"bladeFormatter.format" | ||
); | ||
|
||
if (!wasmInitialized) { | ||
onigurumaModule.initCalled = false; | ||
wasmInitialized = true; | ||
} | ||
|
||
const originalText = document.getText(); | ||
const lastLine = document.lineAt(document.lineCount - 1); | ||
const range = new Range(new Position(0, 0), lastLine.range.end); | ||
|
||
if (!extConfig.enabled) { | ||
return [new vscode.TextEdit(range, originalText)]; | ||
} | ||
|
||
const options = { | ||
vsctm: vsctmModule, | ||
oniguruma: onigurumaModule, | ||
indentSize: extConfig.indentSize, | ||
}; | ||
|
||
return new Promise((resolve) => { | ||
return new Formatter(options) | ||
.formatContent(originalText) | ||
.then((text) => { | ||
resolve([new vscode.TextEdit(range, text)]); | ||
}); | ||
}); | ||
}, | ||
}) | ||
); | ||
} | ||
exports.activate = activate; | ||
|
||
function deactivate() {} | ||
|
||
/** | ||
* Returns a node module installed with VSCode, or null if it fails. | ||
*/ | ||
function getCoreNodeModule(moduleName) { | ||
try { | ||
return require(`${vscode.env.appRoot}/node_modules.asar/${moduleName}`); | ||
} catch (err) {} | ||
|
||
try { | ||
return require(`${vscode.env.appRoot}/node_modules/${moduleName}`); | ||
} catch (err) {} | ||
|
||
return null; | ||
} | ||
|
||
module.exports = { | ||
activate, | ||
deactivate, | ||
}; |
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,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es6", | ||
"checkJs": true, /* Typecheck .js files. */ | ||
"lib": [ | ||
"es6" | ||
] | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
Oops, something went wrong.