From 6c78ca562252866dc9dbeab6aa114f3de66e72be Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 26 Sep 2017 17:43:18 +0200 Subject: [PATCH] highlight also dependencies --- src/app.js | 15 +++++++++------ src/app/editor/contextualListener.js | 21 ++++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/app.js b/src/app.js index f2a7915536..c040471819 100644 --- a/src/app.js +++ b/src/app.js @@ -394,25 +394,28 @@ function run () { getCompilationResult: () => { return compiler.lastCompilationResult }, + getCurrentFile: () => { + return config.get('currentFile') + }, highlight: (position, node) => { - if (compiler.lastCompilationResult && compiler.lastCompilationResult.data && compiler.lastCompilationResult.data.sourceList[position.file] === config.get('currentFile')) { - position = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult) + if (compiler.lastCompilationResult && compiler.lastCompilationResult.data) { + var lineColumn = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult) var css = 'highlightreference' if (node.children && node.children.length) { // If node has children, highlight the entire line. if not, just highlight the current source position of the node. css = 'highlightreferenceline' - position = { + lineColumn = { start: { - line: position.start.line, + line: lineColumn.start.line, column: 0 }, end: { - line: position.start.line + 1, + line: lineColumn.start.line + 1, column: 0 } } } - return editor.addMarker(position, config.get('currentFile'), css) + return editor.addMarker(lineColumn, compiler.lastCompilationResult.data.sourceList[position.file], css) } return null }, diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index f4991a8c70..c38db693ef 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -22,22 +22,27 @@ class ContextualListener { } }) - events.editor.register('sessionSwitched', () => { this._stopHighlighting() }) events.editor.register('contentChanged', () => { this._stopHighlighting() }) this.sourceMappingDecoder = new SourceMappingDecoder() this.astWalker = new AstWalker() setInterval(() => { - this._highlightItems(api.getCursorPosition(), api.getCompilationResult()) + this._highlightItems(api.getCursorPosition(), api.getCompilationResult(), api.getCurrentFile()) }, 1000) } - _highlightItems (cursorPosition, compilationResult) { + _highlightItems (cursorPosition, compilationResult, file) { if (this.currentPosition === cursorPosition) return + if (this.currentFile !== file) { + this.currentFile = file + this.currentPosition = cursorPosition + return + } this._stopHighlighting() this.currentPosition = cursorPosition - if (compilationResult && compilationResult.data && compilationResult.source) { - var nodes = this.sourceMappingDecoder.nodesAtPosition(null, cursorPosition, compilationResult.data.sources[compilationResult.source.target]) + this.currentFile = file + if (compilationResult && compilationResult.data && compilationResult.data.sources[file]) { + var nodes = this.sourceMappingDecoder.nodesAtPosition(null, cursorPosition, compilationResult.data.sources[file]) if (nodes && nodes.length && nodes[nodes.length - 1]) { this._highlightExpressions(nodes[nodes.length - 1], compilationResult) } @@ -58,7 +63,9 @@ class ContextualListener { self._index['FlatReferences'][node.id] = node return true } - this.astWalker.walk(compilationResult.sources[source.target].AST, callback) + for (var s in compilationResult.sources) { + this.astWalker.walk(compilationResult.sources[s].AST, callback) + } } } @@ -67,7 +74,7 @@ class ContextualListener { var position = this.sourceMappingDecoder.decode(node.src) var eventId = this._api.highlight(position, node) if (eventId) { - this._activeHighlights.push({ eventId, position, fileTarget: compilationResult.source.target }) + this._activeHighlights.push({ eventId, position, fileTarget: compilationResult.data.sourceList[position.file] }) } }