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

Load snippets via plugin resource #948

Merged
merged 7 commits into from
Mar 16, 2021

Conversation

tsmaeder
Copy link
Contributor

@tsmaeder tsmaeder commented Dec 8, 2020

Signed-off-by: Thomas Mäder tmader@redhat.com

What does this PR do?

Load snippet resources via the plugin resource loading mechanism instead of file uris (like the are in Theia)

What issues does this PR fix or reference?

eclipse-che/che#16502

How to test this PR?

Use the Che-Theia image built for the happy-path test in any workspace including the Java plugin and try using snippets in any Java file.

PR Checklist

As the author of this Pull Request I made sure that:

Reviewers

Reviewers, please comment how you tested the PR when approving it.

Happy Path Channel

HAPPY_PATH_CHANNEL=next

@tsmaeder
Copy link
Contributor Author

tsmaeder commented Dec 9, 2020

[crw-ci-test --rebuild]

benoitf
benoitf previously requested changes Dec 9, 2020
export class PluginResourceResolver implements ResourceResolver {
resolve(uri: URI): MaybePromise<Resource> {
if (uri.scheme !== PluginUri.SCHEME) {
throw new Error('Not a plugin resource');
Copy link
Contributor

Choose a reason for hiding this comment

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

Provides the uri that is invalid ?

Copy link
Contributor Author

@tsmaeder tsmaeder Dec 9, 2020

Choose a reason for hiding this comment

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

True. Note that throwing an exception is just the way for the plugin resolver to indicate it cannot handle this scheme. The error is swallowed silently.

* front end.
*/
export namespace PluginUri {
export const SCHEME = 'pluginresource';
Copy link
Contributor

Choose a reason for hiding this comment

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

if it's specific to che, probably add che into the SCHEME (in case upstream provides pluginresource as well) to avoid any mismatch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not really specific to che: the plugin resources at /hostedPlugin/... are also available upstream.

Copy link
Contributor

Choose a reason for hiding this comment

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

it's tied to che because this protocol is not available upstream

result.push({
language: contribution.language,
source: pck.displayName || pck.name,
uri: PluginUri.createUri(getPluginId(pck), relativePath),
Copy link
Contributor

Choose a reason for hiding this comment

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

we should just simply make a SnippetContributionProviderURI or SnippetContributionProvider singleton upstream and then just overrides how we create URI downstream
Here there are too many overrides

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean, there are too many overrides? It's a single method. If we extract the various contribution providers upstream, we would logically have to to it for all kinds of contributions. That may or may not be desirable, but one of the reasons we're doing this downstream is that the work was deemed urgent.

Copy link
Contributor

@benoitf benoitf Dec 9, 2020

Choose a reason for hiding this comment

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

I mean here that there are too many classes being extended (and we may miss some of them)
while we're only interested on delegating the contribution uri.

That may or may not be desirable, but one of the reasons we're doing this downstream is that the work was deemed urgent.

eclipse-che/che#16502 is opened since march
I think that adding a new simple method in upstream theia to handle the contribution can be accepted in a couple of days as it's a very minor change.

Also we could just delegate the creation of URI for a plug-in (not tied to snippets) and use for upstream theia File protocol and for che: a custom provider.

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I understand it, this issue is not reproducible in upstream theia. In the interest of saving time, I suggest we keep the fix downstream: not only because the benefit for theia is low, but also because the holidays are coming and getting the PR merged on time is not guaranteed. We can always iterate later if the need for such methods in theia arises.

Copy link
Contributor

@benoitf benoitf Dec 10, 2020

Choose a reason for hiding this comment

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

I don't think it would be a problem to have something merge upstream if it's only an helper to get an URI for a plugin resource. Upstream theia having implementation with File and downstream with something else.
Discussing it is taking more time than having proposed a simple tiny PR url upstream.

Also I see two different ways being implemented for getting resources for a plug-in this one and #946 which is kind of colliding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I asked explicitly on a Theia dev call whether separation of plugin host and back end on different machines was something that should be supported in Theia and the answer was no. Hence the downstream effort instead of pursuing eclipse-theia/theia#8468

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And again, we can push for this refactoring upstream any time later, but we already have all the necessary parts to fix the issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's different. It's not to have a plug-in-resource: protocol upstream, just to have something than convert a plug-in path to an URI by using File and that can be replaced in Che (with protocols, etc)

Copy link
Contributor

@sunix sunix Feb 5, 2021

Choose a reason for hiding this comment

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

I agree with @benoitf. Here using inheritance and overrides could be quite hard to maintain in the future. It is overriding methods and copying some parts of upstream code. So if, somehow, in upstream, someone changes that line https://github.com/eclipse-theia/theia/blob/bd25d737742a0974b911da5d3a5c978d950fc64e/packages/monaco/src/browser/monaco-snippet-suggest-provider.ts#L146, it would not be reflected downstream and could cause bugs that are hard to track.

* The path is resolve relative to the directory designated by the
* plugins package path.
*/
export class PluginResource implements Resource {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be a ChePluginResource

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's not Che specific, even if it lives inside che-theia: same reasoning as above. I'm open to proposing a PR upstream with the plugin resource stuff.

Copy link
Contributor

Choose a reason for hiding this comment

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

if it's becoming an upstream yes it'll be a pluginResource else it'll be a Che plugin resource.
Proposing it upstream will be better if you want to stick to 'pluginResource'

Copy link
Contributor

Choose a reason for hiding this comment

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

But I think it's only useful upstream if this protocol is used somewhere

@tsmaeder
Copy link
Contributor Author

tsmaeder commented Dec 9, 2020

[crw-ci-test]

@che-bot
Copy link
Contributor

che-bot commented Dec 9, 2020

❌ E2E Happy path tests failed ❗

Try Che-Theia editor only Try Che-Theia with Java/maven example Try Che-Theia with NodeJs example

See Details

name link
che-theia docker.io/maxura/che-theia:948
che-theia-endpoint-runtime-binary docker.io/maxura/che-theia-endpoint-runtime-binary:948

Tested with Eclipse Che Single User on K8S (minikube v1.1.1)

  • Use comment "[crw-ci-test]" to rerun happy path E2E test.
  • Use comment "[crw-ci-test --rebuild]" to re-build the images and rerun happy path E2E test.

@dmytro-ndp
Copy link
Contributor

[crw-ci-test --rebuild]

@che-bot
Copy link
Contributor

che-bot commented Dec 9, 2020

❌ E2E Happy path tests failed ❗

Try Che-Theia editor only Try Che-Theia with Java/maven example Try Che-Theia with NodeJs example

See Details

name link
che-theia docker.io/maxura/che-theia:948
che-theia-endpoint-runtime-binary docker.io/maxura/che-theia-endpoint-runtime-binary:948

Tested with Eclipse Che Single User on K8S (minikube v1.1.1)

  • Use comment "[crw-ci-test]" to rerun happy path E2E test.
  • Use comment "[crw-ci-test --rebuild]" to re-build the images and rerun happy path E2E test.

@azatsarynnyy
Copy link
Member

[crw-ci-test --rebuild]

@che-bot
Copy link
Contributor

che-bot commented Dec 9, 2020

✅ E2E Happy path tests succeed 🎉

Try Che-Theia editor only Try Che-Theia with Java/maven example Try Che-Theia with NodeJs example

See Details

name link
che-theia docker.io/maxura/che-theia:948
che-theia-endpoint-runtime-binary docker.io/maxura/che-theia-endpoint-runtime-binary:948

Tested with Eclipse Che Single User on K8S (minikube v1.1.1)

  • Use comment "[crw-ci-test]" to rerun happy path E2E test.
  • Use comment "[crw-ci-test --rebuild]" to re-build the images and rerun happy path E2E test.

@dmytro-ndp
Copy link
Contributor

[crw-ci-test --rebuild]

@che-bot
Copy link
Contributor

che-bot commented Dec 11, 2020

✅ E2E Happy path tests succeed 🎉

Try Che-Theia editor only Try Che-Theia with Java/maven example Try Che-Theia with NodeJs example

See Details

name link
che-theia docker.io/maxura/che-theia:948
che-theia-endpoint-runtime-binary docker.io/maxura/che-theia-endpoint-runtime-binary:948

Tested with Eclipse Che Single User on K8S (minikube v1.1.1)

  • Use comment "[crw-ci-test]" to rerun happy path E2E test.
  • Use comment "[crw-ci-test --rebuild]" to re-build the images and rerun happy path E2E test.

@tsmaeder
Copy link
Contributor Author

tsmaeder commented Jan 7, 2021

I've tried using the sidecar file system to load snippet files, but that does not work because monaco tries to fetch the snippet files before the sidecar files system is registered.

@benoitf
Copy link
Contributor

benoitf commented Jan 8, 2021

@tsmaeder we can't register the filesystem earlier ?

@tsmaeder
Copy link
Contributor Author

tsmaeder commented Jan 8, 2021

@benoitf not easily: the file system is initialized when the plugin manager for a particular front-end is initialized. However, the initialization of connections to plugin hosts is done in parallel to opening the editor, it seems. I believe we would have to rework the lifecycle of plugin host connections. T.b.h, I think it would be beneficial to the project, but might introduce bugs and will delay startup.

@tsmaeder
Copy link
Contributor Author

@benoitf could we move forward with this PR? It works and your suggestion of introducing a SnippetContributionProviderURI will not work until we make the plugin host file system provider work earlier as I described, because the upstream still uses the file system to load the snippets.

@benoitf
Copy link
Contributor

benoitf commented Jan 20, 2021

will not work until we make the plugin host file system provider work earlier as I described, because the upstream still uses the file system to load the snippets.

as compromise, I'm fine to keep the logic of custom URI on Che-Theia, but not having to override multiple scanners / copy almost all content of upstream readSnippets

@tsmaeder
Copy link
Contributor Author

as compromise, I'm fine to keep the logic of custom URI on Che-Theia
@benoitf What do you mean by "logic of custom URI"? Do you mean using a resource instead of the file service to read the contents of 'snippets.json'? Or do you mean the generation of uri's from extension contributions like 'contributes.snippets'?

@benoitf
Copy link
Contributor

benoitf commented Jan 21, 2021

@tsmaeder to keep ChePluginResource and CheSnippetSuggestProvider, but remove the need of CheTheiaPluginScanner, CheVsCodePluginScanner by implementing upstream the delegation of readSnippet URI (SnippetContributionProviderURI)

@benoitf benoitf dismissed their stale review January 21, 2021 12:59

I'm ok to have it merge if during the upcoming sprint, SnippetContributionProviderURI is coming, and icing on the cake, we can remove ChepluginUri/chepluginresource and use an eager registration of filesystem provider

@ericwill ericwill requested a review from sunix February 3, 2021 15:42
@ericwill ericwill mentioned this pull request Feb 4, 2021
35 tasks
@che-bot
Copy link
Contributor

che-bot commented Feb 12, 2021

❌ E2E Happy path tests failed ❗

Try Che-Theia editor only Try Che-Theia with Java/maven example Try Che-Theia with NodeJs example

See Details

name link
che-theia docker.io/maxura/che-theia:948
che-theia-endpoint-runtime-binary docker.io/maxura/che-theia-endpoint-runtime-binary:948

Tested with Eclipse Che Single User on K8S (minikube v1.1.1)

  • Use comment "[crw-ci-test]" to rerun happy path E2E test.
  • Use comment "[crw-ci-test --rebuild]" to re-build the images and rerun happy path E2E test.

@che-bot
Copy link
Contributor

che-bot commented Feb 12, 2021

✅ E2E Happy path tests succeed 🎉

Try Che-Theia editor only Try Che-Theia with Java/maven example Try Che-Theia with NodeJs example

See Details

name link
che-theia docker.io/maxura/che-theia:948
che-theia-endpoint-runtime-binary docker.io/maxura/che-theia-endpoint-runtime-binary:948

Tested with Eclipse Che Single User on K8S (minikube v1.1.1)

  • Use comment "[crw-ci-test]" to rerun happy path E2E test.
  • Use comment "[crw-ci-test --rebuild]" to re-build the images and rerun happy path E2E test.

Copy link
Member

@azatsarynnyy azatsarynnyy left a comment

Choose a reason for hiding this comment

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

I tested the changes - snippets work well:

try

@benoitf benoitf self-requested a review February 18, 2021 15:40
@che-bot
Copy link
Contributor

che-bot commented Feb 18, 2021

❌ E2E Happy path tests failed ❗

Try Che-Theia editor only Try Che-Theia with Java/maven example Try Che-Theia with NodeJs example

See Details

name link
che-theia docker.io/maxura/che-theia:948
che-theia-endpoint-runtime-binary docker.io/maxura/che-theia-endpoint-runtime-binary:948

Tested with Eclipse Che Single User on K8S (minikube v1.1.1)

  • Use comment "[crw-ci-test]" to rerun happy path E2E test.
  • Use comment "[crw-ci-test --rebuild]" to re-build the images and rerun happy path E2E test.

@ericwill
Copy link
Contributor

If we want this in Che 7.26, we'll need to backport this PR and also fork theia at this commit and cherry pick the upstream fix onto our fork.

@che-bot
Copy link
Contributor

che-bot commented Feb 26, 2021

❌ E2E Happy path tests failed ❗

Try Che-Theia editor only Try Che-Theia with Java/maven example Try Che-Theia with NodeJs example

See Details

name link
che-theia quay.io/crw_pr/che-theia:948
che-theia-endpoint-runtime-binary quay.io/crw_pr/che-theia-endpoint-runtime-binary:948

Tested with Eclipse Che Single User on K8S (minikube v1.1.1)

  • Use comment "[crw-ci-test]" to rerun happy path E2E test.
  • Use comment "[crw-ci-test --rebuild]" to re-build the images and rerun happy path E2E test.

@che-bot
Copy link
Contributor

che-bot commented Mar 2, 2021

❌ E2E Happy path tests failed ❗

Try Che-Theia editor only Try Che-Theia with Java/maven example Try Che-Theia with NodeJs example

See Details

name link
che-theia quay.io/crw_pr/che-theia:948
che-theia-endpoint-runtime-binary quay.io/crw_pr/che-theia-endpoint-runtime-binary:948

Tested with Eclipse Che Single User on K8S (minikube v1.1.1)

  • Use comment "[crw-ci-test]" to rerun happy path E2E test.
  • Use comment "[crw-ci-test --rebuild]" to re-build the images and rerun happy path E2E test.

@che-bot
Copy link
Contributor

che-bot commented Mar 3, 2021

❌ E2E Happy path tests failed ❗

Try Che-Theia editor only Try Che-Theia with Java/maven example Try Che-Theia with NodeJs example

See Details

name link
che-theia quay.io/crw_pr/che-theia:948
che-theia-endpoint-runtime-binary quay.io/crw_pr/che-theia-endpoint-runtime-binary:948

Tested with Eclipse Che Single User on K8S (minikube v1.1.1)

  • Use comment "[crw-ci-test]" to rerun happy path E2E test.
  • Use comment "[crw-ci-test --rebuild]" to re-build the images and rerun happy path E2E test.

@tsmaeder
Copy link
Contributor Author

@azatsarynnyy @ericwill have another look, if you please. PR is considerably changed, so you should re-review

@che-bot
Copy link
Contributor

che-bot commented Mar 10, 2021

✅ E2E Happy path tests succeed 🎉

Try Che-Theia editor only Try Che-Theia with Java/maven example Try Che-Theia with NodeJs example

See Details

name link
che-theia quay.io/crw_pr/che-theia:948
che-theia-endpoint-runtime-binary quay.io/crw_pr/che-theia-endpoint-runtime-binary:948

Tested with Eclipse Che Single User on K8S (minikube v1.1.1)

  • Use comment "[crw-ci-test]" to rerun happy path E2E test.
  • Use comment "[crw-ci-test --rebuild]" to re-build the images and rerun happy path E2E test.

return;
}
}

requestPluginResourceStat(pluginId: string, resourcePath: string): Promise<Stat> {
Copy link
Contributor

Choose a reason for hiding this comment

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

for readability maybe it would be easier to flag it as async method (and use await instead of chaining promises)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used to like the async/await syntax, but t.b.h these days I find it makes following the control flow rather confusing, in particular when debugging. I tend to only use async/await where it really improves readability. Here it does not, IMO:

@che-bot
Copy link
Contributor

che-bot commented Mar 10, 2021

✅ E2E Happy path tests succeed 🎉

Try Che-Theia editor only Try Che-Theia with Java/maven example Try Che-Theia with NodeJs example

See Details

name link
che-theia quay.io/crw_pr/che-theia:948
che-theia-endpoint-runtime-binary quay.io/crw_pr/che-theia-endpoint-runtime-binary:948

Tested with Eclipse Che Single User on K8S (minikube v1.1.1)

  • Use comment "[crw-ci-test]" to rerun happy path E2E test.
  • Use comment "[crw-ci-test --rebuild]" to re-build the images and rerun happy path E2E test.

@benoitf
Copy link
Contributor

benoitf commented Mar 11, 2021

as it's a bugfix, would be nice to have unit tests

- [ ]:  Tests are covering the bugfix

all modules having now jest setup.

@tsmaeder
Copy link
Contributor Author

@benoitf since this is a bug that rises from the integration of multiple components (containers, even), I don't see an easy way to write a unit test that would be meaningful.
On a more general level, requiring regression tests for every bugfix does not yield sufficient quality gains to justify the expense in development time, IMO. Investing in reducing the complexity or our codebase and better manual testing possibilities would have a better return on investment. (That and making everyone use Che to develop Che).

Signed-off-by: Thomas Mäder <tmader@redhat.com>
Signed-off-by: Thomas Mäder <tmader@redhat.com>
Signed-off-by: Thomas Mäder <tmader@redhat.com>
Signed-off-by: Thomas Mäder <tmader@redhat.com>
Signed-off-by: Thomas Mäder <tmader@redhat.com>
Signed-off-by: Thomas Mäder <tmader@redhat.com>
Signed-off-by: Thomas Mäder <tmader@redhat.com>
@codecov
Copy link

codecov bot commented Mar 15, 2021

Codecov Report

Merging #948 (0f3faf1) into master (2628ea7) will decrease coverage by 0.28%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #948      +/-   ##
==========================================
- Coverage   21.07%   20.78%   -0.29%     
==========================================
  Files         298      302       +4     
  Lines       11090    11244     +154     
  Branches     1680     1706      +26     
==========================================
  Hits         2337     2337              
- Misses       8603     8756     +153     
- Partials      150      151       +1     
Impacted Files Coverage Δ
...lugin-remote/src/browser/che-plugin-file-system.ts 0.00% <0.00%> (ø)
...emote/src/browser/plugin-remote-frontend-module.ts 0.00% <0.00%> (ø)
...e-theia-plugin-remote/src/common/che-plugin-uri.ts 0.00% <0.00%> (ø)
...a-plugin-remote/src/node/che-plugin-uri-factory.ts 0.00% <0.00%> (ø)
...eia-plugin-remote/src/node/hosted-plugin-remote.ts 0.00% <0.00%> (ø)
...-theia-plugin-remote/src/node/internal-protocol.ts 0.00% <0.00%> (ø)
...-plugin-remote/src/node/plugin-reader-extension.ts 0.00% <0.00%> (ø)
...in-remote/src/node/plugin-remote-backend-module.ts 0.00% <0.00%> (ø)
...theia-plugin-remote/src/node/plugin-remote-init.ts 0.00% <0.00%> (ø)
...ia-plugin-remote/src/node/plugin-remote-mapping.ts 0.00% <0.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2628ea7...0f3faf1. Read the comment docs.

@che-bot
Copy link
Contributor

che-bot commented Mar 15, 2021

✅ E2E Happy path tests succeed 🎉

Try Che-Theia editor only Try Che-Theia with Java/maven example Try Che-Theia with NodeJs example

See Details

name link
che-theia quay.io/crw_pr/che-theia:948
che-theia-endpoint-runtime-binary quay.io/crw_pr/che-theia-endpoint-runtime-binary:948

Tested with Eclipse Che Single User on K8S (minikube v1.1.1)

  • Use comment "[crw-ci-test]" to rerun happy path E2E test.
  • Use comment "[crw-ci-test --rebuild]" to re-build the images and rerun happy path E2E test.

@tsmaeder tsmaeder merged commit 552f160 into eclipse-che:master Mar 16, 2021
@che-bot che-bot added this to the 7.28 milestone Mar 16, 2021
@l0rd l0rd added the new&noteworthy For new and/or noteworthy issues that deserve a blog post, new docs, or emphasis in release notes label Mar 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new&noteworthy For new and/or noteworthy issues that deserve a blog post, new docs, or emphasis in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants