mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 05:50:11 +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 { 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> {
|
||||
constructor(
|
||||
languageId: string,
|
||||
|
|
@ -44,9 +56,7 @@ export function setupMode(defaults: LanguageServiceDefaults): IDisposable {
|
|||
const client = new WorkerManager(defaults);
|
||||
disposables.push(client);
|
||||
|
||||
const worker: languageFeatures.WorkerAccessor<JSONWorker> = (
|
||||
...uris: Uri[]
|
||||
): Promise<JSONWorker> => {
|
||||
worker = (...uris: Uri[]): Promise<JSONWorker> => {
|
||||
return client.getLanguageServiceWorker(...uris);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -144,6 +144,22 @@ export class JSONWorker {
|
|||
let ranges = this._languageService.getSelectionRanges(document, positions, jsonDocument);
|
||||
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 {
|
||||
let models = this._ctx.getMirrorModels();
|
||||
for (let model of models) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
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 ---------
|
||||
|
||||
|
|
@ -197,8 +198,12 @@ export const jsonDefaults: LanguageServiceDefaults = new LanguageServiceDefaults
|
|||
modeConfigurationDefault
|
||||
);
|
||||
|
||||
export const getWorker = (): Promise<(...uris: Uri[]) => Promise<JSONWorker>> => {
|
||||
return getMode().then((mode) => mode.getWorker());
|
||||
};
|
||||
|
||||
// export to the global based API
|
||||
(<any>languages).json = { jsonDefaults };
|
||||
(<any>languages).json = { jsonDefaults, getWorker };
|
||||
|
||||
// --- Registration to monaco editor ---
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue