|
|
|
@ -1,3 +1,11 @@
|
|
|
|
|
<!--
|
|
|
|
|
To test this file, you need to use a local server. The recommendation is that you run:
|
|
|
|
|
|
|
|
|
|
npx serve .
|
|
|
|
|
|
|
|
|
|
Then open http://localhost:5000/test/custom-worker
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
|
|
|
@ -10,9 +18,8 @@
|
|
|
|
|
<h2>Monaco Editor TypeScript test page</h2>
|
|
|
|
|
<button id="resetBtn">Reset Sample</button>
|
|
|
|
|
<div id="container" style="width:800px;height:600px;border:1px solid grey"></div>
|
|
|
|
|
<h3>Compiler settings</h3>
|
|
|
|
|
<textarea style="font-family: monospace;" id="compilerOpts" cols="60" rows="30"></textarea><br/>
|
|
|
|
|
<button id="updateCompilerSettingsBtn">Update compiler settings</button>
|
|
|
|
|
<h3>Custom webworker</h3>
|
|
|
|
|
<button id="logDTS">Log DTS</button>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
var paths = {
|
|
|
|
@ -174,6 +181,8 @@
|
|
|
|
|
'vs/language/typescript/monaco.contribution'
|
|
|
|
|
], () => {
|
|
|
|
|
|
|
|
|
|
monaco.languages.typescript.typescriptDefaults.setWorkerOptions({ customWorkerPath: "http://localhost:5000/test/custom-worker.js" })
|
|
|
|
|
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({ target: 99, jsx: 1, allowNonTsExtensions: true, declaration: true })
|
|
|
|
|
|
|
|
|
|
var editor = monaco.editor.create(document.getElementById('container'), {
|
|
|
|
|
value: localStorage.getItem("code") || getDefaultCode(),
|
|
|
|
@ -181,7 +190,6 @@
|
|
|
|
|
lightbulb: { enabled: true }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log("OK")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
editor.onDidChangeModelContent(() => {
|
|
|
|
@ -191,18 +199,15 @@
|
|
|
|
|
|
|
|
|
|
document.getElementById('resetBtn').onclick = () => {
|
|
|
|
|
editor.setValue(getDefaultCode());
|
|
|
|
|
monaco.languages.typescript.typescriptDefaults.setWorkerOptions({ customWorkerPath: "http://localhost:5000/test/custom-worker.js" })
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const optsString = localStorage.getItem("compiler-opts") || JSON.stringify(getDefaultComplierOpts(), null, 4)
|
|
|
|
|
document.getElementById("compilerOpts").textContent = optsString
|
|
|
|
|
monaco.languages.typescript.typescriptDefaults.setCompilerOptions(JSON.parse(optsString))
|
|
|
|
|
document.getElementById('logDTS').onclick = async () => {
|
|
|
|
|
const model = editor.getModel()
|
|
|
|
|
|
|
|
|
|
document.getElementById('updateCompilerSettingsBtn').onclick = () => {
|
|
|
|
|
const newOpts = document.getElementById('compilerOpts').value
|
|
|
|
|
monaco.languages.typescript.typescriptDefaults.setCompilerOptions(JSON.parse(newOpts))
|
|
|
|
|
localStorage.setItem("compiler-opts", newOpts)
|
|
|
|
|
const worker = await monaco.languages.typescript.getTypeScriptWorker()
|
|
|
|
|
const thisWorker = await worker(model.uri)
|
|
|
|
|
const dts = await thisWorker.getDTSEmitForFile(model.uri.toString())
|
|
|
|
|
console.log(dts)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|