All files / languages language-client.ts

100% Statements 14/14
100% Branches 2/2
100% Functions 3/3
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75                                                                                    30x 30x 30x 30x 30x 30x   30x 30x   30x       30x   30x               30x       2x 1x      
import * as vscode from 'vscode';
import { container } from 'tsyringe';
import { ServiceToken } from '@src/services/tokens';
import { LanguageClientFactory, ILanguageClient } from './language-client-factory';
 
export abstract class LanguageClientBase implements vscode.Disposable {
	/**
	 * Get the relative path to the compiled language server module.
	 */
	readonly serverPath: string;
 
	/**
	 * Get the human readably name of the language.
	 */
	readonly languageName: string;
 
	/**
	 * The language ID for the language client.
	 */
	readonly languageId: string;
 
	/**
	 * The channel ID for logging.
	 */
	readonly channelName: string;
 
	/**
	 * The channel ID for logging.
	 */
	readonly channelId: string;
 
	/**
	 * The output channel.
	 */
	readonly channel: vscode.OutputChannel;
 
	/**
	 * The VS Code language client.
	 */
	client: ILanguageClient | undefined;
 
	constructor(languageId: string, languageName: string) {
		this.languageName = languageName;
		this.languageId = languageId;
		this.channelName = `Mentor Language (${languageName})`;
		this.channelId = `mentor.language.${languageId}`;
		this.channel = vscode.window.createOutputChannel(this.channelName, this.channelId);
		this.serverPath = `dist/${languageId}-language-server.js`;
 
		const context = container.resolve<vscode.ExtensionContext>(ServiceToken.ExtensionContext);
		context.subscriptions.push(this);
 
		this.start(context);
	}
 
	protected start(context: vscode.ExtensionContext) {
		const factory = container.resolve<LanguageClientFactory>(ServiceToken.LanguageClientFactory);
 
		this.client = factory(context, {
			channelId: this.channelId,
			languageName: this.languageName,
			serverPath: this.serverPath,
			languageId: this.languageId,
			outputChannel: this.channel
		});
 
		this.client.start();
	}
 
	async dispose() {
		if (this.client) {
			await this.client.stop();
		}
	}
}