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

Ensure method parameter tooltip/popup never occurs within strings or comments #2072

Merged
merged 8 commits into from
Jul 2, 2018

Conversation

d3r3kk
Copy link

@d3r3kk d3r3kk commented Jun 29, 2018

Fixes #2057

This pull request:

  • Has a title summarizes what is changing
  • Includes a news entry file (remember to thank yourself!)
  • Has unit tests & code coverage is not adversely affected (within reason)
  • Works on all actively maintained versions of Python (e.g. Python 2.7 & the latest Python 3 release)
  • Works on Windows 10, macOS, and Linux (e.g. considered file system case-sensitivity)

- issue microsoft#2057
- struggling with test framework & signature provider!
- incorporate Don's vscMock for SignatureHelp
- completely revert changes I'd made to completionSource tests
- create new 'pythonSignatureProvider' test suite
@d3r3kk d3r3kk added this to the Jul 2018 milestone Jun 29, 2018
@d3r3kk d3r3kk requested a review from DonJayamanne June 29, 2018 07:43
if (position.character <= 0) {
return undefined;
}
const filename = document.fileName;
Copy link
Author

Choose a reason for hiding this comment

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

Not entirely clear why this block was here? Perhaps I'm missing something...

This code would skip processing for any line that begins with "[whitespace]//" which I believe is invalid for Python.

Please let me know if I should put this back (maybe embedded C-code within a .py file?).

Choose a reason for hiding this comment

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

It is possible

x = \
"   //"

Copy link
Author

@d3r3kk d3r3kk Jun 29, 2018

Choose a reason for hiding this comment

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

Yeah, that's true. However, the test here is for a line like this:
// some important thing in a comment...
or this:
// some comment...
...which isn't what Python would hold, I am certain.
(and the quotation marks in your example would fail the test I removed)

Choose a reason for hiding this comment

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

// some important thing in a comment...

This is NOT a comment.

@@ -63,6 +63,7 @@ mockedVSCode.SnippetString = vscodeMocks.vscMockExtHostedTypes.SnippetString;
mockedVSCode.EventEmitter = vscodeMocks.vscMock.EventEmitter;
mockedVSCode.ConfigurationTarget = vscodeMocks.vscMockExtHostedTypes.ConfigurationTarget;
mockedVSCode.StatusBarAlignment = vscodeMocks.vscMockExtHostedTypes.StatusBarAlignment;
mockedVSCode.SignatureHelp = vscodeMocks.vscMockExtHostedTypes.SignatureHelp;
Copy link
Author

Choose a reason for hiding this comment

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

@DonJayamanne you rock so hard. I love that I was able to add this mock so easily.

@codecov
Copy link

codecov bot commented Jun 29, 2018

Codecov Report

Merging #2072 into master will decrease coverage by 0.1%.
The diff coverage is 93.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2072      +/-   ##
==========================================
- Coverage   79.89%   79.79%   -0.11%     
==========================================
  Files         307      307              
  Lines       14064    14083      +19     
  Branches     2494     2499       +5     
==========================================
  Hits        11237    11237              
- Misses       2815     2834      +19     
  Partials       12       12
Flag Coverage Δ
#MacOS 73.99% <93.33%> (-0.06%) ⬇️
#Windows 74.08% <93.33%> (-0.1%) ⬇️
Impacted Files Coverage Δ
src/client/providers/completionSource.ts 98.14% <100%> (+1.53%) ⬆️
src/client/providers/signatureProvider.ts 90% <100%> (+0.71%) ⬆️
src/client/providers/providerUtilities.ts 94.44% <87.5%> (-5.56%) ⬇️
src/client/activation/analysis.ts 25.86% <0%> (-2.35%) ⬇️
src/client/debugger/PythonProcess.ts 57.5% <0%> (-1.67%) ⬇️
src/client/common/types.ts 100% <0%> (ø) ⬆️
src/client/common/configSettings.ts 91.52% <0%> (+0.19%) ⬆️
...rc/client/debugger/PythonProcessCallbackHandler.ts 68.75% <0%> (+0.65%) ⬆️

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 d17f16f...c5c192e. Read the comment docs.

// In case position is at the every end of the comment or unterminated string
index = tokens.getItemContaining(offset - 1);
index = tokens.getItemContaining(offset - 2);
Copy link
Author

Choose a reason for hiding this comment

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

I am having difficulty understanding this one. The given comment is misleading a bit - the test only looks for tokens that are of type TokenType.Comment, but in Python I don't think there is an end to a comment (like there is in Cx languages) - isn't it just # -> everything to EOL for comments in Python? Or is there a special <# ... #> style syntax?

Choose a reason for hiding this comment

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

# is a single line comment token.
We use """ or ''' for multilines
Let me if that answers your question.
If that's ok, then I can approve this PR.

Copy link
Author

@d3r3kk d3r3kk Jun 29, 2018

Choose a reason for hiding this comment

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

Totally answers my question... so removing this block here was the right move I would think.

I'm actually writing a few more tests for the 'isInsideStringOrComment' at the moment, I'll see if those multi-line strings are handled properly or not.

...sorry - responded to the wrong thing. Blaming my tired brain.

Copy link

@DonJayamanne DonJayamanne left a comment

Choose a reason for hiding this comment

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

All ok,
Do remember, # is used only for single line comments.

// In case position is at the every end of the comment or unterminated string
index = tokens.getItemContaining(offset - 1);
index = tokens.getItemContaining(offset - 2);

Choose a reason for hiding this comment

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

# is a single line comment token.
We use """ or ''' for multilines
Let me if that answers your question.
If that's ok, then I can approve this PR.

if (position.character <= 0) {
return undefined;
}
const filename = document.fileName;

Choose a reason for hiding this comment

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

It is possible

x = \
"   //"

- determine whether or not cursors are in a string or comment
- previously expecting signatures within a string
- this no longer occurs
@d3r3kk
Copy link
Author

d3r3kk commented Jun 29, 2018

@DonJayamanne so based on the tests that were in place before I began this work, it appears that the signature was expected within a string. Was that the correct way for the extension to be? Or would the new behaviour (never showing function signatures within comments or strings, ever) be correct?

NOTE: I'm pefectly happy to abandon this work if that is the desired behaviour, I learned a ton about our test framework this week!

@d3r3kk d3r3kk merged commit c976b6c into microsoft:master Jul 2, 2018
@d3r3kk d3r3kk deleted the tooltip-in-string branch July 2, 2018 21:54
@lock lock bot locked as resolved and limited conversation to collaborators Jul 31, 2019
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.

Writing a comma in a string that is an argument to a function causes the pop up box to display
2 participants