mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 18:32:56 +01:00
Strict checks for json
This commit is contained in:
parent
6054aa23fc
commit
45ae1272ea
6 changed files with 85 additions and 47 deletions
|
|
@ -118,7 +118,7 @@ function asDisposable(disposables: IDisposable[]): IDisposable {
|
||||||
|
|
||||||
function disposeAll(disposables: IDisposable[]) {
|
function disposeAll(disposables: IDisposable[]) {
|
||||||
while (disposables.length) {
|
while (disposables.length) {
|
||||||
disposables.pop().dispose();
|
disposables.pop()!.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ import type { worker } from '../fillers/monaco-editor-core';
|
||||||
import { URI } from 'vscode-uri';
|
import { URI } from 'vscode-uri';
|
||||||
import { DiagnosticsOptions } from './monaco.contribution';
|
import { DiagnosticsOptions } from './monaco.contribution';
|
||||||
|
|
||||||
let defaultSchemaRequestService;
|
let defaultSchemaRequestService: ((url: string) => Promise<string>) | undefined;
|
||||||
if (typeof fetch !== 'undefined') {
|
if (typeof fetch !== 'undefined') {
|
||||||
defaultSchemaRequestService = function (url) {
|
defaultSchemaRequestService = function (url: string) {
|
||||||
return fetch(url).then((response) => response.text());
|
return fetch(url).then((response) => response.text());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -32,7 +32,7 @@ export class JSONWorker {
|
||||||
return resolvePath(base, relativePath);
|
return resolvePath(base, relativePath);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
schemaRequestService: createData.enableSchemaRequest && defaultSchemaRequestService
|
schemaRequestService: createData.enableSchemaRequest ? defaultSchemaRequestService : undefined
|
||||||
});
|
});
|
||||||
this._languageService.configure(this._languageSettings);
|
this._languageService.configure(this._languageSettings);
|
||||||
}
|
}
|
||||||
|
|
@ -48,26 +48,35 @@ export class JSONWorker {
|
||||||
async doComplete(
|
async doComplete(
|
||||||
uri: string,
|
uri: string,
|
||||||
position: jsonService.Position
|
position: jsonService.Position
|
||||||
): Promise<jsonService.CompletionList> {
|
): Promise<jsonService.CompletionList | null> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
|
if (!document) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||||
return this._languageService.doComplete(document, position, jsonDocument);
|
return this._languageService.doComplete(document, position, jsonDocument);
|
||||||
}
|
}
|
||||||
async doResolve(item: jsonService.CompletionItem): Promise<jsonService.CompletionItem> {
|
async doResolve(item: jsonService.CompletionItem): Promise<jsonService.CompletionItem> {
|
||||||
return this._languageService.doResolve(item);
|
return this._languageService.doResolve(item);
|
||||||
}
|
}
|
||||||
async doHover(uri: string, position: jsonService.Position): Promise<jsonService.Hover> {
|
async doHover(uri: string, position: jsonService.Position): Promise<jsonService.Hover | null> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
|
if (!document) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||||
return this._languageService.doHover(document, position, jsonDocument);
|
return this._languageService.doHover(document, position, jsonDocument);
|
||||||
}
|
}
|
||||||
async format(
|
async format(
|
||||||
uri: string,
|
uri: string,
|
||||||
range: jsonService.Range,
|
range: jsonService.Range | null,
|
||||||
options: jsonService.FormattingOptions
|
options: jsonService.FormattingOptions
|
||||||
): Promise<jsonService.TextEdit[]> {
|
): Promise<jsonService.TextEdit[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
let textEdits = this._languageService.format(document, range, options);
|
if (!document) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
let textEdits = this._languageService.format(document, range! /* TODO */, options);
|
||||||
return Promise.resolve(textEdits);
|
return Promise.resolve(textEdits);
|
||||||
}
|
}
|
||||||
async resetSchema(uri: string): Promise<boolean> {
|
async resetSchema(uri: string): Promise<boolean> {
|
||||||
|
|
@ -75,12 +84,18 @@ export class JSONWorker {
|
||||||
}
|
}
|
||||||
async findDocumentSymbols(uri: string): Promise<jsonService.SymbolInformation[]> {
|
async findDocumentSymbols(uri: string): Promise<jsonService.SymbolInformation[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
|
if (!document) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||||
let symbols = this._languageService.findDocumentSymbols(document, jsonDocument);
|
let symbols = this._languageService.findDocumentSymbols(document, jsonDocument);
|
||||||
return Promise.resolve(symbols);
|
return Promise.resolve(symbols);
|
||||||
}
|
}
|
||||||
async findDocumentColors(uri: string): Promise<jsonService.ColorInformation[]> {
|
async findDocumentColors(uri: string): Promise<jsonService.ColorInformation[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
|
if (!document) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||||
let colorSymbols = this._languageService.findDocumentColors(document, jsonDocument);
|
let colorSymbols = this._languageService.findDocumentColors(document, jsonDocument);
|
||||||
return Promise.resolve(colorSymbols);
|
return Promise.resolve(colorSymbols);
|
||||||
|
|
@ -91,6 +106,9 @@ export class JSONWorker {
|
||||||
range: jsonService.Range
|
range: jsonService.Range
|
||||||
): Promise<jsonService.ColorPresentation[]> {
|
): Promise<jsonService.ColorPresentation[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
|
if (!document) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||||
let colorPresentations = this._languageService.getColorPresentations(
|
let colorPresentations = this._languageService.getColorPresentations(
|
||||||
document,
|
document,
|
||||||
|
|
@ -105,6 +123,9 @@ export class JSONWorker {
|
||||||
context?: { rangeLimit?: number }
|
context?: { rangeLimit?: number }
|
||||||
): Promise<jsonService.FoldingRange[]> {
|
): Promise<jsonService.FoldingRange[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
|
if (!document) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
let ranges = this._languageService.getFoldingRanges(document, context);
|
let ranges = this._languageService.getFoldingRanges(document, context);
|
||||||
return Promise.resolve(ranges);
|
return Promise.resolve(ranges);
|
||||||
}
|
}
|
||||||
|
|
@ -113,11 +134,14 @@ export class JSONWorker {
|
||||||
positions: jsonService.Position[]
|
positions: jsonService.Position[]
|
||||||
): Promise<jsonService.SelectionRange[]> {
|
): Promise<jsonService.SelectionRange[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
|
if (!document) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||||
let ranges = this._languageService.getSelectionRanges(document, positions, jsonDocument);
|
let ranges = this._languageService.getSelectionRanges(document, positions, jsonDocument);
|
||||||
return Promise.resolve(ranges);
|
return Promise.resolve(ranges);
|
||||||
}
|
}
|
||||||
private _getTextDocument(uri: string): jsonService.TextDocument {
|
private _getTextDocument(uri: string): jsonService.TextDocument | null {
|
||||||
let models = this._ctx.getMirrorModels();
|
let models = this._ctx.getMirrorModels();
|
||||||
for (let model of models) {
|
for (let model of models) {
|
||||||
if (model.uri.toString() === uri) {
|
if (model.uri.toString() === uri) {
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ export class DiagnosticsAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toSeverity(lsSeverity: number): MarkerSeverity {
|
function toSeverity(lsSeverity: number | undefined): MarkerSeverity {
|
||||||
switch (lsSeverity) {
|
switch (lsSeverity) {
|
||||||
case lsTypes.DiagnosticSeverity.Error:
|
case lsTypes.DiagnosticSeverity.Error:
|
||||||
return MarkerSeverity.Error;
|
return MarkerSeverity.Error;
|
||||||
|
|
@ -157,14 +157,20 @@ function toDiagnostics(resource: Uri, diag: lsTypes.Diagnostic): editor.IMarkerD
|
||||||
|
|
||||||
// --- completion ------
|
// --- completion ------
|
||||||
|
|
||||||
function fromPosition(position: Position): lsTypes.Position {
|
function fromPosition(position: Position): lsTypes.Position;
|
||||||
|
function fromPosition(position: undefined): undefined;
|
||||||
|
function fromPosition(position: Position | undefined): lsTypes.Position | undefined;
|
||||||
|
function fromPosition(position: Position | undefined): lsTypes.Position | undefined {
|
||||||
if (!position) {
|
if (!position) {
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
return { character: position.column - 1, line: position.lineNumber - 1 };
|
return { character: position.column - 1, line: position.lineNumber - 1 };
|
||||||
}
|
}
|
||||||
|
|
||||||
function fromRange(range: IRange): lsTypes.Range {
|
function fromRange(range: IRange): lsTypes.Range;
|
||||||
|
function fromRange(range: undefined): undefined;
|
||||||
|
function fromRange(range: IRange | undefined): lsTypes.Range | undefined;
|
||||||
|
function fromRange(range: IRange | undefined): lsTypes.Range | undefined {
|
||||||
if (!range) {
|
if (!range) {
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +182,10 @@ function fromRange(range: IRange): lsTypes.Range {
|
||||||
end: { line: range.endLineNumber - 1, character: range.endColumn - 1 }
|
end: { line: range.endLineNumber - 1, character: range.endColumn - 1 }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function toRange(range: lsTypes.Range): Range {
|
function toRange(range: lsTypes.Range): Range;
|
||||||
|
function toRange(range: undefined): undefined;
|
||||||
|
function toRange(range: lsTypes.Range | undefined): Range | undefined;
|
||||||
|
function toRange(range: lsTypes.Range | undefined): Range | undefined {
|
||||||
if (!range) {
|
if (!range) {
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
|
|
@ -212,7 +221,7 @@ function isInsertReplaceEdit(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toCompletionItemKind(kind: number): languages.CompletionItemKind {
|
function toCompletionItemKind(kind: number | undefined): languages.CompletionItemKind {
|
||||||
let mItemKind = languages.CompletionItemKind;
|
let mItemKind = languages.CompletionItemKind;
|
||||||
|
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
|
|
@ -300,7 +309,10 @@ function fromCompletionItemKind(kind: languages.CompletionItemKind): lsTypes.Com
|
||||||
return lsTypes.CompletionItemKind.Property;
|
return lsTypes.CompletionItemKind.Property;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toTextEdit(textEdit: lsTypes.TextEdit): editor.ISingleEditOperation {
|
function toTextEdit(textEdit: lsTypes.TextEdit): languages.TextEdit;
|
||||||
|
function toTextEdit(textEdit: undefined): undefined;
|
||||||
|
function toTextEdit(textEdit: lsTypes.TextEdit | undefined): languages.TextEdit | undefined;
|
||||||
|
function toTextEdit(textEdit: lsTypes.TextEdit | undefined): languages.TextEdit | undefined {
|
||||||
if (!textEdit) {
|
if (!textEdit) {
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
|
|
@ -310,7 +322,7 @@ function toTextEdit(textEdit: lsTypes.TextEdit): editor.ISingleEditOperation {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function toCommand(c: lsTypes.Command | undefined): languages.Command {
|
function toCommand(c: lsTypes.Command | undefined): languages.Command | undefined {
|
||||||
return c && c.command === 'editor.action.triggerSuggest'
|
return c && c.command === 'editor.action.triggerSuggest'
|
||||||
? { id: c.command, title: c.title, arguments: c.arguments }
|
? { id: c.command, title: c.title, arguments: c.arguments }
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
@ -328,7 +340,7 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
|
||||||
position: Position,
|
position: Position,
|
||||||
context: languages.CompletionContext,
|
context: languages.CompletionContext,
|
||||||
token: CancellationToken
|
token: CancellationToken
|
||||||
): Promise<languages.CompletionList> {
|
): Promise<languages.CompletionList | undefined> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource)
|
return this._worker(resource)
|
||||||
|
|
@ -371,7 +383,7 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
|
||||||
item.insertText = entry.textEdit.newText;
|
item.insertText = entry.textEdit.newText;
|
||||||
}
|
}
|
||||||
if (entry.additionalTextEdits) {
|
if (entry.additionalTextEdits) {
|
||||||
item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
|
item.additionalTextEdits = entry.additionalTextEdits.map<languages.TextEdit>(toTextEdit);
|
||||||
}
|
}
|
||||||
if (entry.insertTextFormat === lsTypes.InsertTextFormat.Snippet) {
|
if (entry.insertTextFormat === lsTypes.InsertTextFormat.Snippet) {
|
||||||
item.insertTextRules = languages.CompletionItemInsertTextRule.InsertAsSnippet;
|
item.insertTextRules = languages.CompletionItemInsertTextRule.InsertAsSnippet;
|
||||||
|
|
@ -415,7 +427,7 @@ function toMarkdownString(entry: lsTypes.MarkupContent | lsTypes.MarkedString):
|
||||||
|
|
||||||
function toMarkedStringArray(
|
function toMarkedStringArray(
|
||||||
contents: lsTypes.MarkupContent | lsTypes.MarkedString | lsTypes.MarkedString[]
|
contents: lsTypes.MarkupContent | lsTypes.MarkedString | lsTypes.MarkedString[]
|
||||||
): IMarkdownString[] {
|
): IMarkdownString[] | undefined {
|
||||||
if (!contents) {
|
if (!contents) {
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
|
|
@ -434,7 +446,7 @@ export class HoverAdapter implements languages.HoverProvider {
|
||||||
model: editor.IReadOnlyModel,
|
model: editor.IReadOnlyModel,
|
||||||
position: Position,
|
position: Position,
|
||||||
token: CancellationToken
|
token: CancellationToken
|
||||||
): Promise<languages.Hover> {
|
): Promise<languages.Hover | undefined> {
|
||||||
let resource = model.uri;
|
let resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource)
|
return this._worker(resource)
|
||||||
|
|
@ -514,7 +526,7 @@ export class DocumentSymbolAdapter implements languages.DocumentSymbolProvider {
|
||||||
public provideDocumentSymbols(
|
public provideDocumentSymbols(
|
||||||
model: editor.IReadOnlyModel,
|
model: editor.IReadOnlyModel,
|
||||||
token: CancellationToken
|
token: CancellationToken
|
||||||
): Promise<languages.DocumentSymbol[]> {
|
): Promise<languages.DocumentSymbol[] | undefined> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource)
|
return this._worker(resource)
|
||||||
|
|
@ -550,7 +562,7 @@ export class DocumentFormattingEditProvider implements languages.DocumentFormatt
|
||||||
model: editor.IReadOnlyModel,
|
model: editor.IReadOnlyModel,
|
||||||
options: languages.FormattingOptions,
|
options: languages.FormattingOptions,
|
||||||
token: CancellationToken
|
token: CancellationToken
|
||||||
): Promise<editor.ISingleEditOperation[]> {
|
): Promise<languages.TextEdit[] | undefined> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource).then((worker) => {
|
return this._worker(resource).then((worker) => {
|
||||||
|
|
@ -560,7 +572,7 @@ export class DocumentFormattingEditProvider implements languages.DocumentFormatt
|
||||||
if (!edits || edits.length === 0) {
|
if (!edits || edits.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return edits.map(toTextEdit);
|
return edits.map<languages.TextEdit>(toTextEdit);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -576,7 +588,7 @@ export class DocumentRangeFormattingEditProvider
|
||||||
range: Range,
|
range: Range,
|
||||||
options: languages.FormattingOptions,
|
options: languages.FormattingOptions,
|
||||||
token: CancellationToken
|
token: CancellationToken
|
||||||
): Promise<editor.ISingleEditOperation[]> {
|
): Promise<languages.TextEdit[] | undefined> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource).then((worker) => {
|
return this._worker(resource).then((worker) => {
|
||||||
|
|
@ -586,7 +598,7 @@ export class DocumentRangeFormattingEditProvider
|
||||||
if (!edits || edits.length === 0) {
|
if (!edits || edits.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return edits.map(toTextEdit);
|
return edits.map<languages.TextEdit>(toTextEdit);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -598,7 +610,7 @@ export class DocumentColorAdapter implements languages.DocumentColorProvider {
|
||||||
public provideDocumentColors(
|
public provideDocumentColors(
|
||||||
model: editor.IReadOnlyModel,
|
model: editor.IReadOnlyModel,
|
||||||
token: CancellationToken
|
token: CancellationToken
|
||||||
): Promise<languages.IColorInformation[]> {
|
): Promise<languages.IColorInformation[] | undefined> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource)
|
return this._worker(resource)
|
||||||
|
|
@ -618,7 +630,7 @@ export class DocumentColorAdapter implements languages.DocumentColorProvider {
|
||||||
model: editor.IReadOnlyModel,
|
model: editor.IReadOnlyModel,
|
||||||
info: languages.IColorInformation,
|
info: languages.IColorInformation,
|
||||||
token: CancellationToken
|
token: CancellationToken
|
||||||
): Promise<languages.IColorPresentation[]> {
|
): Promise<languages.IColorPresentation[] | undefined> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource)
|
return this._worker(resource)
|
||||||
|
|
@ -637,7 +649,7 @@ export class DocumentColorAdapter implements languages.DocumentColorProvider {
|
||||||
item.textEdit = toTextEdit(presentation.textEdit);
|
item.textEdit = toTextEdit(presentation.textEdit);
|
||||||
}
|
}
|
||||||
if (presentation.additionalTextEdits) {
|
if (presentation.additionalTextEdits) {
|
||||||
item.additionalTextEdits = presentation.additionalTextEdits.map(toTextEdit);
|
item.additionalTextEdits = presentation.additionalTextEdits.map<languages.TextEdit>(toTextEdit);
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
|
|
@ -652,7 +664,7 @@ export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
|
||||||
model: editor.IReadOnlyModel,
|
model: editor.IReadOnlyModel,
|
||||||
context: languages.FoldingContext,
|
context: languages.FoldingContext,
|
||||||
token: CancellationToken
|
token: CancellationToken
|
||||||
): Promise<languages.FoldingRange[]> {
|
): Promise<languages.FoldingRange[] | undefined> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource)
|
return this._worker(resource)
|
||||||
|
|
@ -675,7 +687,7 @@ export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toFoldingRangeKind(kind: lsTypes.FoldingRangeKind): languages.FoldingRangeKind {
|
function toFoldingRangeKind(kind: lsTypes.FoldingRangeKind): languages.FoldingRangeKind | undefined {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case lsTypes.FoldingRangeKind.Comment:
|
case lsTypes.FoldingRangeKind.Comment:
|
||||||
return languages.FoldingRangeKind.Comment;
|
return languages.FoldingRangeKind.Comment;
|
||||||
|
|
@ -694,16 +706,16 @@ export class SelectionRangeAdapter implements languages.SelectionRangeProvider {
|
||||||
model: editor.IReadOnlyModel,
|
model: editor.IReadOnlyModel,
|
||||||
positions: Position[],
|
positions: Position[],
|
||||||
token: CancellationToken
|
token: CancellationToken
|
||||||
): Promise<languages.SelectionRange[][]> {
|
): Promise<languages.SelectionRange[][] | undefined> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource)
|
return this._worker(resource)
|
||||||
.then((worker) => worker.getSelectionRanges(resource.toString(), positions.map(fromPosition)))
|
.then((worker) => worker.getSelectionRanges(resource.toString(), positions.map<lsTypes.Position>(fromPosition)))
|
||||||
.then((selectionRanges) => {
|
.then((selectionRanges) => {
|
||||||
if (!selectionRanges) {
|
if (!selectionRanges) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return selectionRanges.map((selectionRange) => {
|
return selectionRanges.map((selectionRange: lsTypes.SelectionRange | undefined) => {
|
||||||
const result: languages.SelectionRange[] = [];
|
const result: languages.SelectionRange[] = [];
|
||||||
while (selectionRange) {
|
while (selectionRange) {
|
||||||
result.push({ range: toRange(selectionRange.range) });
|
result.push({ range: toRange(selectionRange.range) });
|
||||||
|
|
|
||||||
|
|
@ -126,8 +126,8 @@ export interface LanguageServiceDefaults {
|
||||||
|
|
||||||
class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
|
class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
|
||||||
private _onDidChange = new Emitter<LanguageServiceDefaults>();
|
private _onDidChange = new Emitter<LanguageServiceDefaults>();
|
||||||
private _diagnosticsOptions: DiagnosticsOptions;
|
private _diagnosticsOptions!: DiagnosticsOptions;
|
||||||
private _modeConfiguration: ModeConfiguration;
|
private _modeConfiguration!: ModeConfiguration;
|
||||||
private _languageId: string;
|
private _languageId: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ import { languages } from '../fillers/monaco-editor-core';
|
||||||
export function createTokenizationSupport(supportComments: boolean): languages.TokensProvider {
|
export function createTokenizationSupport(supportComments: boolean): languages.TokensProvider {
|
||||||
return {
|
return {
|
||||||
getInitialState: () => new JSONState(null, null, false, null),
|
getInitialState: () => new JSONState(null, null, false, null),
|
||||||
tokenize: (line, state, offsetDelta?, stopAtOffset?) =>
|
tokenize: (line, state?) =>
|
||||||
tokenize(supportComments, line, <JSONState>state, offsetDelta, stopAtOffset)
|
tokenize(supportComments, line, <JSONState>state)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,15 +67,15 @@ class ParentsStack {
|
||||||
}
|
}
|
||||||
|
|
||||||
class JSONState implements languages.IState {
|
class JSONState implements languages.IState {
|
||||||
private _state: languages.IState;
|
private _state: languages.IState | null;
|
||||||
|
|
||||||
public scanError: ScanError;
|
public scanError: ScanError | null;
|
||||||
public lastWasColon: boolean;
|
public lastWasColon: boolean;
|
||||||
public parents: ParentsStack | null;
|
public parents: ParentsStack | null;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
state: languages.IState,
|
state: languages.IState | null,
|
||||||
scanError: ScanError,
|
scanError: ScanError | null,
|
||||||
lastWasColon: boolean,
|
lastWasColon: boolean,
|
||||||
parents: ParentsStack | null
|
parents: ParentsStack | null
|
||||||
) {
|
) {
|
||||||
|
|
@ -103,7 +103,7 @@ class JSONState implements languages.IState {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getStateData(): languages.IState {
|
public getStateData(): languages.IState | null {
|
||||||
return this._state;
|
return this._state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,8 +146,7 @@ function tokenize(
|
||||||
comments: boolean,
|
comments: boolean,
|
||||||
line: string,
|
line: string,
|
||||||
state: JSONState,
|
state: JSONState,
|
||||||
offsetDelta: number = 0,
|
offsetDelta: number = 0
|
||||||
stopAtOffset?: number
|
|
||||||
): languages.ILineTokens {
|
): languages.ILineTokens {
|
||||||
// handle multiline strings and block comments
|
// handle multiline strings and block comments
|
||||||
let numberOfInsertedCharacters = 0;
|
let numberOfInsertedCharacters = 0;
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,13 @@ export class WorkerManager {
|
||||||
private _lastUsedTime: number;
|
private _lastUsedTime: number;
|
||||||
private _configChangeListener: IDisposable;
|
private _configChangeListener: IDisposable;
|
||||||
|
|
||||||
private _worker: editor.MonacoWebWorker<JSONWorker>;
|
private _worker: editor.MonacoWebWorker<JSONWorker> | null;
|
||||||
private _client: Promise<JSONWorker>;
|
private _client: Promise<JSONWorker> | null;
|
||||||
|
|
||||||
constructor(defaults: LanguageServiceDefaults) {
|
constructor(defaults: LanguageServiceDefaults) {
|
||||||
this._defaults = defaults;
|
this._defaults = defaults;
|
||||||
this._worker = null;
|
this._worker = null;
|
||||||
|
this._client = null;
|
||||||
this._idleCheckInterval = window.setInterval(() => this._checkIfIdle(), 30 * 1000);
|
this._idleCheckInterval = window.setInterval(() => this._checkIfIdle(), 30 * 1000);
|
||||||
this._lastUsedTime = 0;
|
this._lastUsedTime = 0;
|
||||||
this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker());
|
this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker());
|
||||||
|
|
@ -81,7 +82,9 @@ export class WorkerManager {
|
||||||
_client = client;
|
_client = client;
|
||||||
})
|
})
|
||||||
.then((_) => {
|
.then((_) => {
|
||||||
return this._worker.withSyncedResources(resources);
|
if (this._worker) {
|
||||||
|
return this._worker.withSyncedResources(resources);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then((_) => _client);
|
.then((_) => _client);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue