Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to open classes from the DevUI in the IDE #15296

Merged
merged 2 commits into from
Mar 12, 2021

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Feb 24, 2021

TODO:

  • Add documentation (will do once the approach have been validated by the review - can be done in another PR)

@quarkus-bot quarkus-bot bot added area/arc Issue related to ARC (dependency injection) area/vertx labels Feb 24, 2021
@geoand
Copy link
Contributor Author

geoand commented Feb 24, 2021

This is what it currently looks like:

Screenshot from 2021-02-24 12-21-31

@geoand
Copy link
Contributor Author

geoand commented Feb 24, 2021

@stuartwdouglas @mkouba @maxandersen WDYT?

If you think this makes sense, I can proceed further

// TODO: determine whether IntelliJ or other IDE is being used determine the proper link

// for this to work, users need to check 'Allow unsigned requests' in the Debugger Settings
String link = "http://localhost:63342/api/file/" + srcMainJavaPath + '/'
Copy link
Contributor

Choose a reason for hiding this comment

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

So localhost:63342 is something IntelliJ-specific?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, IntelliJ starts a web server that handles a few API requests

@mkouba
Copy link
Contributor

mkouba commented Feb 24, 2021

I like the idea. Do you think we'd be able to support all the popular IDEs?

@geoand
Copy link
Contributor Author

geoand commented Feb 24, 2021

I like the idea. Do you think we'd be able to support all the popular IDEs?

I sure hope so 😃

// TODO: determine whether IntelliJ or other IDE is being used determine the proper link

// for this to work, users need to check 'Allow unsigned requests' in the Debugger Settings
String link = "http://localhost:63342/api/file/" + srcMainJavaPath + '/'
Copy link
Contributor

Choose a reason for hiding this comment

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

This is cool. You can also use Desktop.getDesktop().open(file) to invoke the preferred editor in the host machine

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 didn't know that, thanks!

That is probably going to be a good fallback if we can't determine what IDE is being used (which I hope we can)

@maxandersen
Copy link
Contributor

Good idea. It's only intellij that had this server thing atm.

Fyi: started https://github.com/starfixdev/starfix to handle this and other usecases more generically. Still poc though :)

But vscode has a URL we can use.

Eclipse can too - but not uniform across platfotms.

I'll take a look and see if can make it work.

@geoand
Copy link
Contributor Author

geoand commented Feb 24, 2021

Thanks for the info Max!

I had seen vscode has its own protocol for the URL so I wasn't worried about it.
For Eclipse, I had no idea.

I'll take a look at the code you linked soon and see what can be done

@stuartwdouglas
Copy link
Member

If we get this working can we also add it to the error page so we can open the class directly from the stack track?

@geoand
Copy link
Contributor Author

geoand commented Feb 25, 2021

If we get this working can we also add it to the error page so we can open the class directly from the stack track?

That's a superb idea

@maxandersen
Copy link
Contributor

okey, so looking in more detail I'm grokking this better. This approach is dependent on generating a link that gets generated into the webpage thus it will only work with IDE's that has url or link support.

Thus the only two IDE's I know that supports this well is intellij and vscode with its vscode:// url form.

The good thing is that this is also what starfix enables - it will register: ide:// and then relay to users IDE.

Thus we probably want a setting like:

quarkus.ide.kind=intellj|vscode|starfix

and then generate the appropriate url - possibly also allow "custom" and have a .ide.customurl property.

Another alternative could be we don't generate a link to a url but just a GET which then local devmode will use to execute code locally...but that has security implications if you share a url then remote users could be opening IDE's on your local machine ;)

@maxandersen
Copy link
Contributor

maxandersen commented Feb 25, 2021

Another aspect is to open at certain line number - that will also be different per IDE/URL.

@geoand
Copy link
Contributor Author

geoand commented Feb 25, 2021

Another aspect is to open at certain line number - that will also be different per IDE/URL.

