Skip to content

Commit

Permalink
Ignoring HTML template chars { and }
Browse files Browse the repository at this point in the history
These are commonly used for HTML templating; see Handlebars, Angular
etc.

Fixes ycm-core/YouCompleteMe#2058
  • Loading branch information
Valloric committed Mar 21, 2016
1 parent adebce8 commit 0e6c4a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ycmd/identifier_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
# Spec: http://www.w3.org/TR/html5/syntax.html#tag-name-state
# But not quite since not everything we want to pull out is a tag name. We
# also want attribute names (and probably unquoted attribute values).
'html': re.compile( r"[a-zA-Z][^\s/>='\"]*", re.UNICODE ),
# And we also want to ignore common template chars like `}` and `{`.
'html': re.compile( r"[a-zA-Z][^\s/>='\"}{\.]*", re.UNICODE ),

# Spec: http://cran.r-project.org/doc/manuals/r-release/R-lang.pdf
# Section 10.3.2.
Expand Down
10 changes: 8 additions & 2 deletions ycmd/tests/identifier_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from nose.tools import eq_, ok_
from ycmd import identifier_utils as iu
from hamcrest import assert_that, has_item


def RemoveIdentifierFreeText_CppComments_test():
Expand Down Expand Up @@ -126,9 +127,14 @@ def ExtractIdentifiersFromText_Css_test():


def ExtractIdentifiersFromText_Html_test():
eq_( [ "foo", "goo-foo", "zoo", "bar", "aa", "z", "b@g" ],
eq_( [ "foo", "goo-foo", "zoo", "bar", "aa", "z", "b@g", "fo", "ba" ],
iu.ExtractIdentifiersFromText(
'<foo> <goo-foo zoo=bar aa="" z=\'\'/> b@g', "html" ) )
'<foo> <goo-foo zoo=bar aa="" z=\'\'/> b@g fo.ba', "html" ) )


def ExtractIdentifiersFromText_Html_TemplateChars_test():
assert_that( iu.ExtractIdentifiersFromText( '<foo>{{goo}}</foo>', 'html' ),
has_item( 'goo' ) )


def IsIdentifier_generic_test():
Expand Down

0 comments on commit 0e6c4a7

Please sign in to comment.