mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-01 07:40:22 -04:00
Improved hover debugger tokenization specificity to not extend past end of line.
This commit is contained in:
parent
f7bdb7e840
commit
bebe5a0620
1 changed files with 8 additions and 7 deletions
|
@ -33,17 +33,18 @@ module.exports = class DebugView extends View
|
|||
setVariableStates: (@variableStates) ->
|
||||
@update()
|
||||
|
||||
isIdentifier: (t) ->
|
||||
t and (t.type is 'identifier' or t.value is 'this' or @globals[t.value])
|
||||
|
||||
onMouseMove: (e) =>
|
||||
return if @destroyed
|
||||
pos = e.getDocumentPosition()
|
||||
endOfDoc = pos.row is @ace.getSession().getDocument().getLength() - 1
|
||||
it = new TokenIterator e.editor.session, pos.row, pos.column
|
||||
isIdentifier = (t) => t and (t.type is 'identifier' or t.value is 'this' or @globals[t.value])
|
||||
while it.getCurrentTokenRow() is pos.row and not isIdentifier(token = it.getCurrentToken())
|
||||
endOfLine = it.getCurrentToken()?.index is it.$rowTokens.length - 1
|
||||
while it.getCurrentTokenRow() is pos.row and not @isIdentifier(token = it.getCurrentToken())
|
||||
break if endOfLine or not token # Don't iterate beyond end or beginning of line
|
||||
it.stepBackward()
|
||||
break unless token
|
||||
break if endOfDoc # Don't iterate backward on last line, since we might be way below.
|
||||
if isIdentifier token
|
||||
if @isIdentifier token
|
||||
# This could be a property access, like "enemy.target.pos" or "this.spawnedRectangles".
|
||||
# We have to realize this and dig into the nesting of the objects.
|
||||
start = it.getCurrentTokenColumn()
|
||||
|
@ -53,7 +54,7 @@ module.exports = class DebugView extends View
|
|||
break unless it.getCurrentToken()?.value is "."
|
||||
it.stepBackward()
|
||||
token = null # If we're doing a complex access like this.getEnemies().length, then length isn't a valid var.
|
||||
break unless isIdentifier(prev = it.getCurrentToken())
|
||||
break unless @isIdentifier(prev = it.getCurrentToken())
|
||||
token = prev
|
||||
start = it.getCurrentTokenColumn()
|
||||
chain.unshift token.value
|
||||
|
|
Loading…
Add table
Reference in a new issue