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

[READY] Fix multiline comments and strings issues #831

Merged
merged 3 commits into from
Sep 9, 2017

Conversation

micbou
Copy link
Collaborator

@micbou micbou commented Sep 7, 2017

When collect_identifiers_from_comments_and_strings is 0, we are replacing comments and strings with empty strings before extracting the identifiers. If one of these comments or strings span multiple lines, the current line number line_num may become invalid and, in that case, the identifier completer will fail to add the previous identifier on the CurrentIdentifierFinished event:

ignore-comments-current-identifier-finished
As you can see, the test identifier is properly extracted before the comment but not after.

Another issue with multiline comments and strings is that, when adding an identifier under the cursor on the InsertLeave event, we only remove comments and strings on the current line. This is incorrect if the current line is in the middle of a multiline comment or string:

ignore-comments-insert-leave
The test identifier is extracted even though it's inside a comment.

For now, I am updating the tests to showcase both issues. I'll update the PR with the fixes once the builds failed.


This change is Reviewable

@micbou micbou changed the title [WIP] Fix multiline comments and strings issues [READY] Fix multiline comments and strings issues Sep 7, 2017
@micbou
Copy link
Collaborator Author

micbou commented Sep 7, 2017

Fix the tests by replacing comments and strings with empty lines instead of empty strings. Also, replace them on the whole content and not just the current line when adding an identifier under the cursor.


Reviewed 4 of 4 files at r1.
Review status: all files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

@micbou micbou force-pushed the replace-comments-strings-empty-lines branch from 5f09390 to 84df3e5 Compare September 7, 2017 02:50
@codecov-io
Copy link

codecov-io commented Sep 7, 2017

Codecov Report

Merging #831 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #831      +/-   ##
==========================================
+ Coverage   94.84%   94.84%   +<.01%     
==========================================
  Files          79       79              
  Lines        5390     5396       +6     
  Branches      169      169              
==========================================
+ Hits         5112     5118       +6     
  Misses        230      230              
  Partials       48       48

@puremourning
Copy link
Member

Reviewed 1 of 4 files at r1, 1 of 1 files at r2.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


ycmd/identifier_utils.py, line 179 at r2 (raw file):