Line numbers would take a lot more work to get - we'd need to actually get them from debugging info in the .class file.
(I don't think that Jandex stores this info currently) Jandex does not currently index the LineNumberTable attribute in bytecode, although we could certainly make it do so.

@geoand
Copy link
Contributor Author

geoand commented Feb 25, 2021

okey, so looking in more detail I'm grokking this better. This approach is dependent on generating a link that gets generated into the webpage thus it will only work with IDE's that has url or link support.

It doesn't have to be like this - I just did it to get some quick off the ground.
We can easily make the Quarkus process launch whatever needs to be launched in order to open the file in the IDE

@geoand
Copy link
Contributor Author

geoand commented Feb 27, 2021

okey, so looking in more detail I'm grokking this better. This approach is dependent on generating a link that gets generated into the webpage thus it will only work with IDE's that has url or link support.

It doesn't have to be like this - I just did it to get some quick off the ground.
We can easily make the Quarkus process launch whatever needs to be launched in order to open the file in the IDE

Looking at how Eclipse doesn't seem to have a way to do this, I am thinking that we will likely need to open the IDE from the "server-side", meaning that the link in the DevUI will be handled by a Vert.x Handler that will then do whatever is necessary to open the link in the IDE.

@gastaldi
Copy link
Contributor

@geoand my thought exactly 👍🏻

@maxandersen
Copy link
Contributor

i would not be too excited having this be something that we open server side for two reasons:

  1. ux flow - if you are serving out devmode to someone you want to demo something their clicks will result you seing your ~IDE pop up where it should have been the users ide
  2. when running remote dev, which side owns it?

something like starfix would fix it for eclipse btw.

@gastaldi
Copy link
Contributor

@maxandersen that makes sense, remote dev is a clear use case that invalidates a server side approach. It would be great if we could use Starfix here.
Is there anyone else (besides you) working on it? I may lend a hand if necessary.

@geoand
Copy link
Contributor Author

geoand commented Feb 27, 2021

If we can get this to work from a browser URL, then sure, that makes the most sense.

But startix is something a user would need to install, right?
I don't expect many people to install anything additional to be honest...
And even if we do expect them to, how does starfix solve the problem? Does it register a URL protocol handler with the Operating System?

As for the other cases, do we really think that dev Mode running on another machine is a thing?
For remote-dev, we could just disable the links.

The way I see it, both options have pros and cons.

@geoand
Copy link
Contributor Author

geoand commented Feb 27, 2021

Also to be clear, relying on starfix would make this PR relatively easy - it would just create starfix URLs

@gastaldi
Copy link
Contributor

image

@gastaldi
Copy link
Contributor

Yeah, jokes aside, maybe the best UX would be to enable links ONLY if Starfix is installed (as a chrome extension).

AFAIK there is a Jetbrains chrome extension that does that already: https://chrome.google.com/webstore/detail/jetbrains-toolbox-extensi/offnedcbhjldheanlbojaefbfbllddna

@geoand
Copy link
Contributor Author

geoand commented Feb 27, 2021

Yeah, we really need to decide what we want the user experience to be.

The technical work should be simple (as demonstrated in this PR)

@maxandersen
Copy link
Contributor

Is there anyone else (besides you) working on it? I may lend a hand if necessary.

no, and i havent spend much time since gsoc last year.
gsoc did verify though that it is very doable and got url protcol handler working for all three major ides.

Also to be clear, relying on starfix would make this PR relatively easy - it would just create starfix URLs

to start, i dont want to suggest to target starfix only. what im suggesting is that we make it url based to get resolved client side rather than handling it server side, at least by default.

we can do a detection in path to make a best guess for what will work, but have a property guiding it, like:

quarkus.ide.target=auto|vscode|idea|starfix

and then generate accordingly.

ultimately, we probably want to enable passing in not just physical location and line number but things like git url and classname as the location on disk might not match.

@maxandersen
Copy link
Contributor

then you would do something like

quarkus.ide.openurl=ide://openClass?git=$git&class=$class&line=$line&location=$location

for starfix, where as for vscode it would just refer to location and line.

@geoand
Copy link
Contributor Author

geoand commented Feb 28, 2021 via email

@maxandersen
Copy link
Contributor

Not at this stage no.

I've opened eclipse issues for it but not been picked up yet.

Maybe we could add a endpoint that Will launch Process locally given request comes from localhost to guard against at.least a direct exploit ?

@geoand
Copy link
Contributor Author

geoand commented Feb 28, 2021 via email

@geoand
Copy link
Contributor Author

geoand commented Mar 11, 2021

I would prefer writing docs after this PR is in as I have already had to rebase 3 times since yesterday alone.

@geoand
Copy link
Contributor Author

geoand commented Mar 11, 2021

The failures are totally unrelated

@maxandersen
Copy link
Contributor

I'll see if I can try it - where should I see the links be added ? In exceptions or just on arc bean Dev list?

@geoand
Copy link
Contributor Author

geoand commented Mar 11, 2021

Only in the Arc beans page.

But the plumbing is there to later on add it wherever we like

@geoand
Copy link
Contributor Author

geoand commented Mar 11, 2021

Unless there are objections, I'd like to merge this and not have to deal with any more conflicts (which are certain to arise)

@maxandersen
Copy link
Contributor

is there a reason why the links aren't copyable ?

// the idea here is to auto-detect the special files that IDEs create
// and also the running IDE process if need be

if (ideFile.getDetectedIDEs().size() == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A nice approach to know which of potential many ide files that should win is to sort them by last modification time. Right now it seems old idea filled would win over more recent code artifacts. For example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, but it still doesn't help us determine Eclipse vs VSCode - which is why this whole dance is necessary.

Copy link
Member

Choose a reason for hiding this comment

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

This detects runtime IDEs, but doesn't even copy their path, so it also doesn't look at executable modification date, which was my issue, because my IDE was not in my path. I figured this could be a further improvement.

Even then, if you decide to do this, watch out that often executables are links and I'm not sure their modification dates can be trusted without resolving the link.

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 am absolutely sure there will be improvements to be done in this area

@ConfigItem(defaultValue = "auto")
public Target target;

enum Target {
Copy link
Contributor

Choose a reason for hiding this comment

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

any way for us to allow user to specify a custom command ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not yet

} else {
List<Ide> matches = new ArrayList<>();
for (Ide file : ideFile.getDetectedIDEs()) {
for (Ide process : runningIdes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

oh wow - just realized you detecting running ides ....thats awesome :)

Copy link
Contributor

Choose a reason for hiding this comment

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

one caveat - this requires the IDE to be running when we start quarkus:dev, right?

also - while testing this having no IDE running i stopped getting links highlighted since no changes made and thus we never relooked for running processes ?

feels a bit weird.

Copy link
Contributor

Choose a reason for hiding this comment

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

and changing code to try trigger recalculation of running ides does not seem to be enough.

Copy link
Member

Choose a reason for hiding this comment

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

People close their IDE?

Copy link
Contributor

Choose a reason for hiding this comment

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

I do constantly :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The IDE detection is necessary because there from the project files we can't really diferentiate if VSCode is Eclipse is being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there is another way to differentiate an Eclise project from a VSCode project, then I'll gladly use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rigger recalculation of runni

When the changes result in a Quarkus dev restart, the processes are re-detected.

Copy link
Contributor

Choose a reason for hiding this comment

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

Weird - it stopped showing links for me :/

import io.quarkus.runtime.annotations.ConfigRoot;

@ConfigRoot
public class IdeConfig {
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure whre the bug is but using dev config editor it makesthis "quarkus.ide.target=code' which gives an error.

also i believe the current property is "quarkus.ide" which i think is limiting our options.

i would suggest "quarkus.ide.command" or similar allowing us to do i.e

quarkus.ide.command=custom
quarukus.ide.custom.command=open -a /Applications/Eclipse.app {filename}"

or similar in the future.

Copy link
Contributor

@maxandersen maxandersen left a comment

Choose a reason for hiding this comment

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

i really like where this is going but for some reason it stops working for me eventually. no linking happens.worked fine the first time.

but that is probably something we can fix in future update.

the only thing i would say to reconsider is to not use toplevel quarkus.ide property name space as the single value to set.

@geoand
Copy link
Contributor Author

geoand commented Mar 12, 2021

@maxandersen I don't see what the problem with the ide config is. Currently you set quarkus.ide.target to set an IDE from the enum values.
We could certainly add an optional command option later.
Am I missing something?

@geoand
Copy link
Contributor Author

geoand commented Mar 12, 2021

is there a reason why the links aren't copyable ?

The aren't actual links in the HTML sense. They are just spans that are clickable and what happens when you click on them is done in Javascript (in order to make it trivial for extensions to be able to use those functions and not have to worry about any of the internals of opening in the IDE)

@geoand geoand requested a review from maxandersen March 12, 2021 06:14
@maxandersen
Copy link
Contributor

@maxandersen I don't see what the problem with the ide config is. Currently you set quarkus.ide.target to set an IDE from the enum values.

We could certainly add an optional command option later.

Am I missing something?

Hmm Okey then I misread the code - what I got was that when I set .target I got an exception.

@geoand
Copy link
Contributor Author

geoand commented Mar 12, 2021

Hmm Okey then I misread the code - what I got was that when I set .target I got an exception.

Let me try it and see.

@geoand
Copy link
Contributor Author

geoand commented Mar 12, 2021

Hmm Okey then I misread the code - what I got was that when I set .target I got an exception.

Let me try it and see.

I just tried it and when I set vscode as the value of quarkus.ide.target, everything works as expected.
I tried both application.properties and setting the value from the Config UI.

@geoand
Copy link
Contributor Author

geoand commented Mar 12, 2021

@maxandersen and I discussed and agreed to get this in now and start using it. Any shortcomings or alternatives approaches can certainly be taken up as we get more hands on experience with DevUI entries using this feature.

@phillip-kruger would you be willing to integrate this with the Log output to allow users to open classes from exception stacktraces?

@phillip-kruger
Copy link
Member

@geoand - yes, happy to help. As a separate PR though right ?

@geoand
Copy link
Contributor Author

geoand commented Mar 12, 2021

Thanks!

Definitely a separate PR. I'll merge this once CI completes

@geoand geoand dismissed maxandersen’s stale review March 12, 2021 09:00

Comments addressed

@geoand geoand merged commit f1bbb73 into quarkusio:master Mar 12, 2021
@quarkus-bot quarkus-bot bot added this to the 1.13 - master milestone Mar 12, 2021
@geoand geoand deleted the open-in-ide branch March 12, 2021 09:00
@phillip-kruger
Copy link
Member

@geoand - #15761

^^^ PR to add this to the log ^^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) area/core area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/maven area/vertx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants