mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 11:38:51 +01:00
Contribute to json language server with a custom language. (#198583)
* Contribute to json language server with a custom language. * Add `snippets` to `"activationEvents"` * Remove hardcoded `snippets` from `documentSettings` * Fix wrong variable in `!isEqualSet()` * Use `extensions.allAcrossExtensionHosts` instead of `extensions.all` * enable `"enabledApiProposals"` for `extensions.allAcrossExtensionHosts` * Fix error: `Property 'allAcrossExtensionHosts' does not exist on type 'typeof extensions'` * Remove `snippets`
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
export type JSONLanguageStatus = { schemas: string[] };
|
||||
|
||||
import {
|
||||
workspace, window, languages, commands, ExtensionContext, extensions, Uri, ColorInformation,
|
||||
workspace, window, languages, commands, OutputChannel, ExtensionContext, extensions, Uri, ColorInformation,
|
||||
Diagnostic, StatusBarAlignment, TextEditor, TextDocument, FormattingOptions, CancellationToken, FoldingRange,
|
||||
ProviderResult, TextEdit, Range, Position, Disposable, CompletionItem, CompletionList, CompletionContext, Hover, MarkdownString, FoldingContext, DocumentSymbol, SymbolInformation, l10n
|
||||
} from 'vscode';
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
|
||||
import { hash } from './utils/hash';
|
||||
import { createDocumentSymbolsLimitItem, createLanguageStatusItem, createLimitStatusItem } from './languageStatus';
|
||||
import { getLanguageParticipants, LanguageParticipants } from './languageParticipants';
|
||||
|
||||
namespace VSCodeContentRequest {
|
||||
export const type: RequestType<string, string, any> = new RequestType('vscode/content');
|
||||
@@ -126,6 +127,9 @@ export type LanguageClientConstructor = (name: string, description: string, clie
|
||||
export interface Runtime {
|
||||
schemaRequests: SchemaRequestService;
|
||||
telemetry?: TelemetryReporter;
|
||||
readonly timer: {
|
||||
setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): Disposable;
|
||||
};
|
||||
}
|
||||
|
||||
export interface SchemaRequestService {
|
||||
@@ -141,13 +145,51 @@ let jsoncFoldingLimit = 5000;
|
||||
let jsonColorDecoratorLimit = 5000;
|
||||
let jsoncColorDecoratorLimit = 5000;
|
||||
|
||||
export async function startClient(context: ExtensionContext, newLanguageClient: LanguageClientConstructor, runtime: Runtime): Promise<BaseLanguageClient> {
|
||||
export interface AsyncDisposable {
|
||||
dispose(): Promise<void>;
|
||||
}
|
||||
|
||||
const toDispose = context.subscriptions;
|
||||
export async function startClient(context: ExtensionContext, newLanguageClient: LanguageClientConstructor, runtime: Runtime): Promise<AsyncDisposable> {
|
||||
const outputChannel = window.createOutputChannel(languageServerDescription);
|
||||
|
||||
const languageParticipants = getLanguageParticipants();
|
||||
context.subscriptions.push(languageParticipants);
|
||||
|
||||
let client: Disposable | undefined = await startClientWithParticipants(context, languageParticipants, newLanguageClient, outputChannel, runtime);
|
||||
|
||||
let restartTrigger: Disposable | undefined;
|
||||
languageParticipants.onDidChange(() => {
|
||||
if (restartTrigger) {
|
||||
restartTrigger.dispose();
|
||||
}
|
||||
restartTrigger = runtime.timer.setTimeout(async () => {
|
||||
if (client) {
|
||||
outputChannel.appendLine('Extensions have changed, restarting JSON server...');
|
||||
outputChannel.appendLine('');
|
||||
const oldClient = client;
|
||||
client = undefined;
|
||||
await oldClient.dispose();
|
||||
client = await startClientWithParticipants(context, languageParticipants, newLanguageClient, outputChannel, runtime);
|
||||
}
|
||||
}, 2000);
|
||||
});
|
||||
|
||||
return {
|
||||
dispose: async () => {
|
||||
restartTrigger?.dispose();
|
||||
await client?.dispose();
|
||||
outputChannel.dispose();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function startClientWithParticipants(context: ExtensionContext, languageParticipants: LanguageParticipants, newLanguageClient: LanguageClientConstructor, outputChannel: OutputChannel, runtime: Runtime): Promise<AsyncDisposable> {
|
||||
|
||||
const toDispose: Disposable[] = [];
|
||||
|
||||
let rangeFormatting: Disposable | undefined = undefined;
|
||||
|
||||
const documentSelector = ['json', 'jsonc'];
|
||||
const documentSelector = languageParticipants.documentSelector;
|
||||
|
||||
const schemaResolutionErrorStatusBarItem = window.createStatusBarItem('status.json.resolveError', StatusBarAlignment.Right, 0);
|
||||
schemaResolutionErrorStatusBarItem.name = l10n.t('JSON: Schema Resolution Error');
|
||||
@@ -306,6 +348,7 @@ export async function startClient(context: ExtensionContext, newLanguageClient:
|
||||
}
|
||||
};
|
||||
|
||||
clientOptions.outputChannel = outputChannel;
|
||||
// Create the language client and start the client.
|
||||
const client = newLanguageClient('json', languageServerDescription, clientOptions);
|
||||
client.registerProposedFeatures();
|
||||
@@ -490,7 +533,13 @@ export async function startClient(context: ExtensionContext, newLanguageClient:
|
||||
});
|
||||
}
|
||||
|
||||
return client;
|
||||
return {
|
||||
dispose: async () => {
|
||||
await client.stop();
|
||||
toDispose.forEach(d => d.dispose());
|
||||
rangeFormatting?.dispose();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function getSchemaAssociations(_context: ExtensionContext): ISchemaAssociation[] {
|
||||
|
||||
Reference in New Issue
Block a user