From db327beb63133f6867552d6a87b61c977e079450 Mon Sep 17 00:00:00 2001 From: KapitanOczywisty <44417092+KapitanOczywisty@users.noreply.github.com> Date: Tue, 8 Sep 2020 20:59:15 +0200 Subject: [PATCH] Update example: allow peek definition --- ...ervices-configure-javascript-defaults.html | 23 +++++++++++-------- .../configure-javascript-defaults/sample.js | 23 +++++++++++-------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/test/playground.generated/extending-language-services-configure-javascript-defaults.html b/test/playground.generated/extending-language-services-configure-javascript-defaults.html index 6fdcf396..19a6adcf 100644 --- a/test/playground.generated/extending-language-services-configure-javascript-defaults.html +++ b/test/playground.generated/extending-language-services-configure-javascript-defaults.html @@ -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' }); diff --git a/website/playground/new-samples/extending-language-services/configure-javascript-defaults/sample.js b/website/playground/new-samples/extending-language-services/configure-javascript-defaults/sample.js index f8c8f263..3b07f6ad 100644 --- a/website/playground/new-samples/extending-language-services/configure-javascript-defaults/sample.js +++ b/website/playground/new-samples/extending-language-services/configure-javascript-defaults/sample.js @@ -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' });