Merge pull request #825 from ethereum/dynamicHighlight

Highlight content of sol dependencies
pull/1/head
yann300 7 years ago committed by GitHub
commit c84847b57a
  1. 15
      src/app.js
  2. 21
      src/app/editor/contextualListener.js

@ -394,25 +394,28 @@ function run () {
getCompilationResult: () => { getCompilationResult: () => {
return compiler.lastCompilationResult return compiler.lastCompilationResult
}, },
getCurrentFile: () => {
return config.get('currentFile')
},
highlight: (position, node) => { highlight: (position, node) => {
if (compiler.lastCompilationResult && compiler.lastCompilationResult.data && compiler.lastCompilationResult.data.sourceList[position.file] === config.get('currentFile')) { if (compiler.lastCompilationResult && compiler.lastCompilationResult.data) {
position = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult) var lineColumn = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult)
var css = 'highlightreference' var css = 'highlightreference'
if (node.children && node.children.length) { 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. // If node has children, highlight the entire line. if not, just highlight the current source position of the node.
css = 'highlightreferenceline' css = 'highlightreferenceline'
position = { lineColumn = {
start: { start: {
line: position.start.line, line: lineColumn.start.line,
column: 0 column: 0
}, },
end: { end: {
line: position.start.line + 1, line: lineColumn.start.line + 1,
column: 0 column: 0
} }
} }
} }
return editor.addMarker(position, config.get('currentFile'), css) return editor.addMarker(lineColumn, compiler.lastCompilationResult.data.sourceList[position.file], css)
} }
return null return null
}, },

@ -22,22 +22,27 @@ class ContextualListener {
} }
}) })
events.editor.register('sessionSwitched', () => { this._stopHighlighting() })
events.editor.register('contentChanged', () => { this._stopHighlighting() }) events.editor.register('contentChanged', () => { this._stopHighlighting() })
this.sourceMappingDecoder = new SourceMappingDecoder() this.sourceMappingDecoder = new SourceMappingDecoder()
this.astWalker = new AstWalker() this.astWalker = new AstWalker()
setInterval(() => { setInterval(() => {
this._highlightItems(api.getCursorPosition(), api.getCompilationResult()) this._highlightItems(api.getCursorPosition(), api.getCompilationResult(), api.getCurrentFile())
}, 1000) }, 1000)
} }
_highlightItems (cursorPosition, compilationResult) { _highlightItems (cursorPosition, compilationResult, file) {
if (this.currentPosition === cursorPosition) return if (this.currentPosition === cursorPosition) return
if (this.currentFile !== file) {
this.currentFile = file
this.currentPosition = cursorPosition
return
}
this._stopHighlighting() this._stopHighlighting()
this.currentPosition = cursorPosition this.currentPosition = cursorPosition
if (compilationResult && compilationResult.data && compilationResult.source) { this.currentFile = file
var nodes = this.sourceMappingDecoder.nodesAtPosition(null, cursorPosition, compilationResult.data.sources[compilationResult.source.target]) 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]) { if (nodes && nodes.length && nodes[nodes.length - 1]) {
this._highlightExpressions(nodes[nodes.length - 1], compilationResult) this._highlightExpressions(nodes[nodes.length - 1], compilationResult)
} }
@ -58,7 +63,9 @@ class ContextualListener {
self._index['FlatReferences'][node.id] = node self._index['FlatReferences'][node.id] = node
return true 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 position = this.sourceMappingDecoder.decode(node.src)
var eventId = this._api.highlight(position, node) var eventId = this._api.highlight(position, node)
if (eventId) { if (eventId) {
this._activeHighlights.push({ eventId, position, fileTarget: compilationResult.source.target }) this._activeHighlights.push({ eventId, position, fileTarget: compilationResult.data.sourceList[position.file] })
} }
} }

Loading…
Cancel
Save