def RemoveIdentifierFreeText( text, filetype = None ):
  return CommentAndStringRegexForFiletype( filetype ).sub(

What happens with something like this:

/* test */ realIdentifier

Does it kill realIdentifier?

Point is... does this over remove if the comment is not a whole-line comment?


Comments from Reviewable

@micbou
Copy link
Collaborator Author

micbou commented Sep 7, 2017

Reviewed 1 of 1 files at r2.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


ycmd/identifier_utils.py, line 179 at r2 (raw file):

Previously, puremourning (Ben Jackson) wrote…

What happens with something like this:

/* test */ realIdentifier

Does it kill realIdentifier?

Point is... does this over remove if the comment is not a whole-line comment?

No, /* test */ will be matched and ReplaceWithEmptyLines will return ``. See the RemoveIdentifierFreeText_CstyleComments test.


Comments from Reviewable

@Valloric
Copy link
Member

Valloric commented Sep 7, 2017

That's a fantastic RB description, thank you! Made it very easy to understand the problem.


Review status: all files reviewed at latest revision, 2 unresolved discussions.


ycmd/identifier_utils.py, line 174 at r2 (raw file):

def ReplaceWithEmptyLines( match ):

Maybe regex_match to emphasize it's the match object from re?


ycmd/identifier_utils.py, line 179 at r2 (raw file):

Previously, micbou wrote…

No, /* test */ will be matched and ReplaceWithEmptyLines will return ``. See the RemoveIdentifierFreeText_CstyleComments test.

Let's make sure we have a test for that though.


Comments from Reviewable

@micbou micbou force-pushed the replace-comments-strings-empty-lines branch 3 times, most recently from 1c875b7 to 6a02da8 Compare September 7, 2017 21:28
@micbou
Copy link
Collaborator Author

micbou commented Sep 7, 2017

Reviewed 1 of 1 files at r3, 1 of 1 files at r4, 1 of 1 files at r5.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


ycmd/identifier_utils.py, line 174 at r2 (raw file):

Previously, Valloric (Val Markovic) wrote…

Maybe regex_match to emphasize it's the match object from re?

Done.


ycmd/identifier_utils.py, line 179 at r2 (raw file):

Previously, Valloric (Val Markovic) wrote…

Let's make sure we have a test for that though.

Added a test for this case (identifier after a C-style comment).


Comments from Reviewable

@puremourning
Copy link
Member

Review status: all files reviewed at latest revision, 2 unresolved discussions.


ycmd/identifier_utils.py, line 179 at r2 (raw file):

Previously, micbou wrote…

Added a test for this case (identifier after a C-style comment).

Ah I think my mobile broke what I was trying to put. On reflecting on the code I'm pretty sure it is fine, but the example I meant was

/*
 */ anIdentifier

Like i said, I'm pretty sure it works,


Comments from Reviewable

@puremourning
Copy link
Member

:lgtm: assuming th case I mentioned works as expected. Thanks!


Review status: all files reviewed at latest revision, 2 unresolved discussions.


Comments from Reviewable

@micbou micbou force-pushed the replace-comments-strings-empty-lines branch from 6a02da8 to 74648f8 Compare September 7, 2017 23:25
@micbou
Copy link
Collaborator Author

micbou commented Sep 7, 2017

Reviewed 1 of 1 files at r6.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


ycmd/identifier_utils.py, line 179 at r2 (raw file):

Previously, puremourning (Ben Jackson) wrote…

Ah I think my mobile broke what I was trying to put. On reflecting on the code I'm pretty sure it is fine, but the example I meant was

/*
 */ anIdentifier

Like i said, I'm pretty sure it works,

Updated the test.


Comments from Reviewable

@Valloric
Copy link
Member

Valloric commented Sep 9, 2017

:lgtm:

Thanks for the PR!

@zzbot r=puremourning


Review status: all files reviewed at latest revision, 1 unresolved discussion.


Comments from Reviewable

@zzbot
Copy link
Contributor

zzbot commented Sep 9, 2017

📌 Commit 74648f8 has been approved by puremourning

@zzbot
Copy link
Contributor

zzbot commented Sep 9, 2017

⌛ Testing commit 74648f8 with merge 2e7a596...

zzbot added a commit that referenced this pull request Sep 9, 2017
…uremourning

[READY] Fix multiline comments and strings issues

When `collect_identifiers_from_comments_and_strings` is `0`, we are replacing comments and strings with empty strings before extracting the identifiers. If one of these comments or strings span multiple lines, the current line number `line_num` may become invalid and, in that case, the identifier completer will fail to add the previous identifier on the `CurrentIdentifierFinished` event:

![ignore-comments-current-identifier-finished](https://user-images.githubusercontent.com/10026824/30140028-dca4c58e-9371-11e7-9231-f8ef35130ed7.gif)
As you can see, the `test` identifier is properly extracted before the comment but not after.

Another issue with multiline comments and strings is that, when adding an identifier under the cursor on the `InsertLeave` event, we only remove comments and strings on the current line. This is incorrect if the current line is in the middle of a multiline comment or string:

![ignore-comments-insert-leave](https://user-images.githubusercontent.com/10026824/30140274-b8af9fee-9373-11e7-94ec-78cf00585c39.gif)
The `test` identifier is extracted even though it's inside a comment.

For now, I am updating the tests to showcase both issues. I'll update the PR with the fixes once the builds failed.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/ycmd/831)
<!-- Reviewable:end -->
@zzbot
Copy link
Contributor

zzbot commented Sep 9, 2017

💔 Test failed - status-travis

@zzbot
Copy link
Contributor

zzbot commented Sep 9, 2017

☀️ Test successful - status-travis
Approved by: puremourning
Pushing 2e7a596 to master...

@zzbot zzbot merged commit 74648f8 into ycm-core:master Sep 9, 2017
@micbou micbou deleted the replace-comments-strings-empty-lines branch September 9, 2017 20:44
zzbot added a commit to ycm-core/YouCompleteMe that referenced this pull request Sep 10, 2017
[READY] Update ycmd

This new version of ycmd includes the following changes:

 - PR ycm-core/ycmd#795: add option to make relative paths in flags from extra conf absolute;
 - PR ycm-core/ycmd#802: fix compilation on Haiku;
 - PR ycm-core/ycmd#804: add libclang detection on FreeBSD;
 - PR ycm-core/ycmd#808: write python used during build before installing completers;
 - PR ycm-core/ycmd#810: support unknown languages from tags;
 - PR ycm-core/ycmd#811: update Universal Ctags languages list;
 - PR ycm-core/ycmd#814: resolve symlinks in extra conf glob patterns;
 - PR ycm-core/ycmd#815: update JediHTTP;
 - PR ycm-core/ycmd#816: update Boost to 1.65.0;
 - PR ycm-core/ycmd#819: filter and sort candidates when query is empty;
 - PR ycm-core/ycmd#820: improve LLVM root path search for prebuilt binaries;
 - PR ycm-core/ycmd#822: inline critical utility functions;
 - PR ycm-core/ycmd#824: do not sort header paths in filename completer;
 - PR ycm-core/ycmd#825: implement partial sorting;
 - PR ycm-core/ycmd#830: add max_num_candidates option;
 - PR ycm-core/ycmd#831: fix multiline comments and strings issues;
 - PR ycm-core/ycmd#832: update Clang to 5.0.0.

The `g:ycm_max_num_candidates` and `g:ycm_max_num_identifier_candidates` options are added to the documentation.

The link to ycmd extra conf is updated.

Fixes #2562.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2768)
<!-- Reviewable:end -->
zzbot added a commit to ycm-core/YouCompleteMe that referenced this pull request Sep 10, 2017
[READY] Update ycmd

This new version of ycmd includes the following changes:

 - PR ycm-core/ycmd#795: add option to make relative paths in flags from extra conf absolute;
 - PR ycm-core/ycmd#802: fix compilation on Haiku;
 - PR ycm-core/ycmd#804: add libclang detection on FreeBSD;
 - PR ycm-core/ycmd#808: write python used during build before installing completers;
 - PR ycm-core/ycmd#810: support unknown languages from tags;
 - PR ycm-core/ycmd#811: update Universal Ctags languages list;
 - PR ycm-core/ycmd#814: resolve symlinks in extra conf glob patterns;
 - PR ycm-core/ycmd#815: update JediHTTP;
 - PR ycm-core/ycmd#816: update Boost to 1.65.0;
 - PR ycm-core/ycmd#819: filter and sort candidates when query is empty;
 - PR ycm-core/ycmd#820: improve LLVM root path search for prebuilt binaries;
 - PR ycm-core/ycmd#822: inline critical utility functions;
 - PR ycm-core/ycmd#824: do not sort header paths in filename completer;
 - PR ycm-core/ycmd#825: implement partial sorting;
 - PR ycm-core/ycmd#830: add max_num_candidates option;
 - PR ycm-core/ycmd#831: fix multiline comments and strings issues;
 - PR ycm-core/ycmd#832: update Clang to 5.0.0.

The `g:ycm_max_num_candidates` and `g:ycm_max_num_identifier_candidates` options are added to the documentation.

The link to ycmd extra conf is updated.

Fixes #2562.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2768)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants