Skip to content

Commit

Permalink
Fix multiline comments and strings tests
Browse files Browse the repository at this point in the history
  • Loading branch information
micbou committed Sep 7, 2017
1 parent c0e5149 commit 5f09390
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 5 additions & 2 deletions ycmd/completers/all/identifier_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,13 @@ def _RemoveSmallCandidates( candidates, min_num_candidate_size_chars ):

def _GetCursorIdentifier( collect_from_comments_and_strings,
request_data ):
line = request_data[ 'line_value' ]
filepath = request_data[ 'filepath' ]
contents = request_data[ 'file_data' ][ filepath ][ 'contents' ]
filetype = request_data[ 'first_filetype' ]
if not collect_from_comments_and_strings:
line = identifier_utils.RemoveIdentifierFreeText( line, filetype )
contents = identifier_utils.RemoveIdentifierFreeText( contents, filetype )
contents_per_line = SplitLines( contents )
line = contents_per_line[ request_data[ 'line_num' ] - 1 ]
return identifier_utils.IdentifierAtIndex(
line,
request_data[ 'column_codepoint' ] - 1,
Expand Down
8 changes: 7 additions & 1 deletion ycmd/identifier_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from builtins import * # noqa

import re
from ycmd.utils import SplitLines

C_STYLE_COMMENT = "/\*(?:\n|.)*?\*/"
CPP_STYLE_COMMENT = "//.*?$"
Expand Down Expand Up @@ -170,8 +171,13 @@ def IdentifierRegexForFiletype( filetype ):
return FILETYPE_TO_IDENTIFIER_REGEX.get( filetype, DEFAULT_IDENTIFIER_REGEX )


def ReplaceWithEmptyLines( match ):
return '\n' * ( len( SplitLines( match.group( 0 ) ) ) - 1 )


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


def ExtractIdentifiersFromText( text, filetype = None ):
Expand Down

0 comments on commit 5f09390

Please sign in to comment.