Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
asukaminato0721 committed Nov 19, 2023
0 parents commit d5bd26b
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 0 deletions.
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
9 changes: 9 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.vscode/**
.vscode-test/**
test/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/jsconfig.json
**/*.map
**/.eslintrc.json
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2004 Asuka Minato <not important>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# MmaFmt

Format mma code.

Very slow, but works.

Need to have <https://github.com/WolframResearch/codeformatter> installed first.
47 changes: 47 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const vscode = require("vscode");
const { spawnSync } = require("child_process");

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
context.subscriptions.push(
vscode.languages.registerDocumentFormattingEditProvider("wolfram", {
provideDocumentFormattingEdits(document) {
const cellContent = [];
for (let i = 0; i < document.lineCount; i++) {
cellContent.push(document.lineAt(i).text);
}
const cellContentString = cellContent.join("\n");

return [
vscode.TextEdit.replace(
new vscode.Range(
new vscode.Position(0, 0),
new vscode.Position(
document.lineCount - 1,
document.lineAt(document.lineCount - 1).text.length
)
),

spawnSync(`wolframscript`, ["-f", "./fmt.wls", cellContentString], {
timeout: 30000,
stdio: "pipe",
}).stdout.toString()
),
];
},
})
);
}
// This method is called when your extension is deactivated
function deactivate() {}

module.exports = {
activate,
deactivate,
};
6 changes: 6 additions & 0 deletions fmt.wls
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Needs["CodeFormatter`"];

$ScriptCommandLine //
Last //
CodeFormatter`CodeFormat //
Print
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": "ES2020",
"checkJs": true, /* Typecheck .js files. */
"lib": [
"ES2020"
]
},
"exclude": [
"node_modules"
]
}
39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "mmafmt",
"displayName": "mmafmt",
"description": "fmt code",
"version": "0.0.1",
"repository": {
"url": "whatever"
},
"activationEvents": [
"onLanguage:wolfram"
],
"engines": {
"vscode": "^1.75.0"
},
"categories": [
"Programming Languages",
"Keymaps"
],
"main": "./extension.js",
"contributes": {
"configuration": {
"title": "MmaFmt"
},
"languages": [
{
"id": "wolfram",
"aliases": [
"Wolfram Language"
],
"extensions": [
".wls",
".wlnb",
".wl",
".nb"
]
}
]
}
}

0 comments on commit d5bd26b

Please sign in to comment.