Skip to content

Implemented fix for first parameter being a substring of the second p…#106432

Merged
mjbvz merged 7 commits intomicrosoft:masterfrom
tomerstav:signature-help-highlighting-wrong-param
Sep 18, 2020
Merged

Implemented fix for first parameter being a substring of the second p…#106432
mjbvz merged 7 commits intomicrosoft:masterfrom
tomerstav:signature-help-highlighting-wrong-param

Conversation

@tomerstav
Copy link
Copy Markdown
Contributor


Screen Shot 2020-09-10 at 6 15 57 PM

Problem was that 'param' was a substring of 'parameter'. Fixed it such that lookup in the signature label requires parameters to either end with a comma or bracket.

This PR fixes #106129

Copy link
Copy Markdown
Collaborator

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

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

@alexdima We allow extensions to return an index range for the parameter. This means that VS Code never has to compute the range itself from the text. I believe that is the approach we want to encourage

return param.label;
} else {
const idx = signature.label.lastIndexOf(param.label);
const idx = signature.label.lastIndexOf(`${param.label},`) ?? signature.label.lastIndexOf(`${param.label})`);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think the part after ?? will ever be executed since lastIndexOf always returns a number

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.

Yes that's correct. I have updated my PR. Also took into account these scenarios for idx. Note that I add one because lookup contains additional character at start.
//() -> 0
//(param) -> 1
//(param, xparam) -> 1
//(xparam,param) -> 8
//(xparam,param,yparam) -> 8
//(xparam, param,yparam) -> 9
//(xparam, param) -> 9
//(xparam,param) -> 9

@alexdima
Copy link
Copy Markdown
Member

@mjbvz I'm sorry I'm not familiar with this code

ping @joaomoreno

} else {
const idx = signature.label.lastIndexOf(param.label);
return idx >= 0
const idx = Math.max(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This fix seems specific to JavaScript style signatures. How about looking for the last match of a regular expression such as \b${param.label}\b which would check for the param label surrounded by word boundaries? Not perfect but that way param would not match parameter

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 for your feedback. Let me give that a shot

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.

Updated. Let me know what you think

Copy link
Copy Markdown
Collaborator

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

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

Looks good overall. Just one minor change and then I think we can merge this

return param.label;
} else {
const idx = signature.label.lastIndexOf(param.label);
const regex = new RegExp(`\\b${param.label}\\b`, 'g');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In case the param.label contains special regular expression, make sure to use escapeRegExpCharacters

@mjbvz mjbvz added this to the September 2020 milestone Sep 18, 2020
@mjbvz mjbvz merged commit 536ea46 into microsoft:master Sep 18, 2020
@mjbvz
Copy link
Copy Markdown
Collaborator

mjbvz commented Sep 18, 2020

Thanks! This will be in the next VS Code insiders build and is scheduled to ship with VS Code 1.50

@tomerstav tomerstav deleted the signature-help-highlighting-wrong-param branch September 18, 2020 22:55
@tomerstav
Copy link
Copy Markdown
Contributor Author

Thanks! This will be in the next VS Code insiders build and is scheduled to ship with VS Code 1.50

Awesome happy to help!

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.

Signature Help highlighting wrong parameter

3 participants