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 #597

Closed
wants to merge 1 commit into from

Conversation

JPinkney
Copy link
Contributor

@JPinkney JPinkney commented Jan 8, 2020

What does this PR do?

This PR introduces testing api that allows you to talk to a specific vscode extensions language features. It gives the ability to create tests that call into a vscode language extension for two reasons:

  1. Languages team can run tests against newer version of language plugins so we know if a language plugin can be updated or something needs to be fixed
  2. Che tests can talk directly with the language server so we know that if the language server request fails then it's an actual failure, rather than a test failing for a different reason and making it look like it was the cause

Examples of such tests can be found in: https://github.com/jpinkney/che-java-tests though they're WIP.

What issues does this PR fix or reference?

eclipse-che/che#14409

Release Notes

Docs PR

@tsmaeder
Copy link
Contributor

tsmaeder commented Jan 9, 2020

One thing that is not clear to me is how tests are loaded and run.

@JPinkney
Copy link
Contributor Author

I originally experimented with having the test loader as a che theia plugin but over time it felt like it made more sense to go with the strategy where each plugin will load the tests themselves. This allows the tests to have a certain level of configurability, such as how long the tests should try to run before timing out, and gives the additional benefit of not having to lock into using specific testing frameworks.

I've done some documentation on how the tests will work in https://github.com/jpinkney/che-java-tests#running-these-tests-automatically-when-a-workspace-starts but the basic idea is that you first start a workspace using a devfile that references a theia testing plugin (like https://github.com/jpinkney/che-java-tests). When the workspace starts the testing plugin loads in all the tests and communicates with the testing-api that is available in this PR

@JPinkney
Copy link
Contributor Author

@benoitf @tsmaeder Do you mind taking a look again ?

Copy link
Contributor

@benoitf benoitf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello
will look more deeply

I think there are some missings compilation.tsconfig.json for new folders ?

I was wondering why we need another root namespace for the test-service ? '@eclipse-che/testing-service and not included it in @eclipse-che/plugin under a test namespace

@JPinkney
Copy link
Contributor Author

@benoitf I can move it to under the @eclipse-che/plugin in a test namespace. Should I also move everything in testing-service-ext to under plugin-ext?

@azatsarynnyy
Copy link
Member

I'm +1 for keeping everything under a single che namespace.

@tsmaeder
Copy link
Contributor

I was wondering why we need another root namespace for the test-service ? '@eclipse-che/testing-service and not included it in @eclipse-che/plugin under a test namespace

I think it makes perfect sense to have a separate API namespace: the che namespace essentially deals with communicating with the WSMaster API: workspace, devfiles, etc. The testing namespace has no substantial connection with that topic.
Secondly, by keeping it separate, the testing API could moved upstream eventually. Marrying it to Che workspaces would make that impossbile.
Thirdly, it could make sense not to ship the testing API in a production version of Che, but only in a development version. Think of build.sh --production.
So I'm all for keeping it separate.

@benoitf
Copy link
Contributor

benoitf commented Feb 14, 2020

sorry Thomas, but for all the reasons you're referring I'm even more for included in che namespace

che namespace is what you have when using che instead of theia, its not for only using workspace API. (it's just that it's evolving on the needs)
If people write plugin's for che, they don't want to know if a separate API will be provided or not.
And if they need to find yet another namespace when writing code, it's even more complex.

Secondly, by keeping it separate, the testing API could moved upstream eventually. Marrying it to Che workspaces would make that impossbile.

I don't see where it would make it impossible, you can link namespace. And what if people already starts to use @eclipse-che/testing-service it would break for them as well.

Also I'm talking about che namespace. Che namespace is what you get when using Theia in Che, it's not only che workspace

Thirdly, it could make sense not to ship the testing API in a production version of Che, but only in a development version. Think of build.sh --production.

Why you would cut that ? If I use VS Code I can run tests on the 'production binary'. As a user I would want to test my plug-in on che.openshift.io for example.
Also people will never know if they could deploy or not the plugin in that case.

@tsmaeder
Copy link
Contributor

@benoitf the testing API is not che-specific, there is really no reason to include it in the Che namespace other than pure convenience. If Che is mentioned elsewhere in the PR, we should probably change those occurrences. We even thought about doing all the works upstream, but decided on doing it downstream because it's simpler to proceed with the task.

@tsmaeder
Copy link
Contributor

you can link namespace

Could you explain what you mean by this? I don't understand.

Copy link
Contributor

@tsmaeder tsmaeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As always, I have t couple of nitpicks, but otherwise I like this PR.

Signed-off-by: Josh Pinkney <joshpinkney@gmail.com>
@che-bot
Copy link
Contributor

che-bot commented Feb 18, 2020

Can one of the admins verify this patch?

@tsmaeder
Copy link
Contributor

lgtm!

Copy link
Contributor

@benoitf benoitf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please merge test service into @eclipse-che/plugin into test namespace or language.test


declare module '@eclipse-che/testing-service' {

export namespace languageserver {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these methods should be well documented, this is what the user will see when using code completion on the namespace

export function renameEdits(pluginID: string, resource: UriComponents, position: Position, newName: string, token: CancellationToken): PromiseLike<WorkspaceEditDto | undefined>;
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, are you following some rules to have sometimes Promise vs PromiseLike ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I this case, it should reflect what ever the "non-testing" version of the function uses.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok b/c I see in "non-testing"

provideRenameEdits(document: TextDocument, position: Position, newName: string, token: CancellationToken): ProviderResult<WorkspaceEdit>

provideDocumentSymbols(document: TextDocument, token: CancellationToken): ProviderResult<SymbolInformation[] | DocumentSymbol[]>;

and renameEdits is using PromiseLike while documentSymbols is using Promise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types are different because when I was creating the d.ts file I used the types that came out of https://github.com/eclipse-theia/theia/blob/master/packages/plugin-ext/src/common/plugin-api-rpc.ts#L1146 not the types that came out of the theia.d.ts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I see that but we should map to external/public stuff, not implementation, no ?

@tsmaeder tsmaeder mentioned this pull request Feb 19, 2020
34 tasks
token: CancellationToken
): PromiseLike<FoldingRange[] | undefined>;
export function documentColors(pluginID: string, resource: UriComponents, token: CancellationToken): PromiseLike<RawColorInfo[]>;
export function renameEdits(pluginID: string, resource: UriComponents, position: Position, newName: string, token: CancellationToken): PromiseLike<WorkspaceEditDto | undefined>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have WorkspaceEditDto and not WorkspaceEdit ?

Lots of types should come from @theia/plugin no ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it should follow the declaration, not the implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import * as vst from 'vscode-languageserver-types';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is used that import ?

@tsmaeder
Copy link
Contributor

please merge test service into @eclipse-che/plugin into test namespace or language.test

@JPinkney and I discussed this in yesterdays daily and we both agree that the testing stuff should be a separate module and API namespace if that's what you object to (for the reasons outlined before).

} from '@theia/plugin-ext/lib/common/plugin-api-rpc-model';
import { UriComponents } from '@theia/plugin-ext/lib/common/uri-components';
import { CancellationToken, FoldingContext } from '@theia/plugin';
import { SymbolInformation } from 'vscode-languageserver-types';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we not using https://github.com/eclipse-theia/theia/blob/master/packages/plugin/src/theia.d.ts#L5448 (I would say all types should come from @theia/plugin no) ?

@JPinkney
Copy link
Contributor Author

JPinkney commented Mar 10, 2020

@benoitf I've tried switching the types to be compatible with @theia/plugin but I'm not entirely sure if its possible

in che-languages-test-api when we call:

(languagesExt as LanguagesExt).$provideCompletionItems(......)

we are recieving back

Promise<CompletionResultDto | undefined>

from https://github.com/eclipse-theia/theia/blob/master/packages/plugin-ext/src/plugin/languages/completion.ts#L39. We aren't actually calling the delegate that has the type theia.CompletionItemProvider https://github.com/eclipse-theia/theia/blob/master/packages/plugin-ext/src/plugin/languages/completion.ts#L34.

Instead, we are getting back the converted result that happens after the delegate is called.

When I tried to modify che-languages-test-api to support @thiea/plugin types like

$provideImplementation(pluginID: string, document: TextDocument, position: Position, token: CancellationToken): ProviderResult<Definition | DefinitionLink[]> {
        return this.pluginHandleRegistry.lookupLanguagesExtForPluginAndAction(pluginID, 'implementation').then(({ languagesExt, handle }) => {
            return (languagesExt as LanguagesExt).$provideImplementation(handle, document.uri, { column: position.character, lineNumber: position.line }, token);
        });
    }

it leads to a lot of incompatible types for all of the methods (provideCompletionItems, provideImplementation, etc etc) in that class.

It looks like this is because the LanguagesExt interface is using the types from plugin-api-rpc-model' and che-languages-test-api is trying to use @theia/plugin types

I do have a working branch that has moved the testing api into @eclipse-che/api though.

@tsmaeder
Copy link
Contributor

I do have a working branch that has moved the testing api into @eclipse-che/api though.

Let's please not do that. It's wrong! Before we do that, let's discuss it in a call.

@ericwill
Copy link
Contributor

Superseded by #802

@ericwill ericwill closed this Jul 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants