Update example: allow peek definition

pull/2112/head
KapitanOczywisty 2020-09-08 20:59:15 +02:00
parent 2a996151d7
commit db327beb63
2 changed files with 28 additions and 18 deletions

View File

@ -53,28 +53,33 @@ monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
});
// extra libraries
monaco.languages.typescript.javascriptDefaults.addExtraLib([
var libSource = [
'declare class Facts {',
' /**',
' * Returns the next fact',
' */',
' static next():string',
'}',
].join('\n'), 'ts:filename/facts.d.ts');
].join('\n');
var libUri = 'ts:filename/facts.d.ts';
monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, libUri);
// When resolving definitions and references, editor will try to use created models.
// Following line allows "peek definition/references" commands to work with library.
monaco.editor.createModel(libSource, 'typescript', monaco.Uri.parse(libUri));
var jsCode = [
'"use strict";',
'',
"class Chuck {",
" greet() {",
" return Facts.next();",
" }",
"}"
'class Chuck {',
' greet() {',
' return Facts.next();',
' }',
'}'
].join('\n');
monaco.editor.create(document.getElementById("container"), {
monaco.editor.create(document.getElementById('container'), {
value: jsCode,
language: "javascript"
language: 'javascript'
});

View File

@ -16,26 +16,31 @@ monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
});
// extra libraries
monaco.languages.typescript.javascriptDefaults.addExtraLib([
var libSource = [
'declare class Facts {',
' /**',
' * Returns the next fact',
' */',
' static next():string',
'}',
].join('\n'), 'ts:filename/facts.d.ts');
].join('\n');
var libUri = 'ts:filename/facts.d.ts';
monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, libUri);
// When resolving definitions and references, editor will try to use created models.
// Following line allows "peek definition/references" commands to work with library.
monaco.editor.createModel(libSource, 'typescript', monaco.Uri.parse(libUri));
var jsCode = [
'"use strict";',
'',
"class Chuck {",
" greet() {",
" return Facts.next();",
" }",
"}"
'class Chuck {',
' greet() {',
' return Facts.next();',
' }',
'}'
].join('\n');
monaco.editor.create(document.getElementById("container"), {
monaco.editor.create(document.getElementById('container'), {
value: jsCode,
language: "javascript"
language: 'javascript'
});