Переглянути джерело

Merge branch 'main' into fix-contributing-instructions

Henning Dieterichs 3 роки тому
батько
коміт
475c42daa2

+ 0 - 35
src/basic-languages/mysql/mysql.test.ts

@@ -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',

+ 4 - 0
webpack-plugin/README.md

@@ -78,8 +78,12 @@ Options can be passed in to `MonacoWebpackPlugin`. They can be used to generate
   | handlebars | html         |
   | 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 '!'.
 
+  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)).
   - default value: `false`.
 

+ 18 - 10
website/index/samples/sample.dart.txt

@@ -1,21 +1,24 @@
-import 'dart:async';
 import 'dart:math' show Random;
-main() async {
+
+void main() async {
   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');
   }
 }
+
 /// Generates a stream of increasingly accurate estimates of π.
-Stream<double> computePi({int batch: 100000}) async* {
-  var total = 0;
+Stream<double> computePi({int batch = 100000}) async* {
+  var total = 0; // Inferred to be of type int
   var count = 0;
   while (true) {
-    var points = generateRandom().take(batch);
-    var inside = points.where((p) => p.isInsideUnitCircle);
+    final points = generateRandom().take(batch);
+    final inside = points.where((p) => p.isInsideUnitCircle);
+
     total += batch;
     count += inside.length;
-    var ratio = count / total;
+    final ratio = count / total;
+
     // Area of a circle is A = π⋅r², therefore π = A/r².
     // So, when given random points with x ∈ <0,1>,
     // 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;
   }
 }
-Iterable<Point> generateRandom([int seed]) sync* {
+
+Iterable<Point> generateRandom([int? seed]) sync* {
   final random = Random(seed);
   while (true) {
     yield Point(random.nextDouble(), random.nextDouble());
   }
 }
+
 class Point {
-  final double x, y;
+  final double x;
+  final double y;
+
   const Point(this.x, this.y);
+
   bool get isInsideUnitCircle => x * x + y * y <= 1;
 }

+ 6 - 0
website/playground/new-samples/all.js

@@ -156,6 +156,12 @@
 			id: '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',
 			name: 'Semantic tokens provider example',

+ 0 - 0
website/playground/new-samples/extending-language-services/model-markers-example/sample.css


+ 1 - 0
website/playground/new-samples/extending-language-services/model-markers-example/sample.html

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

+ 48 - 0
website/playground/new-samples/extending-language-services/model-markers-example/sample.js

@@ -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);
+});