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: () => {
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
},

@ -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] })
}
}

Loading…
Cancel
Save