Add detection of HTML/CSS/JS comments for entrypoints

This commit is contained in:
phoenixeliot 2016-07-28 14:24:43 -07:00
parent 592e57351c
commit dd66a8c252

View file

@ -905,17 +905,19 @@ module.exports = class SpellView extends CocoView
if @_singleLineCommentRegex if @_singleLineCommentRegex
@_singleLineCommentRegex.lastIndex = 0 @_singleLineCommentRegex.lastIndex = 0
return @_singleLineCommentRegex return @_singleLineCommentRegex
commentStart = commentStarts[@spell.language] or '//' if @spell.language is 'html'
@_singleLineCommentRegex = new RegExp "[ \t]*#{commentStart}[^\"'\n]*", 'g' commentStart = "#{commentStarts.html}|#{commentStarts.css}|#{commentStarts.javascript}"
else
commentStart = commentStarts[@spell.language] or '//'
@_singleLineCommentRegex = new RegExp "[ \t]*(#{commentStart})[^\"'\n]*"
@_singleLineCommentRegex @_singleLineCommentRegex
lineWithCodeRegex: -> singleLineCommentOnlyRegex: ->
if @_lineWithCodeRegex if @_singleLineCommentOnlyRegex
@_lineWithCodeRegex.lastIndex = 0 @_singleLineCommentOnlyRegex.lastIndex = 0
return @_lineWithCodeRegex return @_singleLineCommentOnlyRegex
commentStart = commentStarts[@spell.language] or '//' @_singleLineCommentOnlyRegex = new RegExp( '^' + @singleLineCommentRegex().source)
@_lineWithCodeRegex = new RegExp "^[ \t]*(?!( |]t|#{commentStart}))+", 'g' @_singleLineCommentOnlyRegex
@_lineWithCodeRegex
commentOutMyCode: -> commentOutMyCode: ->
prefix = if @spell.language is 'javascript' then 'return; ' else 'return ' prefix = if @spell.language is 'javascript' then 'return; ' else 'return '
@ -1113,7 +1115,7 @@ module.exports = class SpellView extends CocoView
session.removeGutterDecoration index, 'next-entry-point' session.removeGutterDecoration index, 'next-entry-point'
lineHasComment = @singleLineCommentRegex().test line lineHasComment = @singleLineCommentRegex().test line
lineHasCode = line.trim()[0] and not _.string.startsWith line.trim(), commentStart lineHasCode = line.trim()[0] and not @singleLineCommentOnlyRegex().test line
lineIsBlank = /^[ \t]*$/.test line lineIsBlank = /^[ \t]*$/.test line
lineHasExplicitMarker = line.indexOf('') isnt -1 lineHasExplicitMarker = line.indexOf('') isnt -1
@ -1283,6 +1285,7 @@ module.exports = class SpellView extends CocoView
@saveSpadeTimeout = null @saveSpadeTimeout = null
super() super()
# Note: These need to be double-escaped for insertion into regexes
commentStarts = commentStarts =
javascript: '//' javascript: '//'
python: '#' python: '#'
@ -1290,3 +1293,4 @@ commentStarts =
lua: '--' lua: '--'
java: '//' java: '//'
html: '<!--' html: '<!--'
css: '/\\*'