-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* should work full offline again * prettier integration with format
- Loading branch information
Showing
4 changed files
with
6,023 additions
and
12,542 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
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,57 @@ | ||
import { loader } from "@monaco-editor/react"; | ||
|
||
import * as monaco from "monaco-editor"; | ||
import editorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker"; | ||
import jsonWorker from "monaco-editor/esm/vs/language/json/json.worker?worker"; | ||
import cssWorker from "monaco-editor/esm/vs/language/css/css.worker?worker"; | ||
import htmlWorker from "monaco-editor/esm/vs/language/html/html.worker?worker"; | ||
import tsWorker from "monaco-editor/esm/vs/language/typescript/ts.worker?worker"; | ||
|
||
import prettier from "prettier/esm/standalone"; | ||
import prettierPluginBabel from "prettier/esm/parser-babel"; | ||
import prettierEspree from "prettier/esm/parser-espree"; | ||
|
||
self.MonacoEnvironment = { | ||
getWorker(_, label) { | ||
if (label === "json") { | ||
return new jsonWorker(); | ||
} | ||
if (label === "css" || label === "scss" || label === "less") { | ||
return new cssWorker(); | ||
} | ||
if (label === "html" || label === "handlebars" || label === "razor") { | ||
return new htmlWorker(); | ||
} | ||
if (label === "typescript" || label === "javascript") { | ||
return new tsWorker(); | ||
} | ||
return new editorWorker(); | ||
}, | ||
}; | ||
|
||
const formatWithPrettier = (value) => { | ||
console.log("yeah", prettier); | ||
try { | ||
return prettier.format(value, { | ||
parser: "babel", | ||
plugins: [prettierPluginBabel, prettierEspree], | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
return value; | ||
} | ||
}; | ||
|
||
monaco.languages.registerDocumentFormattingEditProvider("javascript", { | ||
provideDocumentFormattingEdits: (model) => { | ||
console.log("mmm"); | ||
return [ | ||
{ | ||
range: model.getFullModelRange(), | ||
text: formatWithPrettier(model.getValue()), | ||
}, | ||
]; | ||
}, | ||
}); | ||
|
||
loader.config({ monaco }); |
Oops, something went wrong.