فهرست منبع

Adopt core & plugins for 0.5.0

Alex Dima 9 سال پیش
والد
کامیت
18f953b747

+ 16 - 0
CHANGELOG.md

@@ -0,0 +1,16 @@
+# Monaco Editor Change log
+
+## [0.5.0]
+
+### Breaking changes
+- `monaco.editor.createWebWorker` now loads the AMD module and calls `create` and passes in as first argument a context of type `monaco.worker.IWorkerContext` and as second argument the `initData`. This breaking change was needed to allow handling the case of misconfigured web workers (running on a file protocol or the cross-domain case)
+- the `CodeActionProvider.provideCodeActions` now gets passed in a `CodeActionContext` that contains the markers at the relevant range.
+- the `hoverMessage` of a decoration is now a `MarkedString | MarkedString[]`
+- the `contents` of a `Hover` returned by a `HoverProvider` is now a `MarkedString | MarkedString[]`
+- removed deprecated `IEditor.onDidChangeModelRawContent`, `IModel.onDidChangeRawContent`
+
+### Notable fixes
+- Broken configurations (loading from `file://` or misconfigured cross-domain loading) now load the web worker code in the UI thread. This caused a breaking change in the behaviour of `monaco.editor.createWebWorker`
+- The right-pointing mouse pointer is oversized in high DPI - [issue](https://github.com/Microsoft/monaco-editor/issues/5)
+- The editor functions now correctly when hosted inside a `position:fixed` element.
+- Cross origin configuration is now picked up (as advertised in documentation from MonacoEnvironment)

+ 8 - 7
README.md

@@ -9,9 +9,10 @@ The Monaco Editor is the code editor that powers [VS Code](https://github.com/Mi
 Please mention the version of the editor when creating issues and the browser you're having trouble in.
 
 This repository contains only the scripts to glue things together, please create issues against the actual repositories where the source code lives:
- * monaco-editor-core: [Issues](https://github.com/Microsoft/vscode) -- [npm module](https://www.npmjs.com/package/monaco-editor-core) (Issues with the editor itself)
- * monaco-typescript: [Issues](https://github.com/Microsoft/monaco-typescript) -- [npm module](https://www.npmjs.com/package/monaco-typescript) (Issues with JavaScript or TypeScript language support)
- * monaco-languages: [Issues](https://github.com/Microsoft/monaco-languages) -- [npm module](https://www.npmjs.com/package/monaco-languages) (Issues with bat, coffee script, cpp, csharp, fsharp, go, ini, jade, lua, objective-c, powershell, python, r, ruby, sql, swift, vb or xml)
+ * [monaco-editor-core](https://github.com/Microsoft/vscode) -- (the editor itself)
+ * [monaco-typescript](https://github.com/Microsoft/monaco-typescript) -- (JavaScript or TypeScript language support)
+ * [monaco-css](https://github.com/Microsoft/monaco-css) -- (CSS, LESS or SCSS advanced language support)
+ * [monaco-languages](https://github.com/Microsoft/monaco-languages) -- (bat, coffee script, cpp, csharp, fsharp, go, ini, jade, lua, objective-c, powershell, python, r, ruby, sql, swift, vb or xml colorizers)
 
 ## Known issues
 In IE, the editor must be completely surrounded in the body element, otherwise the hit testing we do for mouse operations does not work. You can inspect this using F12 and clicking on the body element and confirm that visually it surrounds the editor.
@@ -152,16 +153,14 @@ Create a Monarch tokenizer [here](https://microsoft.github.io/monaco-editor/mona
 * clone https://github.com/Microsoft/vscode in `$/src/vscode/` (next to this repo)
 * run `$/src/vscode> gulp watch`
 * run `$/src/monaco-editor> npm run simpleserver`
-* edit `$/src/monaco-editor/test/index.html` and set `var RUN_EDITOR_FROM_SOURCE = true;`
-* open http://localhost:8080/monaco-editor/test/
+* open http://localhost:8080/monaco-editor/test/?editor=dev
 
 ### Running a plugin (e.g. monaco-typescript) from source
 
 * clone https://github.com/Microsoft/monaco-typescript in `$/src/monaco-typescript` (next to this repo)
 * run `$/src/monaco-typescript> npm run watch`
 * run `$/src/monaco-editor> npm run simpleserver`
-* edit `$/src/monaco-editor/test/index.html` and set `RUN_PLUGINS_FROM_SOURCE['monaco-typescript'] = true;`
-* open http://localhost:8080/monaco-editor/test/
+* open http://localhost:8080/monaco-editor/test/?editor=dev&monaco-typescript=dev
 
 ---
 
@@ -177,11 +176,13 @@ Create a Monarch tokenizer [here](https://microsoft.github.io/monaco-editor/mona
 #### Adopt new `monaco-editor-core` in plugins (if necessary)
 * https://github.com/Microsoft/monaco-typescript
 * https://github.com/Microsoft/monaco-languages
+* https://github.com/Microsoft/monaco-css
 
 #### Adopt new `monaco-editor-core`
 * edit `$/src/monaco-editor/package.json` and update the version for (as necessary):
  * `monaco-editor-core`
  * `monaco-typescript`
+ * `monaco-css`
  * `monaco-languages`
 * update the version in `$/src/monaco-editor/package.json`
  * I try to keep it similar to `monaco-editor-core`, maybe just vary the patch version.

+ 45 - 3
gulpfile.js

@@ -37,10 +37,20 @@ gulp.task('release', ['clean-release'], function() {
 		// other files
 		gulp.src([
 			'node_modules/monaco-editor-core/LICENSE',
+			'node_modules/monaco-editor-core/CHANGELOG.md',
 			'node_modules/monaco-editor-core/monaco.d.ts',
 			'node_modules/monaco-editor-core/ThirdPartyNotices.txt',
 			'README.md'
-		]).pipe(addPluginDTS()).pipe(gulp.dest('release'))
+		])
+		.pipe(es.through(function(data) {
+			if (/CHANGELOG\.md$/.test(data.path)) {
+				fs.writeFileSync('CHANGELOG.md', data.contents);
+			}
+			this.emit('data', data);
+		}))
+		.pipe(addPluginDTS())
+		.pipe(addPluginThirdPartyNotices())
+		.pipe(gulp.dest('release'))
 	)
 });
 
@@ -66,7 +76,8 @@ function pluginStream(plugin, destinationPath) {
 	return (
 		gulp.src([
 			plugin.path + '/**/*',
-			'!' + contribPath
+			'!' + contribPath,
+			'!' + plugin.path + '/**/monaco.d.ts'
 		])
 		.pipe(gulp.dest(destinationPath + plugin.modulePrefix))
 	);
@@ -156,6 +167,37 @@ function addPluginDTS() {
 	});
 }
 
+/**
+ * Edit ThirdPartyNotices.txt:
+ * - append ThirdPartyNotices.txt from plugins
+ */
+function addPluginThirdPartyNotices() {
+	return es.through(function(data) {
+		if (!/ThirdPartyNotices\.txt$/.test(data.path)) {
+			this.emit('data', data);
+			return;
+		}
+		var contents = data.contents.toString();
+
+		var extraContent = [];
+		metadata.METADATA.PLUGINS.forEach(function(plugin) {
+			var thirdPartyNoticePath = path.join(path.dirname(plugin.path), 'ThirdPartyNotices.txt');
+			try {
+				var thirdPartyNoticeContent = fs.readFileSync(thirdPartyNoticePath).toString();
+				thirdPartyNoticeContent = thirdPartyNoticeContent.split('\n').slice(8).join('\n');
+				extraContent.push(thirdPartyNoticeContent);
+			} catch (err) {
+				return;
+			}
+		});
+
+		contents += '\n' + extraContent.join('\n');
+		data.contents = new Buffer(contents);
+
+		this.emit('data', data);
+	});
+}
+
 
 // --- website
 
@@ -276,7 +318,7 @@ gulp.task('playground-samples', ['clean-playground-samples'], function() {
 				sampleId: sampleId
 			});
 
-var content =
+			var content =
 `// This is a generated file. Please do not edit directly.
 var SAMPLES = this.SAMPLES || [];
 SAMPLES.push(${JSON.stringify(sampleOut)});

+ 4 - 4
package.json

@@ -18,10 +18,10 @@
     "event-stream": "^3.3.2",
     "gulp": "^3.9.1",
     "http-server": "^0.9.0",
-    "monaco-editor-core": "0.4.2",
-    "monaco-languages": "0.2.1",
-    "monaco-typescript": "0.2.1",
-    "monaco-css": "1.0.0",
+    "monaco-editor-core": "0.5.1",
+    "monaco-languages": "0.3.0",
+    "monaco-typescript": "0.5.0",
+    "monaco-css": "1.1.0",
     "rimraf": "^2.5.2"
   }
 }

+ 1 - 1
test/cross-origin-broken.html

@@ -19,7 +19,7 @@
 	loadEditor(function() {
 		monaco.editor.create(document.getElementById('container'), {
 			value: document.documentElement.innerHTML,
-			language: 'xml'
+			language: 'css'
 		});
 	}, 'http://localhost:8088');
 </script>

+ 2 - 2
test/cross-origin-good.html

@@ -15,7 +15,7 @@
 <script src="../metadata.js"></script>
 <script src="dev-setup.js"></script>
 <script>
-	window.GlobalEnvironment = {
+	window.MonacoEnvironment = {
 		getWorkerUrl: function() {
 			return loadDevEditor() ? 'cross-origin-worker-proxy-dev.js' : 'cross-origin-worker-proxy.js';
 		}
@@ -26,7 +26,7 @@
 	loadEditor(function() {
 		monaco.editor.create(document.getElementById('container'), {
 			value: document.documentElement.innerHTML,
-			language: 'xml'
+			language: 'css'
 		});
 	}, 'http://localhost:8088');
 </script>

+ 1 - 1
test/cross-origin-worker-proxy-dev.js

@@ -1,4 +1,4 @@
-self.GlobalEnvironment = {
+self.MonacoEnvironment = {
 	baseUrl: 'http://localhost:8088/vscode/out/'
 };
 importScripts('http://localhost:8088/vscode/out/vs/base/worker/workerMain.js');

+ 1 - 1
test/cross-origin-worker-proxy.js

@@ -1,4 +1,4 @@
-self.GlobalEnvironment = {
+self.MonacoEnvironment = {
 	baseUrl: 'http://localhost:8088/monaco-editor/node_modules/monaco-editor-core/min/'
 };
 importScripts('http://localhost:8088/monaco-editor/node_modules/monaco-editor-core/min/vs/base/worker/workerMain.js');

+ 1 - 0
website/.gitignore

@@ -0,0 +1 @@
+node_modules/monaco-editor/dev

+ 82 - 136
website/playground/monaco.d.ts.txt

@@ -347,37 +347,24 @@ declare module monaco {
         static WinCtrl: number;
         static chord(firstPart: number, secondPart: number): number;
     }
-    export interface IHTMLContentElementCode {
+    /**
+     * MarkedString can be used to render human readable text. It is either a markdown string
+     * or a code-block that provides a language and a code snippet. Note that
+     * markdown strings will be sanitized - that means html will be escaped.
+     */
+    export type MarkedString = string | {
         language: string;
         value: string;
-    }
-
-    export interface IHTMLContentElement {
-        /**
-         * supports **bold**, __italics__, and [[actions]]
-         */
-        formattedText?: string;
-        text?: string;
-        className?: string;
-        style?: string;
-        customStyle?: any;
-        tagName?: string;
-        children?: IHTMLContentElement[];
-        isText?: boolean;
-        role?: string;
-        markdown?: string;
-        code?: IHTMLContentElementCode;
-    }
+    };
 
     export interface IKeyboardEvent {
-        browserEvent: Event;
+        browserEvent: KeyboardEvent;
         target: HTMLElement;
         ctrlKey: boolean;
         shiftKey: boolean;
         altKey: boolean;
         metaKey: boolean;
         keyCode: KeyCode;
-        clone(): IKeyboardEvent;
         asKeybinding(): number;
         equals(keybinding: number): boolean;
         preventDefault(): void;
@@ -1499,13 +1486,9 @@ declare module monaco.editor {
          */
         className?: string;
         /**
-         * Message to be rendered when hovering over the decoration.
-         */
-        hoverMessage?: string;
-        /**
-         * Array of IHTMLContentElements to render as the decoration message.
+         * Array of MarkedString to render as the decoration message.
          */
-        htmlMessage?: IHTMLContentElement[];
+        hoverMessage?: MarkedString | MarkedString[];
         /**
          * Should the decoration expand to encompass a whole line.
          */
@@ -2115,11 +2098,6 @@ declare module monaco.editor {
      * A model.
      */
     export interface IModel extends IReadOnlyModel, IEditableTextModel, ITextModelWithMarkers, ITokenizedModel, ITextModelWithTrackedRanges, ITextModelWithDecorations, IEditorModel {
-        /**
-         * @deprecated Please use `onDidChangeContent` instead.
-         * An event emitted when the contents of the model have changed.
-         */
-        onDidChangeRawContent(listener: (e: IModelContentChangedEvent) => void): IDisposable;
         /**
          * An event emitted when the contents of the model have changed.
          */
@@ -2241,32 +2219,6 @@ declare module monaco.editor {
         isRedoing: boolean;
     }
 
-    /**
-     * An event describing a change in the text of a model.
-     */
-    export interface IModelContentChangedEvent {
-        /**
-         * The event type. It can be used to detect the actual event type:
-         * 		EditorCommon.EventType.ModelContentChangedFlush => IModelContentChangedFlushEvent
-         * 		EditorCommon.EventType.ModelContentChangedLinesDeleted => IModelContentChangedLineChangedEvent
-         * 		EditorCommon.EventType.ModelContentChangedLinesInserted => IModelContentChangedLinesDeletedEvent
-         * 		EditorCommon.EventType.ModelContentChangedLineChanged => IModelContentChangedLinesInsertedEvent
-         */
-        changeType: string;
-        /**
-         * The new version id the model has transitioned to.
-         */
-        versionId: number;
-        /**
-         * Flag that indicates that this event was generated while undoing.
-         */
-        isUndoing: boolean;
-        /**
-         * Flag that indicates that this event was generated while redoing.
-         */
-        isRedoing: boolean;
-    }
-
     /**
      * The raw text backing a model.
      */
@@ -2293,62 +2245,6 @@ declare module monaco.editor {
         options: ITextModelResolvedOptions;
     }
 
-    /**
-     * An event describing that a model has been reset to a new value.
-     */
-    export interface IModelContentChangedFlushEvent extends IModelContentChangedEvent {
-        /**
-         * The new text content of the model.
-         */
-        detail: IRawText;
-    }
-
-    /**
-     * An event describing that a line has changed in a model.
-     */
-    export interface IModelContentChangedLineChangedEvent extends IModelContentChangedEvent {
-        /**
-         * The line that has changed.
-         */
-        lineNumber: number;
-        /**
-         * The new value of the line.
-         */
-        detail: string;
-    }
-
-    /**
-     * An event describing that line(s) have been deleted in a model.
-     */
-    export interface IModelContentChangedLinesDeletedEvent extends IModelContentChangedEvent {
-        /**
-         * At what line the deletion began (inclusive).
-         */
-        fromLineNumber: number;
-        /**
-         * At what line the deletion stopped (inclusive).
-         */
-        toLineNumber: number;
-    }
-
-    /**
-     * An event describing that line(s) have been inserted in a model.
-     */
-    export interface IModelContentChangedLinesInsertedEvent extends IModelContentChangedEvent {
-        /**
-         * Before what line did the insertion begin
-         */
-        fromLineNumber: number;
-        /**
-         * `toLineNumber` - `fromLineNumber` + 1 denotes the number of lines that were inserted
-         */
-        toLineNumber: number;
-        /**
-         * The text that was inserted
-         */
-        detail: string;
-    }
-
     /**
      * Decoration data associated with a model decorations changed event.
      */
@@ -2915,11 +2811,6 @@ declare module monaco.editor {
      * An editor.
      */
     export interface IEditor {
-        /**
-         * @deprecated. Please use `onDidChangeModelContent` instead.
-         * An event emitted when the content of the current model has changed.
-         */
-        onDidChangeModelRawContent(listener: (e: IModelContentChangedEvent) => void): IDisposable;
         /**
          * An event emitted when the content of the current model has changed.
          */
@@ -3841,6 +3732,30 @@ declare module monaco.languages {
      */
     export function registerCompletionItemProvider(languageId: string, provider: CompletionItemProvider): IDisposable;
 
+    /**
+     * Contains additional diagnostic information about the context in which
+     * a [code action](#CodeActionProvider.provideCodeActions) is run.
+     */
+    export interface CodeActionContext {
+        /**
+         * An array of diagnostics.
+         *
+         * @readonly
+         */
+        markers: editor.IMarkerData[];
+    }
+
+    /**
+     * The code action interface defines the contract between extensions and
+     * the [light bulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action) feature.
+     */
+    export interface CodeActionProvider {
+        /**
+         * Provide commands for the given document and range.
+         */
+        provideCodeActions(model: editor.IReadOnlyModel, range: Range, context: CodeActionContext, token: CancellationToken): CodeAction[] | Thenable<CodeAction[]>;
+    }
+
     /**
      * Completion item kinds.
      */
@@ -4145,7 +4060,7 @@ declare module monaco.languages {
         /**
          * The contents of this hover.
          */
-        htmlContent: IHTMLContentElement[];
+        contents: MarkedString[];
         /**
          * The range to which this hover applies. When missing, the
          * editor will use the range at the current position or the
@@ -4175,17 +4090,6 @@ declare module monaco.languages {
         score: number;
     }
 
-    /**
-     * The code action interface defines the contract between extensions and
-     * the [light bulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action) feature.
-     */
-    export interface CodeActionProvider {
-        /**
-         * Provide commands for the given document and range.
-         */
-        provideCodeActions(model: editor.IReadOnlyModel, range: Range, token: CancellationToken): CodeAction[] | Thenable<CodeAction[]>;
-    }
-
     /**
      * Represents a parameter of a callable-signature. A parameter can
      * have a label and a doc-comment.
@@ -4712,13 +4616,15 @@ declare module monaco.worker {
     export interface IMirrorModel {
         uri: Uri;
         version: number;
-        getText(): string;
+        getValue(): string;
     }
 
-    /**
-     * Get all available mirror models in this worker.
-     */
-    export function getMirrorModels(): IMirrorModel[];
+    export interface IWorkerContext {
+        /**
+         * Get all available mirror models in this worker.
+         */
+        getMirrorModels(): IMirrorModel[];
+    }
 
 }
 
@@ -4830,3 +4736,43 @@ declare module monaco.languages.typescript {
     export var typescriptDefaults: LanguageServiceDefaults;
     export var javascriptDefaults: LanguageServiceDefaults;
 }
+
+/*---------------------------------------------------------------------------------------------
+ *  Copyright (c) Microsoft Corporation. All rights reserved.
+ *  Licensed under the MIT License. See License.txt in the project root for license information.
+ *--------------------------------------------------------------------------------------------*/
+declare module monaco.languages.css {
+    export interface DiagnosticsOptions {
+        validate?: boolean;
+        lint?: {
+			compatibleVendorPrefixes?: 'ignore' | 'warning' | 'error',
+			vendorPrefix?: 'ignore' | 'warning' | 'error',
+			duplicateProperties?: 'ignore' | 'warning' | 'error',
+			emptyRules?: 'ignore' | 'warning' | 'error',
+			importStatement?: 'ignore' | 'warning' | 'error',
+			boxModel?: 'ignore' | 'warning' | 'error',
+			universalSelector?: 'ignore' | 'warning' | 'error',
+			zeroUnits?: 'ignore' | 'warning' | 'error',
+			fontFaceProperties?: 'ignore' | 'warning' | 'error',
+			hexColorLength?: 'ignore' | 'warning' | 'error',
+			argumentsInColorFunction?: 'ignore' | 'warning' | 'error',
+			unknownProperties?: 'ignore' | 'warning' | 'error',
+			ieHack?: 'ignore' | 'warning' | 'error',
+			unknownVendorSpecificProperties?: 'ignore' | 'warning' | 'error',
+			propertyIgnoredDueToDisplay?: 'ignore' | 'warning' | 'error',
+			important?: 'ignore' | 'warning' | 'error',
+			float?: 'ignore' | 'warning' | 'error',
+			idSelector?: 'ignore' | 'warning' | 'error'
+		}
+    }
+
+    export interface LanguageServiceDefaults {
+        onDidChange: IEvent<LanguageServiceDefaults>;
+        diagnosticsOptions: DiagnosticsOptions;
+        setDiagnosticsOptions(options: DiagnosticsOptions): void;
+    }
+
+    export var cssDefaults: LanguageServiceDefaults;
+    export var lessDefaults: LanguageServiceDefaults;
+	export var scssDefaults: LanguageServiceDefaults;
+}