Skip to content

Improve evaluate on hover feature. - #9821

Merged
Isidor Nikolic (isidorn) merged 5 commits into
microsoft:masterfrom
rajkumar42:master
Aug 25, 2016
Merged

Isidor Nikolic (isidorn) merged 5 commits into
microsoft:masterfrom
rajkumar42:master

Conversation

@rajkumar42

Copy link
Copy Markdown
Contributor

when session has support for 'supportsEvaluateForHovers', using regex to extract the
sub-expression of the hover and using it to evaluate.

@msftclas

Hi Rajkumar Janakiraman (@rajkumar42), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor (Rajkumar Janakiraman). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

@rajkumar42

Rajkumar Janakiraman (rajkumar42) commented Jul 26, 2016 •

Copy link
Copy Markdown
Contributor Author

Corrected: Stop gap fix for #4059
Gregg Miskelly (@gregg-miskelly) Wes Rupert (@wesrupert)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would suggest adding some comments indicating what this code is doing. Something like:

Line 121:
// If the debug adapter supports evaluation-based-hover, we need to try and guess what the expression under the mouse cursor is. Someday it might be nice if the language service could somehow provide this. But this code attempts to approximate the answer for a variety of languages. Some example supported expressions: myVar.prop, a.b.c.d, myVar?.prop, myVar->prop, MyClass::StaticProp, *myVar

Reg ex explanation
// Match any character except a set of characters which often break interesting sub-expressions

Line 124 comment:
// First find the full expression under the cursor

Line 135 comment:
// If there are non-word characters after the cursor, we want to truncate the expression then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks!! I've added the comments.

@rajkumar42

Copy link
Copy Markdown
Contributor Author

Andre Weinand (@weinand), Isidor Nikolic (@isidorn) can you please code review?

@isidorn

Copy link
Copy Markdown

We are currently in the endgame this week, thus assigning this to august and I will code review / potentially merge start of next week.

@isidorn

Isidor Nikolic (isidorn) commented Jul 28, 2016 •

Copy link
Copy Markdown

Did a quick glance over the code, will do a full review next week. Here's some suggestions:

  • Are you sure you are using supportEvaluateOnHover correctly. If I understand everything correctly the goal of this PR is to better find the expression that is being hovered over. That has nothing to do with the supportEvaluateOnHover flag. That flag just tells how to evaluate the expression, if true we will do the evaluate if not we will find it in the variables view. All the debuggers should benefit from your imporvement, not only those that supportEvaluateOnHover
  • Instead of writing lenghty documentation, just document the feature in this PR and just put a link to this PR as a comment
  • Do not specify variable types if they are automatically infered by TS, that is not our style
  • Please extract your logic into a seperate method so it is easier to read
  • Squash all your commits into one once done so it is easier to read
  • You seem to have branched of master when there was a build failure - please get latest from master so the build checks pass
  • It would be great if bug Hover is not appearing on a variable sometimes #9894 would also be fixed as part of this
  • DId you build vscode of your changes and test you do not break at least the following debug adapters:
    • node
    • c++

Thanks a lot for this PR!

@rajkumar42

Copy link
Copy Markdown
Contributor Author

Isidor Nikolic (@isidorn)

  • This is not a comprehensive fix. One regex for all languages won't work. My fix is a stop gap solution for C#/C++ and probably work for some languages as well. Ideally every debug extension can provide a parser based on their language service. We can discuss about the extensibility point in the issue VS Code provides odd hover expression to debug adapters if the expression has '.'s #4059
  • I have built and verified VSCode changes with C#/C++/node debuggers.

@rajkumar42

Copy link
Copy Markdown
Contributor Author

Jackson Davis (@jacdavis) can you take a quick look?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

does this ignore expressions that are split across lines? Do we care?

@wesrupert

Copy link
Copy Markdown

LGTM as a stop-gap, though I second Rajkumar's concerns about trying to handle this at the editor-level at all.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

doesn't this filter out template/generic types? For instance, in C++, an expression like this should be valid:
CSeafood::Swim where CSeafood is a template instance with template parameter Squid.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No need to specify RegExp, types are inffered by TypeScript

@isidorn

Isidor Nikolic (isidorn) commented Aug 2, 2016 •

Copy link
Copy Markdown

