Skip to content

Commit

Permalink
chore: Initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
shufo committed Jul 21, 2020
0 parents commit d1c72cc
Show file tree
Hide file tree
Showing 16 changed files with 4,118 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .editorconfig
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
25 changes: 25 additions & 0 deletions .eslintrc.json
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"
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.vscode-test/
*.vsix
7 changes: 7 additions & 0 deletions .vscode/extensions.json
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"
]
}
28 changes: 28 additions & 0 deletions .vscode/launch.json
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"
]
}
]
}
8 changes: 8 additions & 0 deletions .vscodeignore
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 0.1.0 (2020-07-21)



13 changes: 13 additions & 0 deletions README.md
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)
74 changes: 74 additions & 0 deletions extension.js
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,
};
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions jsconfig.json
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"
]
}
Loading

0 comments on commit d1c72cc

Please sign in to comment.