Merge pull request #2112 from KapitanOczywisty/javascriptDefaults

Update example: allow peek definition
This commit is contained in:
Alexandru Dima 2020-09-17 22:24:02 +02:00 committed by GitHub
commit 45279f68e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 18 deletions

View file

@ -816,6 +816,8 @@ function createSimpleServer(rootDir, port) {
}); });
} }
gulp.task('generate-test-samples', taskSeries(generateTestSamplesTask));
gulp.task('simpleserver', taskSeries(generateTestSamplesTask, function() { gulp.task('simpleserver', taskSeries(generateTestSamplesTask, function() {
const SERVER_ROOT = path.normalize(path.join(__dirname, '../')); const SERVER_ROOT = path.normalize(path.join(__dirname, '../'));
createSimpleServer(SERVER_ROOT, 8080); createSimpleServer(SERVER_ROOT, 8080);

View file

@ -53,28 +53,33 @@ monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
}); });
// extra libraries // extra libraries
monaco.languages.typescript.javascriptDefaults.addExtraLib([ var libSource = [
'declare class Facts {', 'declare class Facts {',
' /**', ' /**',
' * Returns the next fact', ' * Returns the next fact',
' */', ' */',
' static next():string', ' 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, the editor will try to use created models.
// Creating a model for the library allows "peek definition/references" commands to work with the library.
monaco.editor.createModel(libSource, 'typescript', monaco.Uri.parse(libUri));
var jsCode = [ var jsCode = [
'"use strict";', '"use strict";',
'', '',
"class Chuck {", 'class Chuck {',
" greet() {", ' greet() {',
" return Facts.next();", ' return Facts.next();',
" }", ' }',
"}" '}'
].join('\n'); ].join('\n');
monaco.editor.create(document.getElementById("container"), { monaco.editor.create(document.getElementById('container'), {
value: jsCode, value: jsCode,
language: "javascript" language: 'javascript'
}); });

View file

@ -16,26 +16,31 @@ monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
}); });
// extra libraries // extra libraries
monaco.languages.typescript.javascriptDefaults.addExtraLib([ var libSource = [
'declare class Facts {', 'declare class Facts {',
' /**', ' /**',
' * Returns the next fact', ' * Returns the next fact',
' */', ' */',
' static next():string', ' 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, the editor will try to use created models.
// Creating a model for the library allows "peek definition/references" commands to work with the library.
monaco.editor.createModel(libSource, 'typescript', monaco.Uri.parse(libUri));
var jsCode = [ var jsCode = [
'"use strict";', '"use strict";',
'', '',
"class Chuck {", 'class Chuck {',
" greet() {", ' greet() {',
" return Facts.next();", ' return Facts.next();',
" }", ' }',
"}" '}'
].join('\n'); ].join('\n');
monaco.editor.create(document.getElementById("container"), { monaco.editor.create(document.getElementById('container'), {
value: jsCode, value: jsCode,
language: "javascript" language: 'javascript'
}); });