My biggest problem with the current approach is that it uses the flag supportsEvaluateForHovers to use a different strategy to find a word. This feels like a hack to me as the supportsEvaluateForHovers capability has nothing to do with the way a word is being matched.

It seems like we all have concerns on solving this on the editor level.
Due to that I propose that we somehow move more of this logic to the extension, so each adapter extension could reason about what is being hovered over - a good example is Haskel as Wes Rupert (@wesrupert) pointed out.
One idea would be that VSCode simply sends the line and column number of the cursor and the adapter would send back the data for the hover. Not sure how feasable this is.

Since Andre Weinand (@weinand) is on vacation this week I propose to wait for next week to get his feedback on this matter.

@rajkumar42

Copy link
Copy Markdown
Contributor Author

Agreed, making it an extension would make it robust. We can hold off till Andre Weinand (@weinand) gets back.

Say the expression under mouse hover is foo["bar"], debuggers which supportsEvaluateForHovers would actually evaluate to foo["bar"], but for the debuggers which don't it could only find and show foo from the stack. Hence the difference in finding the expression depending on supportsEvaluateForHovers feature. Sorry if hadn't made it clear before.

@rajkumar42

Copy link
Copy Markdown
Contributor Author

Isidor Nikolic (@isidorn) ping...

@weinand

Copy link
Copy Markdown
Contributor

Rajkumar Janakiraman (@rajkumar42) Isidor will be back in the office next week.

@rajkumar42

Copy link
Copy Markdown
Contributor Author

Andre Weinand (@weinand) we were actually waiting for your input.

@weinand

Copy link
Copy Markdown
Contributor

I agree with most what was said in this thread:

  • in the future a language service should be involved in preparing the arguments before they are passed to the debug adapter (supportsEvaluateForHovers: true) or used for the variable lookup in the frontend (supportsEvaluateForHovers: true).
  • since we do not yet have hover support for a language service, this PR should be considered as a temporary workaround. As such it should not introduce or require any new architecture, it should be kept minimal, and should reduce the risk by only being used when a C++/C# debug session is active.

The fact that the PR uses supportsEvaluateForHovers to determine what strategy to use seems to be a necessity if it wants to make use of the much more powerful capabilities of the eval based hover (as Rajkumar Janakiraman (@rajkumar42) has pointed out in his comment).

Having VS Code send the line and column information to the debug adapter as part of the evaluate request could help in some (simple) cases but in general it is difficult in the debug adapter to get access to the language service.

@rajkumar42

Copy link
Copy Markdown
Contributor Author

Andre Weinand (@weinand) I have merged the latest changes from vscode/master. 2 unit tests are failing - unrelated to my change. Can you give me guidance on what needs to done to merge the PR?

when session has support for 'supportsEvaluateForHovers', using regex to extract the
sub-expression of the hover and using it to evaluate.
And fixing a minor bug.
return this.domNode;
}

private getHoveredExpression(lineContent: string, range: Range) : Range {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please rename this to better represent what is specific about this method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Any suggestions?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

getExpressionBoundsUnderCursor?

@isidorn

Isidor Nikolic (isidorn) commented Aug 24, 2016 •

Copy link
Copy Markdown

Sorry for the slow reponse, I was on vacation.
I have added some minor comments to your commits. Can you please address them?

Did you try out your changes with node, c++ and c# debugging? We want to make sure everything works out fine.

Once both fo these things are done we can merge the PR in. Next week is our endgame, so in order to have this for the august release we would need to wrap this up until Monday.

@rajkumar42

Copy link
Copy Markdown
Contributor Author

Isidor Nikolic (@isidorn) addressed your comments.
Tested, however since it is a stop-gap solution there will be cases it wouldn't work even in C++/C#.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.003%) to 60.815% when pulling 07874b8 on rajkumar42:master into 194bb22 on Microsoft:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.003%) to 60.815% when pulling 2c35671 on rajkumar42:master into 194bb22 on Microsoft:master.

@isidorn
Isidor Nikolic (isidorn) merged commit 8cba263 into microsoft:master Aug 25, 2016
Isidor Nikolic (isidorn) pushed a commit that referenced this pull request Aug 25, 2016
@isidorn

Copy link
Copy Markdown

Looks good to me, merged! Thanks a lot 🍻
I just did some minor renames on top.

@rajkumar42

Copy link
Copy Markdown
Contributor Author

Thanks!!

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.

9 participants