瀏覽代碼

Avoid loading the entire language service on the main thread code

Alex Dima 3 年之前
父節點
當前提交
a6ebcecf27

+ 1 - 0
.prettierignore

@@ -21,3 +21,4 @@
 /monaco-typescript/out/
 /monaco-typescript/release/
 /monaco-typescript/src/lib/
+/release/

+ 4 - 1
gulpfile.js

@@ -939,7 +939,10 @@ const generateTestSamplesTask = function () {
 		'</body>',
 		'</html>'
 	];
-	fs.writeFileSync(path.join(__dirname, 'monaco-editor/test/playground.generated/index.html'), index.join('\n'));
+	fs.writeFileSync(
+		path.join(__dirname, 'monaco-editor/test/playground.generated/index.html'),
+		index.join('\n')
+	);
 };
 
 function createSimpleServer(rootDir, port) {

+ 63 - 65
monaco-css/src/languageFeatures.ts

@@ -5,7 +5,7 @@
 
 import { LanguageServiceDefaults } from './monaco.contribution';
 import type { CSSWorker } from './cssWorker';
-import * as cssService from 'vscode-css-languageservice';
+import * as lsTypes from 'vscode-languageserver-types';
 import {
 	languages,
 	editor,
@@ -116,20 +116,20 @@ export class DiagnosticsAdapter {
 
 function toSeverity(lsSeverity: number): MarkerSeverity {
 	switch (lsSeverity) {
-		case cssService.DiagnosticSeverity.Error:
+		case lsTypes.DiagnosticSeverity.Error:
 			return MarkerSeverity.Error;
-		case cssService.DiagnosticSeverity.Warning:
+		case lsTypes.DiagnosticSeverity.Warning:
 			return MarkerSeverity.Warning;
-		case cssService.DiagnosticSeverity.Information:
+		case lsTypes.DiagnosticSeverity.Information:
 			return MarkerSeverity.Info;
-		case cssService.DiagnosticSeverity.Hint:
+		case lsTypes.DiagnosticSeverity.Hint:
 			return MarkerSeverity.Hint;
 		default:
 			return MarkerSeverity.Info;
 	}
 }
 
-function toDiagnostics(resource: Uri, diag: cssService.Diagnostic): editor.IMarkerData {
+function toDiagnostics(resource: Uri, diag: lsTypes.Diagnostic): editor.IMarkerData {
 	let code = typeof diag.code === 'number' ? String(diag.code) : <string>diag.code;
 
 	return {
@@ -146,14 +146,14 @@ function toDiagnostics(resource: Uri, diag: cssService.Diagnostic): editor.IMark
 
 // --- completion ------
 
-function fromPosition(position: Position): cssService.Position {
+function fromPosition(position: Position): lsTypes.Position {
 	if (!position) {
 		return void 0;
 	}
 	return { character: position.column - 1, line: position.lineNumber - 1 };
 }
 
-function fromRange(range: IRange): cssService.Range {
+function fromRange(range: IRange): lsTypes.Range {
 	if (!range) {
 		return void 0;
 	}
@@ -166,7 +166,7 @@ function fromRange(range: IRange): cssService.Range {
 	};
 }
 
-function toRange(range: cssService.Range): Range {
+function toRange(range: lsTypes.Range): Range {
 	if (!range) {
 		return void 0;
 	}
@@ -189,47 +189,47 @@ function toCompletionItemKind(kind: number): languages.CompletionItemKind {
 	let mItemKind = languages.CompletionItemKind;
 
 	switch (kind) {
-		case cssService.CompletionItemKind.Text:
+		case lsTypes.CompletionItemKind.Text:
 			return mItemKind.Text;
-		case cssService.CompletionItemKind.Method:
+		case lsTypes.CompletionItemKind.Method:
 			return mItemKind.Method;
-		case cssService.CompletionItemKind.Function:
+		case lsTypes.CompletionItemKind.Function:
 			return mItemKind.Function;
-		case cssService.CompletionItemKind.Constructor:
+		case lsTypes.CompletionItemKind.Constructor:
 			return mItemKind.Constructor;
-		case cssService.CompletionItemKind.Field:
+		case lsTypes.CompletionItemKind.Field:
 			return mItemKind.Field;
-		case cssService.CompletionItemKind.Variable:
+		case lsTypes.CompletionItemKind.Variable:
 			return mItemKind.Variable;
-		case cssService.CompletionItemKind.Class:
+		case lsTypes.CompletionItemKind.Class:
 			return mItemKind.Class;
-		case cssService.CompletionItemKind.Interface:
+		case lsTypes.CompletionItemKind.Interface:
 			return mItemKind.Interface;
-		case cssService.CompletionItemKind.Module:
+		case lsTypes.CompletionItemKind.Module:
 			return mItemKind.Module;
-		case cssService.CompletionItemKind.Property:
+		case lsTypes.CompletionItemKind.Property:
 			return mItemKind.Property;
-		case cssService.CompletionItemKind.Unit:
+		case lsTypes.CompletionItemKind.Unit:
 			return mItemKind.Unit;
-		case cssService.CompletionItemKind.Value:
+		case lsTypes.CompletionItemKind.Value:
 			return mItemKind.Value;
-		case cssService.CompletionItemKind.Enum:
+		case lsTypes.CompletionItemKind.Enum:
 			return mItemKind.Enum;
-		case cssService.CompletionItemKind.Keyword:
+		case lsTypes.CompletionItemKind.Keyword:
 			return mItemKind.Keyword;
-		case cssService.CompletionItemKind.Snippet:
+		case lsTypes.CompletionItemKind.Snippet:
 			return mItemKind.Snippet;
-		case cssService.CompletionItemKind.Color:
+		case lsTypes.CompletionItemKind.Color:
 			return mItemKind.Color;
-		case cssService.CompletionItemKind.File:
+		case lsTypes.CompletionItemKind.File:
 			return mItemKind.File;
-		case cssService.CompletionItemKind.Reference:
+		case lsTypes.CompletionItemKind.Reference:
 			return mItemKind.Reference;
 	}
 	return mItemKind.Property;
 }
 
-function toTextEdit(textEdit: cssService.TextEdit): editor.ISingleEditOperation {
+function toTextEdit(textEdit: lsTypes.TextEdit): editor.ISingleEditOperation {
 	if (!textEdit) {
 		return void 0;
 	}
@@ -239,7 +239,7 @@ function toTextEdit(textEdit: cssService.TextEdit): editor.ISingleEditOperation
 	};
 }
 
-function toCommand(c: cssService.Command | undefined): languages.Command {
+function toCommand(c: lsTypes.Command | undefined): languages.Command {
 	return c && c.command === 'editor.action.triggerSuggest'
 		? { id: c.command, title: c.title, arguments: c.arguments }
 		: undefined;
@@ -302,7 +302,7 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
 					if (entry.additionalTextEdits) {
 						item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
 					}
-					if (entry.insertTextFormat === cssService.InsertTextFormat.Snippet) {
+					if (entry.insertTextFormat === lsTypes.InsertTextFormat.Snippet) {
 						item.insertTextRules = languages.CompletionItemInsertTextRule.InsertAsSnippet;
 					}
 					return item;
@@ -316,15 +316,13 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
 	}
 }
 
-function isMarkupContent(thing: any): thing is cssService.MarkupContent {
+function isMarkupContent(thing: any): thing is lsTypes.MarkupContent {
 	return (
-		thing && typeof thing === 'object' && typeof (<cssService.MarkupContent>thing).kind === 'string'
+		thing && typeof thing === 'object' && typeof (<lsTypes.MarkupContent>thing).kind === 'string'
 	);
 }
 
-function toMarkdownString(
-	entry: cssService.MarkupContent | cssService.MarkedString
-): IMarkdownString {
+function toMarkdownString(entry: lsTypes.MarkupContent | lsTypes.MarkedString): IMarkdownString {
 	if (typeof entry === 'string') {
 		return {
 			value: entry
@@ -345,7 +343,7 @@ function toMarkdownString(
 }
 
 function toMarkedStringArray(
-	contents: cssService.MarkupContent | cssService.MarkedString | cssService.MarkedString[]
+	contents: lsTypes.MarkupContent | lsTypes.MarkedString | lsTypes.MarkedString[]
 ): IMarkdownString[] {
 	if (!contents) {
 		return void 0;
@@ -388,11 +386,11 @@ export class HoverAdapter implements languages.HoverProvider {
 
 function toDocumentHighlightKind(kind: number): languages.DocumentHighlightKind {
 	switch (kind) {
-		case cssService.DocumentHighlightKind.Read:
+		case lsTypes.DocumentHighlightKind.Read:
 			return languages.DocumentHighlightKind.Read;
-		case cssService.DocumentHighlightKind.Write:
+		case lsTypes.DocumentHighlightKind.Write:
 			return languages.DocumentHighlightKind.Write;
-		case cssService.DocumentHighlightKind.Text:
+		case lsTypes.DocumentHighlightKind.Text:
 			return languages.DocumentHighlightKind.Text;
 	}
 	return languages.DocumentHighlightKind.Text;
@@ -428,7 +426,7 @@ export class DocumentHighlightAdapter implements languages.DocumentHighlightProv
 
 // --- definition ------
 
-function toLocation(location: cssService.Location): languages.Location {
+function toLocation(location: lsTypes.Location): languages.Location {
 	return {
 		uri: Uri.parse(location.uri),
 		range: toRange(location.range)
@@ -486,7 +484,7 @@ export class ReferenceAdapter implements languages.ReferenceProvider {
 
 // --- rename ------
 
-function toWorkspaceEdit(edit: cssService.WorkspaceEdit): languages.WorkspaceEdit {
+function toWorkspaceEdit(edit: lsTypes.WorkspaceEdit): languages.WorkspaceEdit {
 	if (!edit || !edit.changes) {
 		return void 0;
 	}
@@ -532,45 +530,45 @@ export class RenameAdapter implements languages.RenameProvider {
 
 // --- document symbols ------
 
-function toSymbolKind(kind: cssService.SymbolKind): languages.SymbolKind {
+function toSymbolKind(kind: lsTypes.SymbolKind): languages.SymbolKind {
 	let mKind = languages.SymbolKind;
 
 	switch (kind) {
-		case cssService.SymbolKind.File:
+		case lsTypes.SymbolKind.File:
 			return mKind.Array;
-		case cssService.SymbolKind.Module:
+		case lsTypes.SymbolKind.Module:
 			return mKind.Module;
-		case cssService.SymbolKind.Namespace:
+		case lsTypes.SymbolKind.Namespace:
 			return mKind.Namespace;
-		case cssService.SymbolKind.Package:
+		case lsTypes.SymbolKind.Package:
 			return mKind.Package;
-		case cssService.SymbolKind.Class:
+		case lsTypes.SymbolKind.Class:
 			return mKind.Class;
-		case cssService.SymbolKind.Method:
+		case lsTypes.SymbolKind.Method:
 			return mKind.Method;
-		case cssService.SymbolKind.Property:
+		case lsTypes.SymbolKind.Property:
 			return mKind.Property;
-		case cssService.SymbolKind.Field:
+		case lsTypes.SymbolKind.Field:
 			return mKind.Field;
-		case cssService.SymbolKind.Constructor:
+		case lsTypes.SymbolKind.Constructor:
 			return mKind.Constructor;
-		case cssService.SymbolKind.Enum:
+		case lsTypes.SymbolKind.Enum:
 			return mKind.Enum;
-		case cssService.SymbolKind.Interface:
+		case lsTypes.SymbolKind.Interface:
 			return mKind.Interface;
-		case cssService.SymbolKind.Function:
+		case lsTypes.SymbolKind.Function:
 			return mKind.Function;
-		case cssService.SymbolKind.Variable:
+		case lsTypes.SymbolKind.Variable:
 			return mKind.Variable;
-		case cssService.SymbolKind.Constant:
+		case lsTypes.SymbolKind.Constant:
 			return mKind.Constant;
-		case cssService.SymbolKind.String:
+		case lsTypes.SymbolKind.String:
 			return mKind.String;
-		case cssService.SymbolKind.Number:
+		case lsTypes.SymbolKind.Number:
 			return mKind.Number;
-		case cssService.SymbolKind.Boolean:
+		case lsTypes.SymbolKind.Boolean:
 			return mKind.Boolean;
-		case cssService.SymbolKind.Array:
+		case lsTypes.SymbolKind.Array:
 			return mKind.Array;
 	}
 	return mKind.Function;
@@ -679,7 +677,7 @@ export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
 						end: range.endLine + 1
 					};
 					if (typeof range.kind !== 'undefined') {
-						result.kind = toFoldingRangeKind(<cssService.FoldingRangeKind>range.kind);
+						result.kind = toFoldingRangeKind(<lsTypes.FoldingRangeKind>range.kind);
 					}
 					return result;
 				});
@@ -687,13 +685,13 @@ export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
 	}
 }
 
-function toFoldingRangeKind(kind: cssService.FoldingRangeKind): languages.FoldingRangeKind {
+function toFoldingRangeKind(kind: lsTypes.FoldingRangeKind): languages.FoldingRangeKind {
 	switch (kind) {
-		case cssService.FoldingRangeKind.Comment:
+		case lsTypes.FoldingRangeKind.Comment:
 			return languages.FoldingRangeKind.Comment;
-		case cssService.FoldingRangeKind.Imports:
+		case lsTypes.FoldingRangeKind.Imports:
 			return languages.FoldingRangeKind.Imports;
-		case cssService.FoldingRangeKind.Region:
+		case lsTypes.FoldingRangeKind.Region:
 			return languages.FoldingRangeKind.Region;
 	}
 }

+ 7 - 1
monaco-editor/test/dev-setup.js

@@ -142,7 +142,13 @@
 	let RESOLVED_CORE = new Component('editor', 'vs', METADATA.CORE.paths);
 	self.RESOLVED_CORE_PATH = RESOLVED_CORE.getResolvedPath('');
 	let RESOLVED_PLUGINS = METADATA.PLUGINS.map(function (plugin) {
-		return new Component(plugin.name, plugin.modulePrefix, plugin.paths, plugin.rootPath, plugin.contrib);
+		return new Component(
+			plugin.name,
+			plugin.modulePrefix,
+			plugin.paths,
+			plugin.rootPath,
+			plugin.contrib
+		);
 	});
 	METADATA = null;
 

+ 83 - 91
monaco-html/src/languageFeatures.ts

@@ -4,7 +4,7 @@
  *--------------------------------------------------------------------------------------------*/
 
 import type { HTMLWorker } from './htmlWorker';
-import * as htmlService from 'vscode-html-languageservice';
+import * as lsTypes from 'vscode-languageserver-types';
 import {
 	languages,
 	editor,
@@ -21,14 +21,14 @@ export interface WorkerAccessor {
 
 // --- completion ------
 
-function fromPosition(position: Position): htmlService.Position {
+function fromPosition(position: Position): lsTypes.Position {
 	if (!position) {
 		return void 0;
 	}
 	return { character: position.column - 1, line: position.lineNumber - 1 };
 }
 
-function fromRange(range: Range): htmlService.Range {
+function fromRange(range: Range): lsTypes.Range {
 	if (!range) {
 		return void 0;
 	}
@@ -38,7 +38,7 @@ function fromRange(range: Range): htmlService.Range {
 	};
 }
 
-function toRange(range: htmlService.Range): Range {
+function toRange(range: lsTypes.Range): Range {
 	if (!range) {
 		return void 0;
 	}
@@ -51,11 +51,11 @@ function toRange(range: htmlService.Range): Range {
 }
 
 function isInsertReplaceEdit(
-	edit: htmlService.TextEdit | htmlService.InsertReplaceEdit
-): edit is htmlService.InsertReplaceEdit {
+	edit: lsTypes.TextEdit | lsTypes.InsertReplaceEdit
+): edit is lsTypes.InsertReplaceEdit {
 	return (
-		typeof (<htmlService.InsertReplaceEdit>edit).insert !== 'undefined' &&
-		typeof (<htmlService.InsertReplaceEdit>edit).replace !== 'undefined'
+		typeof (<lsTypes.InsertReplaceEdit>edit).insert !== 'undefined' &&
+		typeof (<lsTypes.InsertReplaceEdit>edit).replace !== 'undefined'
 	);
 }
 
@@ -63,93 +63,91 @@ function toCompletionItemKind(kind: number): languages.CompletionItemKind {
 	const mItemKind = languages.CompletionItemKind;
 
 	switch (kind) {
-		case htmlService.CompletionItemKind.Text:
+		case lsTypes.CompletionItemKind.Text:
 			return mItemKind.Text;
-		case htmlService.CompletionItemKind.Method:
+		case lsTypes.CompletionItemKind.Method:
 			return mItemKind.Method;
-		case htmlService.CompletionItemKind.Function:
+		case lsTypes.CompletionItemKind.Function:
 			return mItemKind.Function;
-		case htmlService.CompletionItemKind.Constructor:
+		case lsTypes.CompletionItemKind.Constructor:
 			return mItemKind.Constructor;
-		case htmlService.CompletionItemKind.Field:
+		case lsTypes.CompletionItemKind.Field:
 			return mItemKind.Field;
-		case htmlService.CompletionItemKind.Variable:
+		case lsTypes.CompletionItemKind.Variable:
 			return mItemKind.Variable;
-		case htmlService.CompletionItemKind.Class:
+		case lsTypes.CompletionItemKind.Class:
 			return mItemKind.Class;
-		case htmlService.CompletionItemKind.Interface:
+		case lsTypes.CompletionItemKind.Interface:
 			return mItemKind.Interface;
-		case htmlService.CompletionItemKind.Module:
+		case lsTypes.CompletionItemKind.Module:
 			return mItemKind.Module;
-		case htmlService.CompletionItemKind.Property:
+		case lsTypes.CompletionItemKind.Property:
 			return mItemKind.Property;
-		case htmlService.CompletionItemKind.Unit:
+		case lsTypes.CompletionItemKind.Unit:
 			return mItemKind.Unit;
-		case htmlService.CompletionItemKind.Value:
+		case lsTypes.CompletionItemKind.Value:
 			return mItemKind.Value;
-		case htmlService.CompletionItemKind.Enum:
+		case lsTypes.CompletionItemKind.Enum:
 			return mItemKind.Enum;
-		case htmlService.CompletionItemKind.Keyword:
+		case lsTypes.CompletionItemKind.Keyword:
 			return mItemKind.Keyword;
-		case htmlService.CompletionItemKind.Snippet:
+		case lsTypes.CompletionItemKind.Snippet:
 			return mItemKind.Snippet;
-		case htmlService.CompletionItemKind.Color:
+		case lsTypes.CompletionItemKind.Color:
 			return mItemKind.Color;
-		case htmlService.CompletionItemKind.File:
+		case lsTypes.CompletionItemKind.File:
 			return mItemKind.File;
-		case htmlService.CompletionItemKind.Reference:
+		case lsTypes.CompletionItemKind.Reference:
 			return mItemKind.Reference;
 	}
 	return mItemKind.Property;
 }
 
-function fromCompletionItemKind(
-	kind: languages.CompletionItemKind
-): htmlService.CompletionItemKind {
+function fromCompletionItemKind(kind: languages.CompletionItemKind): lsTypes.CompletionItemKind {
 	const mItemKind = languages.CompletionItemKind;
 
 	switch (kind) {
 		case mItemKind.Text:
-			return htmlService.CompletionItemKind.Text;
+			return lsTypes.CompletionItemKind.Text;
 		case mItemKind.Method:
-			return htmlService.CompletionItemKind.Method;
+			return lsTypes.CompletionItemKind.Method;
 		case mItemKind.Function:
-			return htmlService.CompletionItemKind.Function;
+			return lsTypes.CompletionItemKind.Function;
 		case mItemKind.Constructor:
-			return htmlService.CompletionItemKind.Constructor;
+			return lsTypes.CompletionItemKind.Constructor;
 		case mItemKind.Field:
-			return htmlService.CompletionItemKind.Field;
+			return lsTypes.CompletionItemKind.Field;
 		case mItemKind.Variable:
-			return htmlService.CompletionItemKind.Variable;
+			return lsTypes.CompletionItemKind.Variable;
 		case mItemKind.Class:
-			return htmlService.CompletionItemKind.Class;
+			return lsTypes.CompletionItemKind.Class;
 		case mItemKind.Interface:
-			return htmlService.CompletionItemKind.Interface;
+			return lsTypes.CompletionItemKind.Interface;
 		case mItemKind.Module:
-			return htmlService.CompletionItemKind.Module;
+			return lsTypes.CompletionItemKind.Module;
 		case mItemKind.Property:
-			return htmlService.CompletionItemKind.Property;
+			return lsTypes.CompletionItemKind.Property;
 		case mItemKind.Unit:
-			return htmlService.CompletionItemKind.Unit;
+			return lsTypes.CompletionItemKind.Unit;
 		case mItemKind.Value:
-			return htmlService.CompletionItemKind.Value;
+			return lsTypes.CompletionItemKind.Value;
 		case mItemKind.Enum:
-			return htmlService.CompletionItemKind.Enum;
+			return lsTypes.CompletionItemKind.Enum;
 		case mItemKind.Keyword:
-			return htmlService.CompletionItemKind.Keyword;
+			return lsTypes.CompletionItemKind.Keyword;
 		case mItemKind.Snippet:
-			return htmlService.CompletionItemKind.Snippet;
+			return lsTypes.CompletionItemKind.Snippet;
 		case mItemKind.Color:
-			return htmlService.CompletionItemKind.Color;
+			return lsTypes.CompletionItemKind.Color;
 		case mItemKind.File:
-			return htmlService.CompletionItemKind.File;
+			return lsTypes.CompletionItemKind.File;
 		case mItemKind.Reference:
-			return htmlService.CompletionItemKind.Reference;
+			return lsTypes.CompletionItemKind.Reference;
 	}
-	return htmlService.CompletionItemKind.Property;
+	return lsTypes.CompletionItemKind.Property;
 }
 
-function toTextEdit(textEdit: htmlService.TextEdit): editor.ISingleEditOperation {
+function toTextEdit(textEdit: lsTypes.TextEdit): editor.ISingleEditOperation {
 	if (!textEdit) {
 		return void 0;
 	}
@@ -159,7 +157,7 @@ function toTextEdit(textEdit: htmlService.TextEdit): editor.ISingleEditOperation
 	};
 }
 
-function toCommand(c: htmlService.Command | undefined): languages.Command {
+function toCommand(c: lsTypes.Command | undefined): languages.Command {
 	return c && c.command === 'editor.action.triggerSuggest'
 		? { id: c.command, title: c.title, arguments: c.arguments }
 		: undefined;
@@ -222,7 +220,7 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
 					if (entry.additionalTextEdits) {
 						item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
 					}
-					if (entry.insertTextFormat === htmlService.InsertTextFormat.Snippet) {
+					if (entry.insertTextFormat === lsTypes.InsertTextFormat.Snippet) {
 						item.insertTextRules = languages.CompletionItemInsertTextRule.InsertAsSnippet;
 					}
 					return item;
@@ -238,17 +236,13 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
 
 // --- hover ------
 
-function isMarkupContent(thing: any): thing is htmlService.MarkupContent {
+function isMarkupContent(thing: any): thing is lsTypes.MarkupContent {
 	return (
-		thing &&
-		typeof thing === 'object' &&
-		typeof (<htmlService.MarkupContent>thing).kind === 'string'
+		thing && typeof thing === 'object' && typeof (<lsTypes.MarkupContent>thing).kind === 'string'
 	);
 }
 
-function toMarkdownString(
-	entry: htmlService.MarkupContent | htmlService.MarkedString
-): IMarkdownString {
+function toMarkdownString(entry: lsTypes.MarkupContent | lsTypes.MarkedString): IMarkdownString {
 	if (typeof entry === 'string') {
 		return {
 			value: entry
@@ -269,7 +263,7 @@ function toMarkdownString(
 }
 
 function toMarkedStringArray(
-	contents: htmlService.MarkupContent | htmlService.MarkedString | htmlService.MarkedString[]
+	contents: lsTypes.MarkupContent | lsTypes.MarkedString | lsTypes.MarkedString[]
 ): IMarkdownString[] {
 	if (!contents) {
 		return void 0;
@@ -308,15 +302,15 @@ export class HoverAdapter implements languages.HoverProvider {
 
 // --- document highlights ------
 
-function toHighlighKind(kind: htmlService.DocumentHighlightKind): languages.DocumentHighlightKind {
+function toHighlighKind(kind: lsTypes.DocumentHighlightKind): languages.DocumentHighlightKind {
 	const mKind = languages.DocumentHighlightKind;
 
 	switch (kind) {
-		case htmlService.DocumentHighlightKind.Read:
+		case lsTypes.DocumentHighlightKind.Read:
 			return mKind.Read;
-		case htmlService.DocumentHighlightKind.Write:
+		case lsTypes.DocumentHighlightKind.Write:
 			return mKind.Write;
-		case htmlService.DocumentHighlightKind.Text:
+		case lsTypes.DocumentHighlightKind.Text:
 			return mKind.Text;
 	}
 	return mKind.Text;
@@ -348,45 +342,45 @@ export class DocumentHighlightAdapter implements languages.DocumentHighlightProv
 
 // --- document symbols ------
 
-function toSymbolKind(kind: htmlService.SymbolKind): languages.SymbolKind {
+function toSymbolKind(kind: lsTypes.SymbolKind): languages.SymbolKind {
 	let mKind = languages.SymbolKind;
 
 	switch (kind) {
-		case htmlService.SymbolKind.File:
+		case lsTypes.SymbolKind.File:
 			return mKind.Array;
-		case htmlService.SymbolKind.Module:
+		case lsTypes.SymbolKind.Module:
 			return mKind.Module;
-		case htmlService.SymbolKind.Namespace:
+		case lsTypes.SymbolKind.Namespace:
 			return mKind.Namespace;
-		case htmlService.SymbolKind.Package:
+		case lsTypes.SymbolKind.Package:
 			return mKind.Package;
-		case htmlService.SymbolKind.Class:
+		case lsTypes.SymbolKind.Class:
 			return mKind.Class;
-		case htmlService.SymbolKind.Method:
+		case lsTypes.SymbolKind.Method:
 			return mKind.Method;
-		case htmlService.SymbolKind.Property:
+		case lsTypes.SymbolKind.Property:
 			return mKind.Property;
-		case htmlService.SymbolKind.Field:
+		case lsTypes.SymbolKind.Field:
 			return mKind.Field;
-		case htmlService.SymbolKind.Constructor:
+		case lsTypes.SymbolKind.Constructor:
 			return mKind.Constructor;
-		case htmlService.SymbolKind.Enum:
+		case lsTypes.SymbolKind.Enum:
 			return mKind.Enum;
-		case htmlService.SymbolKind.Interface:
+		case lsTypes.SymbolKind.Interface:
 			return mKind.Interface;
-		case htmlService.SymbolKind.Function:
+		case lsTypes.SymbolKind.Function:
 			return mKind.Function;
-		case htmlService.SymbolKind.Variable:
+		case lsTypes.SymbolKind.Variable:
 			return mKind.Variable;
-		case htmlService.SymbolKind.Constant:
+		case lsTypes.SymbolKind.Constant:
 			return mKind.Constant;
-		case htmlService.SymbolKind.String:
+		case lsTypes.SymbolKind.String:
 			return mKind.String;
-		case htmlService.SymbolKind.Number:
+		case lsTypes.SymbolKind.Number:
 			return mKind.Number;
-		case htmlService.SymbolKind.Boolean:
+		case lsTypes.SymbolKind.Boolean:
 			return mKind.Boolean;
-		case htmlService.SymbolKind.Array:
+		case lsTypes.SymbolKind.Array:
 			return mKind.Array;
 	}
 	return mKind.Function;
@@ -445,9 +439,7 @@ export class DocumentLinkAdapter implements languages.LinkProvider {
 	}
 }
 
-function fromFormattingOptions(
-	options: languages.FormattingOptions
-): htmlService.FormattingOptions {
+function fromFormattingOptions(options: languages.FormattingOptions): lsTypes.FormattingOptions {
 	return {
 		tabSize: options.tabSize,
 		insertSpaces: options.insertSpaces
@@ -524,7 +516,7 @@ export class RenameAdapter implements languages.RenameProvider {
 	}
 }
 
-function toWorkspaceEdit(edit: htmlService.WorkspaceEdit): languages.WorkspaceEdit {
+function toWorkspaceEdit(edit: lsTypes.WorkspaceEdit): languages.WorkspaceEdit {
 	if (!edit || !edit.changes) {
 		return void 0;
 	}
@@ -568,7 +560,7 @@ export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
 						end: range.endLine + 1
 					};
 					if (typeof range.kind !== 'undefined') {
-						result.kind = toFoldingRangeKind(<htmlService.FoldingRangeKind>range.kind);
+						result.kind = toFoldingRangeKind(<lsTypes.FoldingRangeKind>range.kind);
 					}
 					return result;
 				});
@@ -576,13 +568,13 @@ export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
 	}
 }
 
-function toFoldingRangeKind(kind: htmlService.FoldingRangeKind): languages.FoldingRangeKind {
+function toFoldingRangeKind(kind: lsTypes.FoldingRangeKind): languages.FoldingRangeKind {
 	switch (kind) {
-		case htmlService.FoldingRangeKind.Comment:
+		case lsTypes.FoldingRangeKind.Comment:
 			return languages.FoldingRangeKind.Comment;
-		case htmlService.FoldingRangeKind.Imports:
+		case lsTypes.FoldingRangeKind.Imports:
 			return languages.FoldingRangeKind.Imports;
-		case htmlService.FoldingRangeKind.Region:
+		case lsTypes.FoldingRangeKind.Region:
 			return languages.FoldingRangeKind.Region;
 	}
 }

+ 83 - 91
monaco-json/src/languageFeatures.ts

@@ -17,7 +17,7 @@ import {
 	MarkerSeverity,
 	IMarkdownString
 } from './fillers/monaco-editor-core';
-import * as jsonService from 'vscode-json-languageservice';
+import * as lsTypes from 'vscode-languageserver-types';
 
 export interface WorkerAccessor {
 	(...more: Uri[]): Promise<JSONWorker>;
@@ -127,20 +127,20 @@ export class DiagnosticsAdapter {
 
 function toSeverity(lsSeverity: number): MarkerSeverity {
 	switch (lsSeverity) {
-		case jsonService.DiagnosticSeverity.Error:
+		case lsTypes.DiagnosticSeverity.Error:
 			return MarkerSeverity.Error;
-		case jsonService.DiagnosticSeverity.Warning:
+		case lsTypes.DiagnosticSeverity.Warning:
 			return MarkerSeverity.Warning;
-		case jsonService.DiagnosticSeverity.Information:
+		case lsTypes.DiagnosticSeverity.Information:
 			return MarkerSeverity.Info;
-		case jsonService.DiagnosticSeverity.Hint:
+		case lsTypes.DiagnosticSeverity.Hint:
 			return MarkerSeverity.Hint;
 		default:
 			return MarkerSeverity.Info;
 	}
 }
 
-function toDiagnostics(resource: Uri, diag: jsonService.Diagnostic): editor.IMarkerData {
+function toDiagnostics(resource: Uri, diag: lsTypes.Diagnostic): editor.IMarkerData {
 	let code = typeof diag.code === 'number' ? String(diag.code) : <string>diag.code;
 
 	return {
@@ -157,14 +157,14 @@ function toDiagnostics(resource: Uri, diag: jsonService.Diagnostic): editor.IMar
 
 // --- completion ------
 
-function fromPosition(position: Position): jsonService.Position {
+function fromPosition(position: Position): lsTypes.Position {
 	if (!position) {
 		return void 0;
 	}
 	return { character: position.column - 1, line: position.lineNumber - 1 };
 }
 
-function fromRange(range: IRange): jsonService.Range {
+function fromRange(range: IRange): lsTypes.Range {
 	if (!range) {
 		return void 0;
 	}
@@ -176,7 +176,7 @@ function fromRange(range: IRange): jsonService.Range {
 		end: { line: range.endLineNumber - 1, character: range.endColumn - 1 }
 	};
 }
-function toRange(range: jsonService.Range): Range {
+function toRange(range: lsTypes.Range): Range {
 	if (!range) {
 		return void 0;
 	}
@@ -196,15 +196,15 @@ interface InsertReplaceEdit {
 	/**
 	 * The range if the insert is requested
 	 */
-	insert: jsonService.Range;
+	insert: lsTypes.Range;
 	/**
 	 * The range if the replace is requested.
 	 */
-	replace: jsonService.Range;
+	replace: lsTypes.Range;
 }
 
 function isInsertReplaceEdit(
-	edit: jsonService.TextEdit | InsertReplaceEdit
+	edit: lsTypes.TextEdit | InsertReplaceEdit
 ): edit is InsertReplaceEdit {
 	return (
 		typeof (<InsertReplaceEdit>edit).insert !== 'undefined' &&
@@ -216,93 +216,91 @@ function toCompletionItemKind(kind: number): languages.CompletionItemKind {
 	let mItemKind = languages.CompletionItemKind;
 
 	switch (kind) {
-		case jsonService.CompletionItemKind.Text:
+		case lsTypes.CompletionItemKind.Text:
 			return mItemKind.Text;
-		case jsonService.CompletionItemKind.Method:
+		case lsTypes.CompletionItemKind.Method:
 			return mItemKind.Method;
-		case jsonService.CompletionItemKind.Function:
+		case lsTypes.CompletionItemKind.Function:
 			return mItemKind.Function;
-		case jsonService.CompletionItemKind.Constructor:
+		case lsTypes.CompletionItemKind.Constructor:
 			return mItemKind.Constructor;
-		case jsonService.CompletionItemKind.Field:
+		case lsTypes.CompletionItemKind.Field:
 			return mItemKind.Field;
-		case jsonService.CompletionItemKind.Variable:
+		case lsTypes.CompletionItemKind.Variable:
 			return mItemKind.Variable;
-		case jsonService.CompletionItemKind.Class:
+		case lsTypes.CompletionItemKind.Class:
 			return mItemKind.Class;
-		case jsonService.CompletionItemKind.Interface:
+		case lsTypes.CompletionItemKind.Interface:
 			return mItemKind.Interface;
-		case jsonService.CompletionItemKind.Module:
+		case lsTypes.CompletionItemKind.Module:
 			return mItemKind.Module;
-		case jsonService.CompletionItemKind.Property:
+		case lsTypes.CompletionItemKind.Property:
 			return mItemKind.Property;
-		case jsonService.CompletionItemKind.Unit:
+		case lsTypes.CompletionItemKind.Unit:
 			return mItemKind.Unit;
-		case jsonService.CompletionItemKind.Value:
+		case lsTypes.CompletionItemKind.Value:
 			return mItemKind.Value;
-		case jsonService.CompletionItemKind.Enum:
+		case lsTypes.CompletionItemKind.Enum:
 			return mItemKind.Enum;
-		case jsonService.CompletionItemKind.Keyword:
+		case lsTypes.CompletionItemKind.Keyword:
 			return mItemKind.Keyword;
-		case jsonService.CompletionItemKind.Snippet:
+		case lsTypes.CompletionItemKind.Snippet:
 			return mItemKind.Snippet;
-		case jsonService.CompletionItemKind.Color:
+		case lsTypes.CompletionItemKind.Color:
 			return mItemKind.Color;
-		case jsonService.CompletionItemKind.File:
+		case lsTypes.CompletionItemKind.File:
 			return mItemKind.File;
-		case jsonService.CompletionItemKind.Reference:
+		case lsTypes.CompletionItemKind.Reference:
 			return mItemKind.Reference;
 	}
 	return mItemKind.Property;
 }
 
-function fromCompletionItemKind(
-	kind: languages.CompletionItemKind
-): jsonService.CompletionItemKind {
+function fromCompletionItemKind(kind: languages.CompletionItemKind): lsTypes.CompletionItemKind {
 	let mItemKind = languages.CompletionItemKind;
 
 	switch (kind) {
 		case mItemKind.Text:
-			return jsonService.CompletionItemKind.Text;
+			return lsTypes.CompletionItemKind.Text;
 		case mItemKind.Method:
-			return jsonService.CompletionItemKind.Method;
+			return lsTypes.CompletionItemKind.Method;
 		case mItemKind.Function:
-			return jsonService.CompletionItemKind.Function;
+			return lsTypes.CompletionItemKind.Function;
 		case mItemKind.Constructor:
-			return jsonService.CompletionItemKind.Constructor;
+			return lsTypes.CompletionItemKind.Constructor;
 		case mItemKind.Field:
-			return jsonService.CompletionItemKind.Field;
+			return lsTypes.CompletionItemKind.Field;
 		case mItemKind.Variable:
-			return jsonService.CompletionItemKind.Variable;
+			return lsTypes.CompletionItemKind.Variable;
 		case mItemKind.Class:
-			return jsonService.CompletionItemKind.Class;
+			return lsTypes.CompletionItemKind.Class;
 		case mItemKind.Interface:
-			return jsonService.CompletionItemKind.Interface;
+			return lsTypes.CompletionItemKind.Interface;
 		case mItemKind.Module:
-			return jsonService.CompletionItemKind.Module;
+			return lsTypes.CompletionItemKind.Module;
 		case mItemKind.Property:
-			return jsonService.CompletionItemKind.Property;
+			return lsTypes.CompletionItemKind.Property;
 		case mItemKind.Unit:
-			return jsonService.CompletionItemKind.Unit;
+			return lsTypes.CompletionItemKind.Unit;
 		case mItemKind.Value:
-			return jsonService.CompletionItemKind.Value;
+			return lsTypes.CompletionItemKind.Value;
 		case mItemKind.Enum:
-			return jsonService.CompletionItemKind.Enum;
+			return lsTypes.CompletionItemKind.Enum;
 		case mItemKind.Keyword:
-			return jsonService.CompletionItemKind.Keyword;
+			return lsTypes.CompletionItemKind.Keyword;
 		case mItemKind.Snippet:
-			return jsonService.CompletionItemKind.Snippet;
+			return lsTypes.CompletionItemKind.Snippet;
 		case mItemKind.Color:
-			return jsonService.CompletionItemKind.Color;
+			return lsTypes.CompletionItemKind.Color;
 		case mItemKind.File:
-			return jsonService.CompletionItemKind.File;
+			return lsTypes.CompletionItemKind.File;
 		case mItemKind.Reference:
-			return jsonService.CompletionItemKind.Reference;
+			return lsTypes.CompletionItemKind.Reference;
 	}
-	return jsonService.CompletionItemKind.Property;
+	return lsTypes.CompletionItemKind.Property;
 }
 
-function toTextEdit(textEdit: jsonService.TextEdit): editor.ISingleEditOperation {
+function toTextEdit(textEdit: lsTypes.TextEdit): editor.ISingleEditOperation {
 	if (!textEdit) {
 		return void 0;
 	}
@@ -312,7 +310,7 @@ function toTextEdit(textEdit: jsonService.TextEdit): editor.ISingleEditOperation
 	};
 }
 
-function toCommand(c: jsonService.Command | undefined): languages.Command {
+function toCommand(c: lsTypes.Command | undefined): languages.Command {
 	return c && c.command === 'editor.action.triggerSuggest'
 		? { id: c.command, title: c.title, arguments: c.arguments }
 		: undefined;
@@ -375,7 +373,7 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
 					if (entry.additionalTextEdits) {
 						item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
 					}
-					if (entry.insertTextFormat === jsonService.InsertTextFormat.Snippet) {
+					if (entry.insertTextFormat === lsTypes.InsertTextFormat.Snippet) {
 						item.insertTextRules = languages.CompletionItemInsertTextRule.InsertAsSnippet;
 					}
 					return item;
@@ -389,17 +387,13 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
 	}
 }
 
-function isMarkupContent(thing: any): thing is jsonService.MarkupContent {
+function isMarkupContent(thing: any): thing is lsTypes.MarkupContent {
 	return (
-		thing &&
-		typeof thing === 'object' &&
-		typeof (<jsonService.MarkupContent>thing).kind === 'string'
+		thing && typeof thing === 'object' && typeof (<lsTypes.MarkupContent>thing).kind === 'string'
 	);
 }
 
-function toMarkdownString(
-	entry: jsonService.MarkupContent | jsonService.MarkedString
-): IMarkdownString {
+function toMarkdownString(entry: lsTypes.MarkupContent | lsTypes.MarkedString): IMarkdownString {
 	if (typeof entry === 'string') {
 		return {
 			value: entry
@@ -420,7 +414,7 @@ function toMarkdownString(
 }
 
 function toMarkedStringArray(
-	contents: jsonService.MarkupContent | jsonService.MarkedString | jsonService.MarkedString[]
+	contents: lsTypes.MarkupContent | lsTypes.MarkedString | lsTypes.MarkedString[]
 ): IMarkdownString[] {
 	if (!contents) {
 		return void 0;
@@ -461,7 +455,7 @@ export class HoverAdapter implements languages.HoverProvider {
 
 // --- definition ------
 
-function toLocation(location: jsonService.Location): languages.Location {
+function toLocation(location: lsTypes.Location): languages.Location {
 	return {
 		uri: Uri.parse(location.uri),
 		range: toRange(location.range)
@@ -470,45 +464,45 @@ function toLocation(location: jsonService.Location): languages.Location {
 
 // --- document symbols ------
 
-function toSymbolKind(kind: jsonService.SymbolKind): languages.SymbolKind {
+function toSymbolKind(kind: lsTypes.SymbolKind): languages.SymbolKind {
 	let mKind = languages.SymbolKind;
 
 	switch (kind) {
-		case jsonService.SymbolKind.File:
+		case lsTypes.SymbolKind.File:
 			return mKind.Array;
-		case jsonService.SymbolKind.Module:
+		case lsTypes.SymbolKind.Module:
 			return mKind.Module;
-		case jsonService.SymbolKind.Namespace:
+		case lsTypes.SymbolKind.Namespace:
 			return mKind.Namespace;
-		case jsonService.SymbolKind.Package:
+		case lsTypes.SymbolKind.Package:
 			return mKind.Package;
-		case jsonService.SymbolKind.Class:
+		case lsTypes.SymbolKind.Class:
 			return mKind.Class;
-		case jsonService.SymbolKind.Method:
+		case lsTypes.SymbolKind.Method:
 			return mKind.Method;
-		case jsonService.SymbolKind.Property:
+		case lsTypes.SymbolKind.Property:
 			return mKind.Property;
-		case jsonService.SymbolKind.Field:
+		case lsTypes.SymbolKind.Field:
 			return mKind.Field;
-		case jsonService.SymbolKind.Constructor:
+		case lsTypes.SymbolKind.Constructor:
 			return mKind.Constructor;
-		case jsonService.SymbolKind.Enum:
+		case lsTypes.SymbolKind.Enum:
 			return mKind.Enum;
-		case jsonService.SymbolKind.Interface:
+		case lsTypes.SymbolKind.Interface:
 			return mKind.Interface;
-		case jsonService.SymbolKind.Function:
+		case lsTypes.SymbolKind.Function:
 			return mKind.Function;
-		case jsonService.SymbolKind.Variable:
+		case lsTypes.SymbolKind.Variable:
 			return mKind.Variable;
-		case jsonService.SymbolKind.Constant:
+		case lsTypes.SymbolKind.Constant:
 			return mKind.Constant;
-		case jsonService.SymbolKind.String:
+		case lsTypes.SymbolKind.String:
 			return mKind.String;
-		case jsonService.SymbolKind.Number:
+		case lsTypes.SymbolKind.Number:
 			return mKind.Number;
-		case jsonService.SymbolKind.Boolean:
+		case lsTypes.SymbolKind.Boolean:
 			return mKind.Boolean;
-		case jsonService.SymbolKind.Array:
+		case lsTypes.SymbolKind.Array:
 			return mKind.Array;
 	}
 	return mKind.Function;
@@ -542,9 +536,7 @@ export class DocumentSymbolAdapter implements languages.DocumentSymbolProvider {
 	}
 }
 
-function fromFormattingOptions(
-	options: languages.FormattingOptions
-): jsonService.FormattingOptions {
+function fromFormattingOptions(options: languages.FormattingOptions): lsTypes.FormattingOptions {
 	return {
 		tabSize: options.tabSize,
 		insertSpaces: options.insertSpaces
@@ -675,7 +667,7 @@ export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
 						end: range.endLine + 1
 					};
 					if (typeof range.kind !== 'undefined') {
-						result.kind = toFoldingRangeKind(<jsonService.FoldingRangeKind>range.kind);
+						result.kind = toFoldingRangeKind(<lsTypes.FoldingRangeKind>range.kind);
 					}
 					return result;
 				});
@@ -683,13 +675,13 @@ export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
 	}
 }
 
-function toFoldingRangeKind(kind: jsonService.FoldingRangeKind): languages.FoldingRangeKind {
+function toFoldingRangeKind(kind: lsTypes.FoldingRangeKind): languages.FoldingRangeKind {
 	switch (kind) {
-		case jsonService.FoldingRangeKind.Comment:
+		case lsTypes.FoldingRangeKind.Comment:
 			return languages.FoldingRangeKind.Comment;
-		case jsonService.FoldingRangeKind.Imports:
+		case lsTypes.FoldingRangeKind.Imports:
 			return languages.FoldingRangeKind.Imports;
-		case jsonService.FoldingRangeKind.Region:
+		case lsTypes.FoldingRangeKind.Region:
 			return languages.FoldingRangeKind.Region;
 	}
 	return void 0;