From b75dd57a0978d6d90a6e703a6d5747eb02e884e5 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 2 Jul 2018 21:57:32 +0200 Subject: [PATCH] fix offsetToLineColumn --- src/app/debugger/debugger.js | 6 +++--- src/app/editor/contextView.js | 2 +- src/app/editor/contextualListener.js | 2 +- src/app/staticanalysis/staticAnalysisView.js | 5 ++++- src/lib/offsetToLineColumnConverter.js | 6 +++--- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/app/debugger/debugger.js b/src/app/debugger/debugger.js index 57a9ebaeed..8d3e39a764 100644 --- a/src/app/debugger/debugger.js +++ b/src/app/debugger/debugger.js @@ -36,7 +36,7 @@ function Debugger (id, sourceHighlighter, localRegistry) { this.isActive = false this.breakPointManager = new remixCore.code.BreakpointManager(this.debugger, (sourceLocation) => { - return self._deps.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, this._deps.compiler.lastCompilationResult.data) + return self._deps.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, this._deps.compiler.lastCompilationResult.source.sources) }) this.debugger.setBreakpointManager(this.breakPointManager) @@ -74,8 +74,8 @@ function Debugger (id, sourceHighlighter, localRegistry) { this.debugger.codeManager.event.register('changed', this, function (code, address, index) { if (self._deps.compiler.lastCompilationResult) { self.debugger.callTree.sourceLocationTracker.getSourceLocationFromInstructionIndex(address, index, self._deps.compiler.lastCompilationResult.data.contracts, function (error, rawLocation) { - if (!error) { - var lineColumnPos = self._deps.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, self._deps.compiler.lastCompilationResult) + if (!error && self._deps.compiler.lastCompilationResult && self._deps.compiler.lastCompilationResult.data) { + var lineColumnPos = self._deps.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, self._deps.compiler.lastCompilationResult.source.sources) self._components.sourceHighlighter.currentSourceLocation(lineColumnPos, rawLocation) } else { self._components.sourceHighlighter.currentSourceLocation(null) diff --git a/src/app/editor/contextView.js b/src/app/editor/contextView.js index c9200ed0b8..e4781f6b68 100644 --- a/src/app/editor/contextView.js +++ b/src/app/editor/contextView.js @@ -98,7 +98,7 @@ class ContextView { } } if (self._deps.compiler.lastCompilationResult && self._deps.compiler.lastCompilationResult.data) { - var lineColumn = self._deps.offsetToLineColumnConverter.offsetToLineColumn(position, position.file, self._deps.compiler.lastCompilationResult) + var lineColumn = self._deps.offsetToLineColumnConverter.offsetToLineColumn(position, position.file, self._deps.compiler.lastCompilationResult.source.sources) var filename = self._deps.compiler.getSourceName(position.file) // TODO: refactor with rendererAPI.errorClick if (filename !== self._deps.config.get('currentFile')) { diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index 103b0349d8..d55965fd49 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -114,7 +114,7 @@ class ContextualListener { _highlightInternal (position, node) { var self = this if (self._deps.compiler.lastCompilationResult && self._deps.compiler.lastCompilationResult.data) { - var lineColumn = self._deps.offsetToLineColumnConverter.offsetToLineColumn(position, position.file, self._deps.compiler.lastCompilationResult) + var lineColumn = self._deps.offsetToLineColumnConverter.offsetToLineColumn(position, position.file, self._deps.compiler.lastCompilationResult.source.sources) 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. diff --git a/src/app/staticanalysis/staticAnalysisView.js b/src/app/staticanalysis/staticAnalysisView.js index fb50a95080..ae68a79e73 100644 --- a/src/app/staticanalysis/staticAnalysisView.js +++ b/src/app/staticanalysis/staticAnalysisView.js @@ -20,6 +20,7 @@ function staticAnalysisView (localRegistry) { this.runner = new StaticAnalysisRunner() this.modulesView = renderModules(this.runner.modules()) this.lastCompilationResult = null + this.lastCompilationSource = null self._components = {} self._components.registry = localRegistry || globlalRegistry // dependencies @@ -31,9 +32,11 @@ function staticAnalysisView (localRegistry) { self._deps.compiler.event.register('compilationFinished', function (success, data, source) { self.lastCompilationResult = null + self.lastCompilationSource = null $('#staticanalysisresult').empty() if (success) { self.lastCompilationResult = data + self.lastCompilationSource = source if (self.view.querySelector('#autorunstaticanalysis').checked) { self.run() } @@ -94,7 +97,7 @@ staticAnalysisView.prototype.run = function () { start: parseInt(split[0]), length: parseInt(split[1]) } - location = self._deps.offsetToLineColumnConverter.offsetToLineColumn(location, file) + location = self._deps.offsetToLineColumnConverter.offsetToLineColumn(location, file, self.lastCompilationSource.sources) location = Object.keys(self.lastCompilationResult.contracts)[file] + ':' + (location.start.line + 1) + ':' + (location.start.column + 1) + ':' } warningCount++ diff --git a/src/lib/offsetToLineColumnConverter.js b/src/lib/offsetToLineColumnConverter.js index f31fa68977..2a73dfbe6f 100644 --- a/src/lib/offsetToLineColumnConverter.js +++ b/src/lib/offsetToLineColumnConverter.js @@ -10,10 +10,10 @@ function offsetToColumnConverter (compilerEvent) { }) } -offsetToColumnConverter.prototype.offsetToLineColumn = function (rawLocation, file, compilationResult) { +offsetToColumnConverter.prototype.offsetToLineColumn = function (rawLocation, file, sources) { if (!this.lineBreakPositionsByContent[file]) { - var filename = Object.keys(compilationResult.data.sources)[file] - this.lineBreakPositionsByContent[file] = this.sourceMappingDecoder.getLinebreakPositions(compilationResult.source.sources[filename].content) + var filename = Object.keys(sources)[file] + this.lineBreakPositionsByContent[file] = this.sourceMappingDecoder.getLinebreakPositions(sources[filename].content) } return this.sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, this.lineBreakPositionsByContent[file]) }