Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Implementation of testing api for testing vscode extensions language features [Part 2] #802

Merged
merged 16 commits into from
Sep 10, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { CheSideCarContentReaderMainImpl } from './che-sidecar-content-reader-ma
import { CheGithubMainImpl } from './che-github-main';
import { CheOpenshiftMainImpl } from './che-openshift-main';
import { CheOauthMainImpl } from './che-oauth-main';
import { CheLanguagesTestAPIImpl } from './che-languages-test-api';

@injectable()
export class CheApiProvider implements MainPluginApiProvider {
Expand All @@ -43,6 +44,7 @@ export class CheApiProvider implements MainPluginApiProvider {
rpc.set(PLUGIN_RPC_CONTEXT.CHE_USER_MAIN, new CheUserMainImpl(container));
rpc.set(PLUGIN_RPC_CONTEXT.CHE_PRODUCT_MAIN, new CheProductMainImpl(container, rpc));
rpc.set(PLUGIN_RPC_CONTEXT.CHE_SIDERCAR_CONTENT_READER_MAIN, new CheSideCarContentReaderMainImpl(container, rpc));
rpc.set(PLUGIN_RPC_CONTEXT.CHE_LANGUAGES_TEST_API_MAIN, new CheLanguagesTestAPIImpl(container));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ import { CheTaskResolver } from './che-task-resolver';
import { CheTaskTerminalWidgetManager } from './che-task-terminal-widget-manager';
import { TaskTerminalWidgetManager } from '@theia/task/lib/browser/task-terminal-widget-manager';
import { ContainerPicker } from './container-picker';
import { ChePluginHandleRegistry } from './che-plugin-handle-registry';
import { CheLanguagesMainTestImpl } from './che-languages-test-main';
import { RPCProtocol } from '@theia/plugin-ext/lib/common/rpc-protocol';
import { interfaces } from 'inversify';
import { LanguagesMainFactory } from '@theia/plugin-ext';

export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(CheApiProvider).toSelf().inSingletonScope();
Expand Down Expand Up @@ -122,4 +127,12 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {

bind(CheTaskTerminalWidgetManager).toSelf().inSingletonScope();
rebind(TaskTerminalWidgetManager).toService(CheTaskTerminalWidgetManager);

bind(ChePluginHandleRegistry).toSelf().inSingletonScope();
bind(CheLanguagesMainTestImpl).toSelf().inTransientScope();
rebind(LanguagesMainFactory).toFactory((context: interfaces.Context) => (rpc: RPCProtocol) => {
const child = context.container.createChild();
child.bind(RPCProtocol).toConstantValue(rpc);
return child.get(CheLanguagesMainTestImpl);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/*********************************************************************
* Copyright (c) 2020 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import { ChePluginHandleRegistry } from './che-plugin-handle-registry';
import { interfaces } from 'inversify';
import { CheLanguagesTestAPI } from '../common/che-languages-test-protocol';
import {
CompletionContext,
CompletionResultDto,
SignatureHelp,
Hover,
DocumentHighlight,
Range,
TextEdit,
FormattingOptions,
Definition,
DocumentLink,
CodeLensSymbol,
DocumentSymbol,
ReferenceContext,
Location,
SignatureHelpContext,
CodeActionContext,
CodeAction,
FoldingRange,
} from '@theia/plugin-ext/lib/common/plugin-api-rpc-model';
import { UriComponents } from '@theia/plugin-ext/lib/common/uri-components';
svor marked this conversation as resolved.
Show resolved Hide resolved
import { CancellationToken, FoldingContext } from '@theia/plugin';
import { SymbolInformation } from 'vscode-languageserver-types';
svor marked this conversation as resolved.
Show resolved Hide resolved
import {
Position,
Selection,
RawColorInfo,
WorkspaceEditDto
} from '@theia/plugin-ext/lib/common/plugin-api-rpc';

/**
* This class redirects language api requests to the correct sidecars and returns the results
*/
export class CheLanguagesTestAPIImpl implements CheLanguagesTestAPI {

private readonly pluginHandleRegistry: ChePluginHandleRegistry;

constructor(container: interfaces.Container) {
this.pluginHandleRegistry = container.get(ChePluginHandleRegistry);
}

async $provideCompletionItems(pluginID: string, resource: UriComponents, position: Position,
context: CompletionContext, token: CancellationToken): Promise<CompletionResultDto | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'completion');
return languagesExt.$provideCompletionItems(handle, resource, position, context, token);
}

async $provideDefinition(pluginID: string, resource: UriComponents, position: Position, token: CancellationToken): Promise<Definition | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'definition');
return languagesExt.$provideDefinition(handle, resource, position, token);
}

async $provideDeclaration(pluginID: string, resource: UriComponents, position: Position, token: CancellationToken): Promise<Definition | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'declaration');
return languagesExt.$provideDeclaration(handle, resource, position, token);
}

