mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 11:35:40 +01:00
parent
dfca77d071
commit
8d1525eb6d
3 changed files with 36 additions and 5 deletions
|
|
@ -10,6 +10,18 @@ import * as languageFeatures from '../common/lspLanguageFeatures';
|
||||||
import { createTokenizationSupport } from './tokenization';
|
import { createTokenizationSupport } from './tokenization';
|
||||||
import { Uri, IDisposable, languages, editor } from '../../fillers/monaco-editor-core';
|
import { Uri, IDisposable, languages, editor } from '../../fillers/monaco-editor-core';
|
||||||
|
|
||||||
|
let worker: languageFeatures.WorkerAccessor<JSONWorker>;
|
||||||
|
|
||||||
|
export function getWorker(): Promise<(...uris: Uri[]) => Promise<JSONWorker>> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!worker) {
|
||||||
|
return reject('JSON not registered!');
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(worker);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
class JSONDiagnosticsAdapter extends languageFeatures.DiagnosticsAdapter<JSONWorker> {
|
class JSONDiagnosticsAdapter extends languageFeatures.DiagnosticsAdapter<JSONWorker> {
|
||||||
constructor(
|
constructor(
|
||||||
languageId: string,
|
languageId: string,
|
||||||
|
|
@ -44,9 +56,7 @@ export function setupMode(defaults: LanguageServiceDefaults): IDisposable {
|
||||||
const client = new WorkerManager(defaults);
|
const client = new WorkerManager(defaults);
|
||||||
disposables.push(client);
|
disposables.push(client);
|
||||||
|
|
||||||
const worker: languageFeatures.WorkerAccessor<JSONWorker> = (
|
worker = (...uris: Uri[]): Promise<JSONWorker> => {
|
||||||
...uris: Uri[]
|
|
||||||
): Promise<JSONWorker> => {
|
|
||||||
return client.getLanguageServiceWorker(...uris);
|
return client.getLanguageServiceWorker(...uris);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,22 @@ export class JSONWorker {
|
||||||
let ranges = this._languageService.getSelectionRanges(document, positions, jsonDocument);
|
let ranges = this._languageService.getSelectionRanges(document, positions, jsonDocument);
|
||||||
return Promise.resolve(ranges);
|
return Promise.resolve(ranges);
|
||||||
}
|
}
|
||||||
|
async parseJSONDocument(uri: string): Promise<jsonService.JSONDocument | null> {
|
||||||
|
let document = this._getTextDocument(uri);
|
||||||
|
if (!document) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||||
|
return Promise.resolve(jsonDocument);
|
||||||
|
}
|
||||||
|
async getMatchingSchemas(uri: string): Promise<jsonService.MatchingSchema[]> {
|
||||||
|
let document = this._getTextDocument(uri);
|
||||||
|
if (!document) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||||
|
return Promise.resolve(this._languageService.getMatchingSchemas(document, jsonDocument));
|
||||||
|
}
|
||||||
private _getTextDocument(uri: string): jsonService.TextDocument | null {
|
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) {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
import * as mode from './jsonMode';
|
import * as mode from './jsonMode';
|
||||||
import { Emitter, IEvent, languages } from '../../fillers/monaco-editor-core';
|
import { Emitter, IEvent, languages, Uri } from '../../fillers/monaco-editor-core';
|
||||||
|
import type { JSONWorker } from './jsonWorker';
|
||||||
|
|
||||||
// --- JSON configuration and defaults ---------
|
// --- JSON configuration and defaults ---------
|
||||||
|
|
||||||
|
|
@ -197,8 +198,12 @@ export const jsonDefaults: LanguageServiceDefaults = new LanguageServiceDefaults
|
||||||
modeConfigurationDefault
|
modeConfigurationDefault
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const getWorker = (): Promise<(...uris: Uri[]) => Promise<JSONWorker>> => {
|
||||||
|
return getMode().then((mode) => mode.getWorker());
|
||||||
|
};
|
||||||
|
|
||||||
// export to the global based API
|
// export to the global based API
|
||||||
(<any>languages).json = { jsonDefaults };
|
(<any>languages).json = { jsonDefaults, getWorker };
|
||||||
|
|
||||||
// --- Registration to monaco editor ---
|
// --- Registration to monaco editor ---
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue