From 94a25953faccd26abcf3d9244a638286beb7a5b8 Mon Sep 17 00:00:00 2001 From: yann300 Date: Sun, 24 Sep 2017 17:02:17 +0200 Subject: [PATCH 01/18] add getCursorPosition fn to editor --- src/app/editor/editor.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/editor/editor.js b/src/app/editor/editor.js index b3950854d0..cc761f6aa3 100644 --- a/src/app/editor/editor.js +++ b/src/app/editor/editor.js @@ -126,6 +126,10 @@ function Editor (opts = {}) { return currentSession } + this.getCursorPosition = function () { + return editor.session.doc.positionToIndex(editor.getCursorPosition(), 0) + } + this.discard = function (path) { if (currentSession !== path) { delete sessions[path] From 281bee231972c8127bcf5117c25298aff6f60db8 Mon Sep 17 00:00:00 2001 From: yann300 Date: Sun, 24 Sep 2017 17:02:32 +0200 Subject: [PATCH 02/18] contextuallistener --- src/app/editor/contextualListener.js | 84 ++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/app/editor/contextualListener.js diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js new file mode 100644 index 0000000000..1f6bee23f9 --- /dev/null +++ b/src/app/editor/contextualListener.js @@ -0,0 +1,84 @@ +'use strict' +var SourceMappingDecoder = require('ethereum-remix').util.SourceMappingDecoder +var AstWalker = require('ethereum-remix').util.AstWalker + +class ContextualListener { + constructor (api, events) { + this._api = api + this._index = { + FunctionDefinition: {}, + FunctionCalls: {}, + FunctionCall: {} + } + this._events = [] + + events.compiler.register('compilationFinished', (success, data, source) => { + this._stopWarning() + if (success) { + this._buildIndex(data, source) + } else { + this._index = { + FunctionDefinition: {}, + FunctionCalls: {}, + FunctionCall: {} + } + } + }) + this.sourceMappingDecoder = new SourceMappingDecoder() + this.astWalker = new AstWalker() + setInterval(() => { + this._context(api.getCursorPosition(), api.getCompilationResult()) + }, 1000) + } + + _context (cursorPosition, compilationResult) { + if (this.currentPosition === cursorPosition) return + this._stopWarning() + this.currentPosition = cursorPosition + if (compilationResult && compilationResult.data && compilationResult.source) { + var nodes = this.sourceMappingDecoder.nodesAtCursorPosition(null, cursorPosition, compilationResult.data.sources[compilationResult.source.target]) + if (nodes && nodes['FunctionCall']) { + this._highlightFunctionCall(nodes['FunctionCall'], compilationResult) + } + } + } + + _buildIndex (compilationResult, source) { + if (compilationResult && compilationResult.sources) { + var self = this + var callback = {} + callback['*'] = function (node) { + if (node && node.name && self._index[node.name]) { + self._index[node.name][node.id] = node + if (node.name === 'FunctionCall' && node.children[0] && node.children[0].attributes) { + var declaration = node.children[0].attributes.referencedDeclaration + if (!self._index['FunctionCalls'][declaration]) self._index['FunctionCalls'][declaration] = [] + self._index['FunctionCalls'][declaration].push(node.id) + } + } + return true + } + this.astWalker.walk(compilationResult.sources[source.target].AST, callback) + } + } + + _highlightFunctionCall (node, compilationResult) { + if (node.name === 'FunctionCall' && node.children[0] && node.children[0].attributes) { + var calls = this._index['FunctionCalls'][node.children[0].attributes.referencedDeclaration] + for (var call in calls) { + var position = this.sourceMappingDecoder.decode(this._index['FunctionCall'][calls[call]].src) + var eventId = this._api.warnFoundCall(position) + this._events.push({ eventId, position, fileTarget: compilationResult.source.target }) + } + } + } + + _stopWarning () { + for (var event in this._events) { + this._api.stopFoundCall(this._events[event]) + } + this._events = [] + } +} + +module.exports = ContextualListener From bf278f68d18a09ed17fb26a8c0b505a3e9fc8a10 Mon Sep 17 00:00:00 2001 From: yann300 Date: Sun, 24 Sep 2017 17:02:46 +0200 Subject: [PATCH 03/18] use contextuallistener --- assets/css/browser-solidity.css | 7 +++++++ src/app.js | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/assets/css/browser-solidity.css b/assets/css/browser-solidity.css index 16f4cef9ed..395241ba5a 100644 --- a/assets/css/browser-solidity.css +++ b/assets/css/browser-solidity.css @@ -290,6 +290,13 @@ input[type="file"] { display: none; } +.highlightcall { + position:absolute; + z-index:20; + background-color: lightgrey; + opacity: 0.5 +} + .highlightcode { position:absolute; z-index:20; diff --git a/src/app.js b/src/app.js index c3b27b5bfc..282e8bb7b9 100644 --- a/src/app.js +++ b/src/app.js @@ -34,6 +34,7 @@ var TxLogger = require('./app/execution/txLogger') var EventsDecoder = require('./app/execution/eventsDecoder') var handleImports = require('./app/compiler/compiler-imports') var FileManager = require('./app/files/fileManager') +var ContextualListener = require('./app/editor/contextualListener') var styleGuide = remix.ui.styleGuide var styles = styleGuide() @@ -385,6 +386,25 @@ function run () { }) var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event) + // ---------------- ContextualListener ----------------------- + this._components.contextualListener = new ContextualListener({ + getCursorPosition: () => { + return this._components.editor.getCursorPosition() + }, + getCompilationResult: () => { + return compiler.lastCompilationResult + }, + warnFoundCall: (position) => { + position = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult) + return editor.addMarker(position, config.get('currentFile'), 'highlightcall') + }, + stopFoundCall: (event) => { + editor.removeMarker(event.eventId, event.fileTarget) + } + }, { + compiler: compiler.event + }) + // ----------------- Renderer ----------------- var rendererAPI = { error: (file, error) => { From 8736b27367283f11aecda0cd2adb0fcfa4b524be Mon Sep 17 00:00:00 2001 From: yann300 Date: Sun, 24 Sep 2017 17:02:59 +0200 Subject: [PATCH 04/18] fix standard --- src/app/editor/contextualListener.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index 1f6bee23f9..85250a4265 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -52,7 +52,7 @@ class ContextualListener { self._index[node.name][node.id] = node if (node.name === 'FunctionCall' && node.children[0] && node.children[0].attributes) { var declaration = node.children[0].attributes.referencedDeclaration - if (!self._index['FunctionCalls'][declaration]) self._index['FunctionCalls'][declaration] = [] + if (!self._index['FunctionCalls'][declaration]) self._index['FunctionCalls'][declaration] = [] self._index['FunctionCalls'][declaration].push(node.id) } } From 2f8900f41920ebe025362586c40800f84fd9f93e Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 25 Sep 2017 11:30:01 +0200 Subject: [PATCH 05/18] renaming --- src/app/editor/contextualListener.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index 85250a4265..445d714cfc 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -36,7 +36,7 @@ class ContextualListener { this._stopWarning() this.currentPosition = cursorPosition if (compilationResult && compilationResult.data && compilationResult.source) { - var nodes = this.sourceMappingDecoder.nodesAtCursorPosition(null, cursorPosition, compilationResult.data.sources[compilationResult.source.target]) + var nodes = this.sourceMappingDecoder.nodesAtPosition(null, cursorPosition, compilationResult.data.sources[compilationResult.source.target]) if (nodes && nodes['FunctionCall']) { this._highlightFunctionCall(nodes['FunctionCall'], compilationResult) } From cd33620fedb7b4b22f8bd5cb41e4fef1b13bc492 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 25 Sep 2017 13:50:01 +0200 Subject: [PATCH 06/18] - rename API - hightlight every expression that has a referenced declaration --- src/app.js | 4 +- src/app/editor/contextualListener.js | 58 ++++++++++++++++------------ 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/app.js b/src/app.js index 282e8bb7b9..54fde4fe44 100644 --- a/src/app.js +++ b/src/app.js @@ -394,11 +394,11 @@ function run () { getCompilationResult: () => { return compiler.lastCompilationResult }, - warnFoundCall: (position) => { + warnExpression: (position) => { position = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult) return editor.addMarker(position, config.get('currentFile'), 'highlightcall') }, - stopFoundCall: (event) => { + stopWarningExpression: (event) => { editor.removeMarker(event.eventId, event.fileTarget) } }, { diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index 445d714cfc..f3cbb5d09f 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -6,9 +6,8 @@ class ContextualListener { constructor (api, events) { this._api = api this._index = { - FunctionDefinition: {}, - FunctionCalls: {}, - FunctionCall: {} + ReferencedDeclarations: {}, + Expressions: [] } this._events = [] @@ -18,27 +17,26 @@ class ContextualListener { this._buildIndex(data, source) } else { this._index = { - FunctionDefinition: {}, - FunctionCalls: {}, - FunctionCall: {} + ReferencedDeclarations: {}, + Expressions: [] } } }) this.sourceMappingDecoder = new SourceMappingDecoder() this.astWalker = new AstWalker() setInterval(() => { - this._context(api.getCursorPosition(), api.getCompilationResult()) + this._warnExpressions(api.getCursorPosition(), api.getCompilationResult()) }, 1000) } - _context (cursorPosition, compilationResult) { + _warnExpressions (cursorPosition, compilationResult) { if (this.currentPosition === cursorPosition) return this._stopWarning() this.currentPosition = cursorPosition if (compilationResult && compilationResult.data && compilationResult.source) { var nodes = this.sourceMappingDecoder.nodesAtPosition(null, cursorPosition, compilationResult.data.sources[compilationResult.source.target]) - if (nodes && nodes['FunctionCall']) { - this._highlightFunctionCall(nodes['FunctionCall'], compilationResult) + if (nodes && nodes.length && nodes[nodes.length - 1]) { + this._warnExpression(nodes[nodes.length - 1], compilationResult) } } } @@ -48,13 +46,12 @@ class ContextualListener { var self = this var callback = {} callback['*'] = function (node) { - if (node && node.name && self._index[node.name]) { - self._index[node.name][node.id] = node - if (node.name === 'FunctionCall' && node.children[0] && node.children[0].attributes) { - var declaration = node.children[0].attributes.referencedDeclaration - if (!self._index['FunctionCalls'][declaration]) self._index['FunctionCalls'][declaration] = [] - self._index['FunctionCalls'][declaration].push(node.id) + if (node && node.attributes && node.attributes.referencedDeclaration) { + if (!self._index['ReferencedDeclarations'][node.attributes.referencedDeclaration]) { + self._index['ReferencedDeclarations'][node.attributes.referencedDeclaration] = [] } + self._index['ReferencedDeclarations'][node.attributes.referencedDeclaration].push(node) + self._index['Expressions'].push(node) } return true } @@ -62,20 +59,33 @@ class ContextualListener { } } - _highlightFunctionCall (node, compilationResult) { - if (node.name === 'FunctionCall' && node.children[0] && node.children[0].attributes) { - var calls = this._index['FunctionCalls'][node.children[0].attributes.referencedDeclaration] - for (var call in calls) { - var position = this.sourceMappingDecoder.decode(this._index['FunctionCall'][calls[call]].src) - var eventId = this._api.warnFoundCall(position) - this._events.push({ eventId, position, fileTarget: compilationResult.source.target }) + _warnExpression (node, compilationResult) { + var self = this + function highlight (id) { + if (self._index['ReferencedDeclarations'] && self._index['ReferencedDeclarations'][id]) { + var calls = self._index['ReferencedDeclarations'][id] + for (var call in calls) { + self._warn(calls[call].src, compilationResult) + } } } + + if (node.attributes && node.attributes.referencedDeclaration) { + highlight(node.attributes.referencedDeclaration) + } else { + highlight(node.id) + } + } + + _warn (src, compilationResult) { + var position = this.sourceMappingDecoder.decode(src) + var eventId = this._api.warnExpression(position) + this._events.push({ eventId, position, fileTarget: compilationResult.source.target }) } _stopWarning () { for (var event in this._events) { - this._api.stopFoundCall(this._events[event]) + this._api.stopWarningExpression(this._events[event]) } this._events = [] } From c27f828170fd6922daadf12b06a2db3bc5fe8549 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 25 Sep 2017 14:14:42 +0200 Subject: [PATCH 07/18] clear index --- src/app/editor/contextualListener.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index f3cbb5d09f..3ca293af71 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -13,13 +13,12 @@ class ContextualListener { events.compiler.register('compilationFinished', (success, data, source) => { this._stopWarning() + this._index = { + ReferencedDeclarations: {}, + Expressions: [] + } if (success) { this._buildIndex(data, source) - } else { - this._index = { - ReferencedDeclarations: {}, - Expressions: [] - } } }) this.sourceMappingDecoder = new SourceMappingDecoder() From 6a4c434c3ee11f190a78862469aff73089bdca5f Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 25 Sep 2017 16:41:29 +0200 Subject: [PATCH 08/18] renaming --- src/app.js | 4 +-- src/app/editor/contextualListener.js | 48 +++++++++++++--------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/app.js b/src/app.js index 54fde4fe44..5c53a7631e 100644 --- a/src/app.js +++ b/src/app.js @@ -394,11 +394,11 @@ function run () { getCompilationResult: () => { return compiler.lastCompilationResult }, - warnExpression: (position) => { + highlight: (position, node) => { position = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult) return editor.addMarker(position, config.get('currentFile'), 'highlightcall') }, - stopWarningExpression: (event) => { + stopHighlighting: (event) => { editor.removeMarker(event.eventId, event.fileTarget) } }, { diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index 3ca293af71..77f39eb458 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -6,16 +6,16 @@ class ContextualListener { constructor (api, events) { this._api = api this._index = { - ReferencedDeclarations: {}, - Expressions: [] + Declarations: {}, + References: [] } this._events = [] events.compiler.register('compilationFinished', (success, data, source) => { - this._stopWarning() + this._stopHighlighting() this._index = { - ReferencedDeclarations: {}, - Expressions: [] + Declarations: {}, + References: [] } if (success) { this._buildIndex(data, source) @@ -24,18 +24,18 @@ class ContextualListener { this.sourceMappingDecoder = new SourceMappingDecoder() this.astWalker = new AstWalker() setInterval(() => { - this._warnExpressions(api.getCursorPosition(), api.getCompilationResult()) + this._highlight(api.getCursorPosition(), api.getCompilationResult()) }, 1000) } - _warnExpressions (cursorPosition, compilationResult) { + _highlight (cursorPosition, compilationResult) { if (this.currentPosition === cursorPosition) return - this._stopWarning() + this._stopHighlighting() this.currentPosition = cursorPosition if (compilationResult && compilationResult.data && compilationResult.source) { var nodes = this.sourceMappingDecoder.nodesAtPosition(null, cursorPosition, compilationResult.data.sources[compilationResult.source.target]) if (nodes && nodes.length && nodes[nodes.length - 1]) { - this._warnExpression(nodes[nodes.length - 1], compilationResult) + this._hightlightExpressions(nodes[nodes.length - 1], compilationResult) } } } @@ -46,11 +46,11 @@ class ContextualListener { var callback = {} callback['*'] = function (node) { if (node && node.attributes && node.attributes.referencedDeclaration) { - if (!self._index['ReferencedDeclarations'][node.attributes.referencedDeclaration]) { - self._index['ReferencedDeclarations'][node.attributes.referencedDeclaration] = [] + if (!self._index['Declarations'][node.attributes.referencedDeclaration]) { + self._index['Declarations'][node.attributes.referencedDeclaration] = [] } - self._index['ReferencedDeclarations'][node.attributes.referencedDeclaration].push(node) - self._index['Expressions'].push(node) + self._index['Declarations'][node.attributes.referencedDeclaration].push(node) + self._index['References'].push(node) } return true } @@ -58,17 +58,19 @@ class ContextualListener { } } - _warnExpression (node, compilationResult) { + _hightlightExpressions (node, compilationResult) { var self = this function highlight (id) { - if (self._index['ReferencedDeclarations'] && self._index['ReferencedDeclarations'][id]) { - var calls = self._index['ReferencedDeclarations'][id] + if (self._index['Declarations'] && self._index['Declarations'][id]) { + var calls = self._index['Declarations'][id] for (var call in calls) { - self._warn(calls[call].src, compilationResult) + var node = calls[call] + var position = self.sourceMappingDecoder.decode(node.src) + var eventId = self._api.highlight(position, node) + self._events.push({ eventId, position, fileTarget: compilationResult.source.target }) } } } - if (node.attributes && node.attributes.referencedDeclaration) { highlight(node.attributes.referencedDeclaration) } else { @@ -76,15 +78,9 @@ class ContextualListener { } } - _warn (src, compilationResult) { - var position = this.sourceMappingDecoder.decode(src) - var eventId = this._api.warnExpression(position) - this._events.push({ eventId, position, fileTarget: compilationResult.source.target }) - } - - _stopWarning () { + _stopHighlighting () { for (var event in this._events) { - this._api.stopWarningExpression(this._events[event]) + this._api.stopHighlighting(this._events[event]) } this._events = [] } From 1aa49cc0032d666e17a9eae91549920a0e498e24 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 25 Sep 2017 16:46:53 +0200 Subject: [PATCH 09/18] make sure we hightlight the current file --- src/app.js | 7 +++++-- src/app/editor/contextualListener.js | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app.js b/src/app.js index 5c53a7631e..f87e9dd04c 100644 --- a/src/app.js +++ b/src/app.js @@ -395,8 +395,11 @@ function run () { return compiler.lastCompilationResult }, highlight: (position, node) => { - position = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult) - return editor.addMarker(position, config.get('currentFile'), 'highlightcall') + if (compiler.lastCompilationResult && compiler.lastCompilationResult.source && compiler.lastCompilationResult.source.target === config.get('currentFile')) { + position = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult) + return editor.addMarker(position, config.get('currentFile'), 'highlightcall') + } + return null }, stopHighlighting: (event) => { editor.removeMarker(event.eventId, event.fileTarget) diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index 77f39eb458..59bde1cff8 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -67,7 +67,9 @@ class ContextualListener { var node = calls[call] var position = self.sourceMappingDecoder.decode(node.src) var eventId = self._api.highlight(position, node) - self._events.push({ eventId, position, fileTarget: compilationResult.source.target }) + if (eventId) { + self._events.push({ eventId, position, fileTarget: compilationResult.source.target }) + } } } } From 6e83b2a46deba352bed2f4520279ea2ad28bda04 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 25 Sep 2017 17:33:45 +0200 Subject: [PATCH 10/18] - reset if edtior content changed - highlight also the declaration --- assets/css/browser-solidity.css | 18 ++++++++++++-- src/app.js | 7 +++--- src/app/editor/contextualListener.js | 36 ++++++++++++++++++---------- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/assets/css/browser-solidity.css b/assets/css/browser-solidity.css index 395241ba5a..4b9b9bf57d 100644 --- a/assets/css/browser-solidity.css +++ b/assets/css/browser-solidity.css @@ -290,11 +290,25 @@ input[type="file"] { display: none; } -.highlightcall { +.highlightreference { position:absolute; z-index:20; background-color: lightgrey; - opacity: 0.5 + opacity: 0.7 +} + +.highlightdeclaration{ + position:absolute; + z-index:20; + background-color: lightgrey; + opacity: 0.4 +} + +.highlightcurrent { + position:absolute; + z-index:20; + background-color: lightgrey; + opacity: 0.4 } .highlightcode { diff --git a/src/app.js b/src/app.js index f87e9dd04c..0ad38d1925 100644 --- a/src/app.js +++ b/src/app.js @@ -394,10 +394,10 @@ function run () { getCompilationResult: () => { return compiler.lastCompilationResult }, - highlight: (position, node) => { + highlight: (position, node, type) => { if (compiler.lastCompilationResult && compiler.lastCompilationResult.source && compiler.lastCompilationResult.source.target === config.get('currentFile')) { position = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult) - return editor.addMarker(position, config.get('currentFile'), 'highlightcall') + return editor.addMarker(position, config.get('currentFile'), 'highlight' + type) } return null }, @@ -405,7 +405,8 @@ function run () { editor.removeMarker(event.eventId, event.fileTarget) } }, { - compiler: compiler.event + compiler: compiler.event, + editor: editor.event }) // ----------------- Renderer ----------------- diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index 59bde1cff8..797085c4ba 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -7,7 +7,7 @@ class ContextualListener { this._api = api this._index = { Declarations: {}, - References: [] + FlatReferences: {} } this._events = [] @@ -15,20 +15,24 @@ class ContextualListener { this._stopHighlighting() this._index = { Declarations: {}, - References: [] + FlatReferences: {} } if (success) { this._buildIndex(data, source) } }) + + events.editor.register('sessionSwitched', () => { this._stopHighlighting() }) + events.editor.register('contentChanged', () => { this._stopHighlighting() }) + this.sourceMappingDecoder = new SourceMappingDecoder() this.astWalker = new AstWalker() setInterval(() => { - this._highlight(api.getCursorPosition(), api.getCompilationResult()) + this._highlightItems(api.getCursorPosition(), api.getCompilationResult()) }, 1000) } - _highlight (cursorPosition, compilationResult) { + _highlightItems (cursorPosition, compilationResult) { if (this.currentPosition === cursorPosition) return this._stopHighlighting() this.currentPosition = cursorPosition @@ -50,33 +54,39 @@ class ContextualListener { self._index['Declarations'][node.attributes.referencedDeclaration] = [] } self._index['Declarations'][node.attributes.referencedDeclaration].push(node) - self._index['References'].push(node) } + self._index['FlatReferences'][node.id] = node return true } this.astWalker.walk(compilationResult.sources[source.target].AST, callback) } } + _highlight (node, compilationResult, type) { + var position = this.sourceMappingDecoder.decode(node.src) + var eventId = this._api.highlight(position, node, type) + if (eventId) { + this._events.push({ eventId, position, fileTarget: compilationResult.source.target }) + } + } + _hightlightExpressions (node, compilationResult) { var self = this - function highlight (id) { + function highlights (id) { if (self._index['Declarations'] && self._index['Declarations'][id]) { var calls = self._index['Declarations'][id] for (var call in calls) { var node = calls[call] - var position = self.sourceMappingDecoder.decode(node.src) - var eventId = self._api.highlight(position, node) - if (eventId) { - self._events.push({ eventId, position, fileTarget: compilationResult.source.target }) - } + self._highlight(node, compilationResult, 'reference') } } } if (node.attributes && node.attributes.referencedDeclaration) { - highlight(node.attributes.referencedDeclaration) + highlights(node.attributes.referencedDeclaration) + var current = this._index['FlatReferences'][node.attributes.referencedDeclaration] + this._highlight(current, compilationResult, 'declaration') } else { - highlight(node.id) + highlights(node.id, 'current') } } From 8be16b1fa0ff4abdc09553c7097f23141b641dfe Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 25 Sep 2017 18:50:31 +0200 Subject: [PATCH 11/18] highlight entire line if contains children --- assets/css/browser-solidity.css | 14 -------------- src/app.js | 16 ++++++++++++++-- src/app/editor/contextualListener.js | 15 ++++++++------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/assets/css/browser-solidity.css b/assets/css/browser-solidity.css index 4b9b9bf57d..d3fc4edd20 100644 --- a/assets/css/browser-solidity.css +++ b/assets/css/browser-solidity.css @@ -297,20 +297,6 @@ input[type="file"] { opacity: 0.7 } -.highlightdeclaration{ - position:absolute; - z-index:20; - background-color: lightgrey; - opacity: 0.4 -} - -.highlightcurrent { - position:absolute; - z-index:20; - background-color: lightgrey; - opacity: 0.4 -} - .highlightcode { position:absolute; z-index:20; diff --git a/src/app.js b/src/app.js index 0ad38d1925..e4791e4501 100644 --- a/src/app.js +++ b/src/app.js @@ -394,10 +394,22 @@ function run () { getCompilationResult: () => { return compiler.lastCompilationResult }, - highlight: (position, node, type) => { + highlight: (position, node) => { if (compiler.lastCompilationResult && compiler.lastCompilationResult.source && compiler.lastCompilationResult.source.target === config.get('currentFile')) { position = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult) - return editor.addMarker(position, config.get('currentFile'), 'highlight' + type) + if (node.children && node.children.length) { + position = { + start: { + line: position.start.line, + column: 0 + }, + end: { + line: position.start.line + 1, + column: 0 + } + } + } + return editor.addMarker(position, config.get('currentFile'), 'highlightreference') } return null }, diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index 797085c4ba..48d23f98d0 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -62,9 +62,10 @@ class ContextualListener { } } - _highlight (node, compilationResult, type) { - var position = this.sourceMappingDecoder.decode(node.src) - var eventId = this._api.highlight(position, node, type) + _highlight (node, compilationResult) { + var src = node.src + var position = this.sourceMappingDecoder.decode(src) + var eventId = this._api.highlight(position, node) if (eventId) { this._events.push({ eventId, position, fileTarget: compilationResult.source.target }) } @@ -77,16 +78,16 @@ class ContextualListener { var calls = self._index['Declarations'][id] for (var call in calls) { var node = calls[call] - self._highlight(node, compilationResult, 'reference') + self._highlight(node, compilationResult) } } } if (node.attributes && node.attributes.referencedDeclaration) { highlights(node.attributes.referencedDeclaration) var current = this._index['FlatReferences'][node.attributes.referencedDeclaration] - this._highlight(current, compilationResult, 'declaration') - } else { - highlights(node.id, 'current') + this._highlight(current, compilationResult) + } else if (node && node.name && node.name !== 'FunctionDefinition' && node.name !== 'ContractDefinition' && node.name !== 'Block') { + highlights(node.id) } } From a44366b3c94f084e701af8b1a45389e5aba3c70e Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 25 Sep 2017 18:56:20 +0200 Subject: [PATCH 12/18] css change --- assets/css/browser-solidity.css | 7 +++++++ src/app.js | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/assets/css/browser-solidity.css b/assets/css/browser-solidity.css index d3fc4edd20..d72db57491 100644 --- a/assets/css/browser-solidity.css +++ b/assets/css/browser-solidity.css @@ -297,6 +297,13 @@ input[type="file"] { opacity: 0.7 } +.highlightreferenceline { + position:absolute; + z-index:20; + background-color: hsla(229, 75%, 87%, .5); /* lightBlue in style-guide.js*/ + opacity: 0.7 +} + .highlightcode { position:absolute; z-index:20; diff --git a/src/app.js b/src/app.js index e4791e4501..15022e8d22 100644 --- a/src/app.js +++ b/src/app.js @@ -397,7 +397,9 @@ function run () { highlight: (position, node) => { if (compiler.lastCompilationResult && compiler.lastCompilationResult.source && compiler.lastCompilationResult.source.target === config.get('currentFile')) { position = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult) + var css = 'highlightreference' if (node.children && node.children.length) { + css = 'highlightreferenceline' position = { start: { line: position.start.line, @@ -409,7 +411,7 @@ function run () { } } } - return editor.addMarker(position, config.get('currentFile'), 'highlightreference') + return editor.addMarker(position, config.get('currentFile'), css) } return null }, From 9c2755269f3696e02aa64df3fb77e508f004bc79 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 26 Sep 2017 12:10:05 +0200 Subject: [PATCH 13/18] check if position.file === current file --- src/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.js b/src/app.js index 15022e8d22..a3fa79807d 100644 --- a/src/app.js +++ b/src/app.js @@ -395,7 +395,7 @@ function run () { return compiler.lastCompilationResult }, highlight: (position, node) => { - if (compiler.lastCompilationResult && compiler.lastCompilationResult.source && compiler.lastCompilationResult.source.target === config.get('currentFile')) { + if (compiler.lastCompilationResult && compiler.lastCompilationResult.data && compiler.lastCompilationResult.data.sourceList[position.file] === config.get('currentFile')) { position = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult) var css = 'highlightreference' if (node.children && node.children.length) { From 9b3904525958f33365a9e2b07cdaebf5ee07c0d9 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 26 Sep 2017 12:10:14 +0200 Subject: [PATCH 14/18] add comment --- src/app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app.js b/src/app.js index a3fa79807d..f2a7915536 100644 --- a/src/app.js +++ b/src/app.js @@ -399,6 +399,7 @@ function run () { position = 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 = { start: { From 4383b4a24c28154a7448ab7bc252bf66ee439051 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 26 Sep 2017 12:10:20 +0200 Subject: [PATCH 15/18] renaming --- src/app/editor/contextualListener.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index 48d23f98d0..4c4bbf77e3 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -9,7 +9,7 @@ class ContextualListener { Declarations: {}, FlatReferences: {} } - this._events = [] + this._activeHighlights = [] events.compiler.register('compilationFinished', (success, data, source) => { this._stopHighlighting() @@ -67,7 +67,7 @@ class ContextualListener { var position = this.sourceMappingDecoder.decode(src) var eventId = this._api.highlight(position, node) if (eventId) { - this._events.push({ eventId, position, fileTarget: compilationResult.source.target }) + this._activeHighlights.push({ eventId, position, fileTarget: compilationResult.source.target }) } } @@ -86,16 +86,16 @@ class ContextualListener { highlights(node.attributes.referencedDeclaration) var current = this._index['FlatReferences'][node.attributes.referencedDeclaration] this._highlight(current, compilationResult) - } else if (node && node.name && node.name !== 'FunctionDefinition' && node.name !== 'ContractDefinition' && node.name !== 'Block') { + } else { highlights(node.id) } } _stopHighlighting () { - for (var event in this._events) { - this._api.stopHighlighting(this._events[event]) + for (var event in this._activeHighlights) { + this._api.stopHighlighting(this._activeHighlights[event]) } - this._events = [] + this._activeHighlights = [] } } From 1204776ae71f929cf9cf8504a907e66774cbb61f Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 26 Sep 2017 12:23:57 +0200 Subject: [PATCH 16/18] add check --- src/app/editor/contextualListener.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index 4c4bbf77e3..124919fecd 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -63,8 +63,8 @@ class ContextualListener { } _highlight (node, compilationResult) { - var src = node.src - var position = this.sourceMappingDecoder.decode(src) + if (!node) return + 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 }) From 7830667a1a3c3659e061d89c28b784d2a74c8253 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 26 Sep 2017 12:24:06 +0200 Subject: [PATCH 17/18] typo --- src/app/editor/contextualListener.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index 124919fecd..57bbff487b 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -39,7 +39,7 @@ class ContextualListener { if (compilationResult && compilationResult.data && compilationResult.source) { var nodes = this.sourceMappingDecoder.nodesAtPosition(null, cursorPosition, compilationResult.data.sources[compilationResult.source.target]) if (nodes && nodes.length && nodes[nodes.length - 1]) { - this._hightlightExpressions(nodes[nodes.length - 1], compilationResult) + this._highlightExpressions(nodes[nodes.length - 1], compilationResult) } } } @@ -71,7 +71,7 @@ class ContextualListener { } } - _hightlightExpressions (node, compilationResult) { + _highlightExpressions (node, compilationResult) { var self = this function highlights (id) { if (self._index['Declarations'] && self._index['Declarations'][id]) { From 4d86b8f093276712204634d9470812769da828b5 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 26 Sep 2017 12:24:46 +0200 Subject: [PATCH 18/18] renaming --- src/app/editor/contextualListener.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index 57bbff487b..f4991a8c70 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -75,9 +75,9 @@ class ContextualListener { var self = this function highlights (id) { if (self._index['Declarations'] && self._index['Declarations'][id]) { - var calls = self._index['Declarations'][id] - for (var call in calls) { - var node = calls[call] + var refs = self._index['Declarations'][id] + for (var ref in refs) { + var node = refs[ref] self._highlight(node, compilationResult) } }