Che: Java code snippets 'try_catch' and 'main' are not working

Created on 31 Mar 2020  Â·  21Comments  Â·  Source: eclipse/che

Describe the bug


In Java files, the code snippet (to generate try catch block) try_catch is not working

Che version

  • [x] latest

Steps to reproduce

  1. Start a Java workspace with a Java project (any of the getting started)
  2. Open a Java file
  3. type try and Ctrl+space inside a method

Expected behavior

Expected to have the try_catch like in VSCode:
Selection_694

But had no try_catch code snippet :(
Selection_695

Runtime

  • [x] Openshift 4.3 and che.openshift.io
arelanguages dogfooding kinbug severitP1

Most helpful comment

@PrasangAPrajapati no, that directory is random. And anyway...you'd have to copy it to the theia container somehow. I suggest waiting until we have the PR from @akosyakov merged and can fix it correctly. Hopefully some within 2 weeks.

All 21 comments

FWIW, this works in Theia master with the latest built-ins.

FWIW, this works in Theia master with the latest built-ins.

@sunix can you test?

FWIW, this works in Theia master with the latest built-ins.

is Theia using the Red Hat Java vscode ext ?

@sunix can you test?

No I don't have Theia installed locally. I let the assignee test with Theia if it is needed.

Hi David,

Plz check che doc for specific details and try to upgrade as appropriately
or built your own custom image if necessary.

On Wed, Apr 1, 2020, 16:28 Sun Seng David TAN notifications@github.com
wrote:

@sunix https://github.com/sunix can you test?

No I don't have Theia installed locally. I let the assignee test with
Theia if it is needed.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/eclipse/che/issues/16502#issuecomment-607140806, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AEYAMLZSMQ2JFIZWGY6IV7TRKMCMFANCNFSM4LXWXH3A
.

Sorry guys but it is impossible to code without a minimum of snippet ... main snippet is not working neither ....

I can confirm this bug as well.

Code snippets that were defined via the VSIX package.json contributes.snippets array appear in Theia, but not Eclipse Che. For example the Red Hat Java VSIX defines two set of snippets.

  • One that is just listed in package.json does not work.
  • The other set that gets loaded via a VS Code CompletionItemProvider implementation does appear.

Theia 1.0.0/1.2.0:
image

Che 7.13.1
image

Confirmed with vscode-java 0.62 in theia and vscode-java 0.63 in openshift.io.

The problem is that the package.json in vscode-java contributes snippets with a relative uri like so:

    "snippets": [
      {
        "language": "java",
        "path": "./snippets/java.json"
      }
    ],

The code in TheiaPluginScanner#readSnippets() constructs an URI from this like so:

uri: FileUri.create(path.join(pck.packagePath, contribution.path)).toString()

This file uri is supposed to refert to a location relative to where package.json of the vscode extension is located. This works fine when the package is installed in the same place as the Theia back end, but fails when the package is located in a sidecar container.

There are two ways we could fix this:

  1. Leave the URI as it is, but bring the files to the container where they are expected (where the Theia back end is running)
  2. Fix the generation of the URI: we already have a way of resolving sidecar-relative URI's.

My first aproach will be to fix the URI

@tsmaeder I like your approach to fix the URI. Will you make this fix and how soon? We can assist by verifying.

I'm working on it.

Turns out the monaco-snippet-suggest-provider.ts uses the FileSystem class directly, not a Resource. Since our workaround is based on resource, it does not get applied. I guess the right thing to do would be to implement file system providers for plugin resources after https://github.com/eclipse-theia/theia/pull/7908/files is merged

the snippets defined in package.json are only used until the Language Server has started. After that, they're disabled and server-side snippets should take over. See https://github.com/redhat-developer/vscode-java/pull/1101

@fbricon that may be, but the file referenced in package.json still isn't resolved properly. So are you saying the "try" snippet should work eventually? Because I'm not seeing that happening in che-theia.

Btw: thx for the hint: I can observe in the debugger that the file referenced in package.json is not properly resolved. So we _may_ be looking at two bugs, not one ;-)

There are two ways we could fix this:

  1. Leave the URI as it is, but bring the files to the container where they are expected (where the Theia back end is running)
  2. Fix the generation of the URI: we already have a way of resolving sidecar-relative URI's.

My first aproach will be to fix the URI

In the 1st option, would you have a suggestion to know how can we get the full path where file has to be in order to resolve it ? I can see extension folder name has some unique string attach in between which is new every time. How can we get that from a different (sidecar) container ? for example: ms-python.go.0.11.4.afbdfvxtsa.Go-0.11.4.vsix where you can see auto-generated afbdfvxtsa in middle.

@PrasangAPrajapati no, that directory is random. And anyway...you'd have to copy it to the theia container somehow. I suggest waiting until we have the PR from @akosyakov merged and can fix it correctly. Hopefully some within 2 weeks.

A naive approach based on registering a vscode FileSystemProvider upon connection of a front end fails because snippet files are read before activation of the Java plugin. We'll have to do something more involved.

if this issue is also concerning upstream Eclipse Theia, please file an issue in upstream theia and link it back there.

@benoitf We can test and do that. Thank you.

Was this page helpful?
0 / 5 - 0 ratings