Merge branch 'main' into fix-contributing-instructions

This commit is contained in:
Henning Dieterichs 2022-07-21 13:52:20 +02:00 committed by GitHub
commit 475c42daa2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 77 additions and 45 deletions

View file

@ -385,41 +385,6 @@ testTokenization('mysql', [
} }
], ],
[
{
line: 'declare `abc 321`;',
tokens: [
{ startIndex: 0, type: 'keyword.sql' },
{ startIndex: 7, type: 'white.sql' },
{ startIndex: 8, type: 'identifier.quote.sql' },
{ startIndex: 9, type: 'identifier.sql' },
{ startIndex: 16, type: 'identifier.quote.sql' },
{ startIndex: 17, type: 'delimiter.sql' }
]
}
],
[
{
line: '`abc`` 321 `` xyz`',
tokens: [
{ startIndex: 0, type: 'identifier.quote.sql' },
{ startIndex: 1, type: 'identifier.sql' },
{ startIndex: 17, type: 'identifier.quote.sql' }
]
}
],
[
{
line: '`abc',
tokens: [
{ startIndex: 0, type: 'identifier.quote.sql' },
{ startIndex: 1, type: 'identifier.sql' }
]
}
],
[ [
{ {
line: 'int', line: 'int',

View file

@ -78,8 +78,12 @@ Options can be passed in to `MonacoWebpackPlugin`. They can be used to generate
| handlebars | html | | handlebars | html |
| scss, less | css | | scss, less | css |
To view a list of all available languages, you can run `import metadata from 'monaco-editor/esm/metadata'; console.log(metadata.languages);`.
- `features` (`string[]`) - include only a subset of the editor features. By default, all features shipped with the `monaco-editor` will be included. Instead of enumerating included features, it is also possible to exclude certain default features prefixing them with an exclamation mark '!'. - `features` (`string[]`) - include only a subset of the editor features. By default, all features shipped with the `monaco-editor` will be included. Instead of enumerating included features, it is also possible to exclude certain default features prefixing them with an exclamation mark '!'.
To view a list of all available features, you can run `import metadata from 'monaco-editor/esm/metadata'; console.log(metadata.features);`.
- `globalAPI` (`boolean`) - specify whether the editor API should be exposed through a global `monaco` object or not. This option is applicable to `0.22.0` and newer version of `monaco-editor`. Since `0.22.0`, the ESM version of the monaco editor does no longer define a global `monaco` object unless `global.MonacoEnvironment = { globalAPI: true }` is set ([change log](https://github.com/microsoft/monaco-editor/blob/main/CHANGELOG.md#0220-29012021)). - `globalAPI` (`boolean`) - specify whether the editor API should be exposed through a global `monaco` object or not. This option is applicable to `0.22.0` and newer version of `monaco-editor`. Since `0.22.0`, the ESM version of the monaco editor does no longer define a global `monaco` object unless `global.MonacoEnvironment = { globalAPI: true }` is set ([change log](https://github.com/microsoft/monaco-editor/blob/main/CHANGELOG.md#0220-29012021)).
- default value: `false`. - default value: `false`.

View file

@ -1,21 +1,24 @@
import 'dart:async';
import 'dart:math' show Random; import 'dart:math' show Random;
main() async {
void main() async {
print('Compute π using the Monte Carlo method.'); print('Compute π using the Monte Carlo method.');
await for (var estimate in computePi().take(100)) { await for (final estimate in computePi().take(100)) {
print('π ≅ $estimate'); print('π ≅ $estimate');
} }
} }
/// Generates a stream of increasingly accurate estimates of π. /// Generates a stream of increasingly accurate estimates of π.
Stream<double> computePi({int batch: 100000}) async* { Stream<double> computePi({int batch = 100000}) async* {
var total = 0; var total = 0; // Inferred to be of type int
var count = 0; var count = 0;
while (true) { while (true) {
var points = generateRandom().take(batch); final points = generateRandom().take(batch);
var inside = points.where((p) => p.isInsideUnitCircle); final inside = points.where((p) => p.isInsideUnitCircle);
total += batch; total += batch;
count += inside.length; count += inside.length;
var ratio = count / total; final ratio = count / total;
// Area of a circle is A = π⋅r², therefore π = A/r². // Area of a circle is A = π⋅r², therefore π = A/r².
// So, when given random points with x ∈ <0,1>, // So, when given random points with x ∈ <0,1>,
// y ∈ <0,1>, the ratio of those inside a unit circle // y ∈ <0,1>, the ratio of those inside a unit circle
@ -24,14 +27,19 @@ Stream<double> computePi({int batch: 100000}) async* {
yield ratio * 4; yield ratio * 4;
} }
} }
Iterable<Point> generateRandom([int seed]) sync* {
Iterable<Point> generateRandom([int? seed]) sync* {
final random = Random(seed); final random = Random(seed);
while (true) { while (true) {
yield Point(random.nextDouble(), random.nextDouble()); yield Point(random.nextDouble(), random.nextDouble());
} }
} }
class Point { class Point {
final double x, y; final double x;
final double y;
const Point(this.x, this.y); const Point(this.x, this.y);
bool get isInsideUnitCircle => x * x + y * y <= 1; bool get isInsideUnitCircle => x * x + y * y <= 1;
} }

View file

@ -156,6 +156,12 @@
id: 'extending-language-services-hover-provider-example', id: 'extending-language-services-hover-provider-example',
path: 'extending-language-services/hover-provider-example' path: 'extending-language-services/hover-provider-example'
}, },
{
chapter: 'Extending Language Services',
name: 'Model markers example',
id: 'extending-language-services-model-markers-example',
path: 'extending-language-services/model-markers-example'
},
{ {
chapter: 'Extending Language Services', chapter: 'Extending Language Services',
name: 'Semantic tokens provider example', name: 'Semantic tokens provider example',

View file

@ -0,0 +1 @@
<div id="container" style="height: 100%"></div>

View file

@ -0,0 +1,48 @@
function validate(model) {
const markers = [];
// lines start at 1
for (let i = 1; i < model.getLineCount() + 1; i++) {
const range = {
startLineNumber: i,
startColumn: 1,
endLineNumber: i,
endColumn: model.getLineLength(i) + 1
};
const content = model.getValueInRange(range).trim();
const number = Number(content);
if (Number.isNaN(number)) {
markers.push({
message: 'not a number',
severity: monaco.MarkerSeverity.Error,
startLineNumber: range.startLineNumber,
startColumn: range.startColumn,
endLineNumber: range.endLineNumber,
endColumn: range.endColumn
});
} else if (!Number.isInteger(number)) {
markers.push({
message: 'not an integer',
severity: monaco.MarkerSeverity.Warning,
startLineNumber: range.startLineNumber,
startColumn: range.startColumn,
endLineNumber: range.endLineNumber,
endColumn: range.endColumn
});
}
}
monaco.editor.setModelMarkers(model, 'owner', markers);
}
const value = `12345
abcd
234.56
12345
abcd
234.56`;
const uri = monaco.Uri.parse('inmemory://test');
const model = monaco.editor.createModel(value, 'demoLanguage', uri);
editor = monaco.editor.create(document.getElementById('container'), { model });
validate(model);
model.onDidChangeContent(() => {
validate(model);
});