async $provideSignatureHelp(pluginID: string, resource: UriComponents, position: Position, context: SignatureHelpContext, token: CancellationToken
): Promise<SignatureHelp | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'signatureHelp');
return languagesExt.$provideSignatureHelp(handle, resource, position, context, token);
}

async $provideImplementation(pluginID: string, resource: UriComponents, position: Position, token: CancellationToken): Promise<Definition | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'implementation');
return languagesExt.$provideImplementation(handle, resource, position, token);
}

async $provideTypeDefinition(pluginID: string, resource: UriComponents, position: Position, token: CancellationToken): Promise<Definition | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'typeDefinition');
return languagesExt.$provideTypeDefinition(handle, resource, position, token);
}

async $provideHover(pluginID: string, resource: UriComponents, position: Position, token: CancellationToken): Promise<Hover | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'hover');
return languagesExt.$provideHover(handle, resource, position, token);
}

async $provideDocumentHighlights(pluginID: string, resource: UriComponents, position: Position, token: CancellationToken): Promise<DocumentHighlight[] | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'documentHighlight');
return languagesExt.$provideDocumentHighlights(handle, resource, position, token);
}

$provideWorkspaceSymbols(pluginID: string, query: string, token: CancellationToken): PromiseLike<SymbolInformation[]> {
return this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'workspaceSymbols').then(({ languagesExt, handle }) =>
languagesExt.$provideWorkspaceSymbols(handle, query, token)
);
}

async $provideDocumentFormattingEdits(pluginID: string, resource: UriComponents,
options: FormattingOptions, token: CancellationToken): Promise<TextEdit[] | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'documentFormattingEdits');
return languagesExt.$provideDocumentFormattingEdits(handle, resource, options, token);
}

async $provideDocumentRangeFormattingEdits(pluginID: string, resource: UriComponents, range: Range,
options: FormattingOptions, token: CancellationToken): Promise<TextEdit[] | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'documentRangeFormattingEdits');
return languagesExt.$provideDocumentRangeFormattingEdits(handle, resource, range, options, token);
}

async $provideOnTypeFormattingEdits(pluginID: string,
resource: UriComponents,
position: Position,
ch: string,
options: FormattingOptions,
token: CancellationToken
): Promise<TextEdit[] | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'onTypeFormattingEdits');
return languagesExt.$provideOnTypeFormattingEdits(handle, resource, position, ch, options, token);
}

async $provideDocumentLinks(pluginID: string, resource: UriComponents, token: CancellationToken): Promise<DocumentLink[] | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'documentLinks');
return languagesExt.$provideDocumentLinks(handle, resource, token);
}

async $provideCodeActions(pluginID: string,
resource: UriComponents,
rangeOrSelection: Range | Selection,
context: CodeActionContext,
token: CancellationToken
): Promise<CodeAction[] | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'codeActions');
return languagesExt.$provideCodeActions(handle, resource, rangeOrSelection, context, token);
}

async $provideCodeLenses(pluginID: string, resource: UriComponents, token: CancellationToken): Promise<CodeLensSymbol[] | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'codeLenses');
return languagesExt.$provideCodeLenses(handle, resource, token);
}

async $provideReferences(pluginID: string, resource: UriComponents, position: Position, context: ReferenceContext, token: CancellationToken): Promise<Location[] | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'references');
return languagesExt.$provideReferences(handle, resource, position, context, token);
}

$provideDocumentColors(pluginID: string, resource: UriComponents, token: CancellationToken): PromiseLike<RawColorInfo[]> {
return this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'documentColors').then(({ languagesExt, handle }) =>
languagesExt.$provideDocumentColors(handle, resource, token)
);
}

$provideFoldingRange(pluginID: string,
resource: UriComponents,
context: FoldingContext,
token: CancellationToken
): PromiseLike<FoldingRange[] | undefined> {
return this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'foldingRange').then(({ languagesExt, handle }) =>
languagesExt.$provideFoldingRange(handle, resource, context, token)
);
}

$provideRenameEdits(pluginID: string, resource: UriComponents, position: Position, newName: string, token: CancellationToken): PromiseLike<WorkspaceEditDto | undefined> {
return this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'renameEdits').then(({ languagesExt, handle }) =>
languagesExt.$provideRenameEdits(handle, resource, position, newName, token)
);
}

async $provideDocumentSymbols(pluginID: string, resource: UriComponents, token: CancellationToken): Promise<DocumentSymbol[] | undefined> {
const { languagesExt, handle } = await this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'symbols');
return languagesExt.$provideDocumentSymbols(handle, resource, token);
}
}
Loading