Skip to content

Commit

Permalink
load types in the monaco editor
Browse files Browse the repository at this point in the history
now it knows the type of CouchDB

had to change the uri of the model so it looks for files in the virtual
file:/// path
  • Loading branch information
gdamjan committed Dec 30, 2023
1 parent 4f5b457 commit dc1705e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion playground/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ async function init() {
allowNonTsExtensions: true,
});

// FIXME: auto-detect all types
for (const lib of ["index.d.ts", "couch-api.d.ts", "types.d.ts", "post-query.d.ts"]) {
const req = await fetch(`./types/${lib}`);
const content = await req.text();
monaco.languages.typescript.typescriptDefaults.addExtraLib(content, `file:///node_modules/@types/irclog-api/${lib}`);
}

let exampleCode = localStorage.getItem("example.ts");
if (!exampleCode) {
const req = await fetch('./example.ts');
exampleCode = await req.text();
}
const uri = monaco.Uri.parse('http://localhost:3000/example.ts');
const uri = monaco.Uri.parse('file:///example.ts');
const model = monaco.editor.createModel(exampleCode, 'typescript', uri);

const editor = monaco.editor.create(document.getElementById('monaco-editor'), {
Expand Down

0 comments on commit dc1705e

Please sign in to comment.