context view

pull/3094/head
yann300 7 years ago
parent 8a6e7b0b25
commit 8ab82a8647
  1. 57
      src/app.js
  2. 56
      src/app/editor/contextView.js

@ -506,39 +506,26 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
var editor = self._components.editor // shortcut for the editor var editor = self._components.editor // shortcut for the editor
registry.put({api: editor, name: 'editor'}) registry.put({api: editor, name: 'editor'})
var config = self._api.config
var filesProviders = self._api.filesProviders
// ----------------- file manager ----------------------------
self._components.fileManager = new FileManager({
config: config,
editor: editor,
filesProviders: filesProviders,
compilerImport: self._components.compilerImport
})
var fileManager = self._components.fileManager
registry.put({api: fileManager, name: 'filemanager'})
// ---------------- ContextualListener ----------------------- // ---------------- ContextualListener -----------------------
this._components.contextualListener = new ContextualListener() this._components.contextualListener = new ContextualListener()
registry.put({api: this._components.contextualListener, name: 'contextualListener'})
// ---------------- ContextView ----------------------- // ---------------- ContextView -----------------------
this._components.contextView = new ContextView({ this._components.contextView = new ContextView()
contextualListener: this._components.contextualListener,
jumpTo: (position) => {
function jumpToLine (lineColumn) {
if (lineColumn.start && lineColumn.start.line && lineColumn.start.column) {
editor.gotoLine(lineColumn.start.line, lineColumn.end.column + 1)
}
}
if (compiler.lastCompilationResult && compiler.lastCompilationResult.data) {
var lineColumn = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult)
var filename = compiler.getSourceName(position.file)
// TODO: refactor with rendererAPI.errorClick
if (filename !== config.get('currentFile')) {
var provider = fileManager.fileProviderOf(filename)
if (provider) {
provider.exists(filename, (error, exist) => {
if (error) return console.log(error)
fileManager.switchFile(filename)
jumpToLine(lineColumn)
})
}
} else {
jumpToLine(lineColumn)
}
}
}
}, {
contextualListener: this._components.contextualListener.event
})
// ----------------- editor panel ---------------------- // ----------------- editor panel ----------------------
this._components.editorpanel = new EditorPanel({ this._components.editorpanel = new EditorPanel({
@ -572,18 +559,6 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
this.event = new EventManager() this.event = new EventManager()
var config = self._api.config
var filesProviders = self._api.filesProviders
self._components.fileManager = new FileManager({
config: config,
editor: editor,
filesProviders: filesProviders,
compilerImport: self._components.compilerImport
})
var fileManager = self._components.fileManager
registry.put({api: fileManager, name: 'filemanager'})
// Add files received from remote instance (i.e. another remix-ide) // Add files received from remote instance (i.e. another remix-ide)
function loadFiles (filesSet, fileProvider, callback) { function loadFiles (filesSet, fileProvider, callback) {
if (!fileProvider) fileProvider = 'browser' if (!fileProvider) fileProvider = 'browser'

@ -2,6 +2,7 @@
var yo = require('yo-yo') var yo = require('yo-yo')
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var SourceMappingDecoder = remixLib.SourceMappingDecoder var SourceMappingDecoder = remixLib.SourceMappingDecoder
var globalRegistry = require('../../global/registry')
var css = require('./styles/contextView-styles') var css = require('./styles/contextView-styles')
@ -13,15 +14,24 @@ var css = require('./styles/contextView-styles')
- rename declaration/references - rename declaration/references
*/ */
class ContextView { class ContextView {
constructor (api, event) { constructor (localRegistry) {
this._api = api const self = this
this._event = event self._components = {}
self._components.registry = localRegistry || globalRegistry
self._deps = {
contextualListener: self._components.registry.get('contextualListener').api,
editor: self._components.registry.get('editor').api,
compiler: self._components.registry.get('compiler').api,
offsetToLineColumnConverter: self._components.registry.get('offsetToLineColumnConverter').api,
config: self._components.registry.get('config').api,
fileManager: self._components.registry.get('filemanager').api
}
this._view this._view
this._nodes this._nodes
this._current this._current
this.sourceMappingDecoder = new SourceMappingDecoder() this.sourceMappingDecoder = new SourceMappingDecoder()
this.previousElement = null this.previousElement = null
event.contextualListener.register('contextChanged', nodes => { self._deps.contextualListener.event.register('contextChanged', nodes => {
this._nodes = nodes this._nodes = nodes
this.update() this.update()
}) })
@ -66,7 +76,7 @@ class ContextView {
if (isDefinition(last)) { if (isDefinition(last)) {
this._current = last this._current = last
} else { } else {
var target = this._api.contextualListener.declarationOf(last) var target = this._deps.contextualListener.declarationOf(last)
if (target) { if (target) {
this._current = target this._current = target
} else { } else {
@ -80,15 +90,41 @@ class ContextView {
return this.previousElement return this.previousElement
} }
_jumpToInternal (position) {
var self = this
function jumpToLine (lineColumn) {
if (lineColumn.start && lineColumn.start.line && lineColumn.start.column) {
self._deps.editor.gotoLine(lineColumn.start.line, lineColumn.end.column + 1)
}
}
if (self._deps.compiler.lastCompilationResult && self._deps.compiler.lastCompilationResult.data) {
var lineColumn = self._deps.offsetToLineColumnConverter.offsetToLineColumn(position, position.file, self._deps.compiler.lastCompilationResult)
var filename = self._deps.compiler.getSourceName(position.file)
// TODO: refactor with rendererAPI.errorClick
if (filename !== self._deps.config.get('currentFile')) {
var provider = self._deps.fileManager.fileProviderOf(filename)
if (provider) {
provider.exists(filename, (error, exist) => {
if (error) return console.log(error)
self._deps.fileManager.switchFile(filename)
jumpToLine(lineColumn)
})
}
} else {
jumpToLine(lineColumn)
}
}
}
_render (node, nodeAtCursorPosition) { _render (node, nodeAtCursorPosition) {
if (!node) return yo`<div></div>` if (!node) return yo`<div></div>`
var self = this var self = this
var references = this._api.contextualListener.referencesOf(node) var references = self._deps.contextualListener.referencesOf(node)
var type = (node.attributes && node.attributes.type) ? node.attributes.type : node.name var type = (node.attributes && node.attributes.type) ? node.attributes.type : node.name
references = `${references ? references.length : '0'} reference(s)` references = `${references ? references.length : '0'} reference(s)`
var ref = 0 var ref = 0
var nodes = self._api.contextualListener.getActiveHighlights() var nodes = self._deps.contextualListener.getActiveHighlights()
for (var k in nodes) { for (var k in nodes) {
if (nodeAtCursorPosition.id === nodes[k].nodeId) { if (nodeAtCursorPosition.id === nodes[k].nodeId) {
ref = k ref = k
@ -101,14 +137,14 @@ class ContextView {
e.target.dataset.action === 'next' ? ref++ : ref-- e.target.dataset.action === 'next' ? ref++ : ref--
if (ref < 0) ref = nodes.length - 1 if (ref < 0) ref = nodes.length - 1
if (ref >= nodes.length) ref = 0 if (ref >= nodes.length) ref = 0
self._api.jumpTo(nodes[ref].position) self._jumpToInternal(nodes[ref].position)
} }
function jumpTo () { function jumpTo () {
if (node && node.src) { if (node && node.src) {
var position = self.sourceMappingDecoder.decode(node.src) var position = self.sourceMappingDecoder.decode(node.src)
if (position) { if (position) {
self._api.jumpTo(position) self._jumpToInternal(position)
} }
} }
} }
@ -125,7 +161,7 @@ class ContextView {
function showGasEstimation () { function showGasEstimation () {
if (node.name === 'FunctionDefinition') { if (node.name === 'FunctionDefinition') {
var result = self._api.contextualListener.gasEstimation(node) var result = self._deps.contextualListener.gasEstimation(node)
var executionCost = 'Execution cost: ' + result.executionCost + ' gas' var executionCost = 'Execution cost: ' + result.executionCost + ' gas'
var codeDepositCost = 'Code deposit cost: ' + result.codeDepositCost + ' gas' var codeDepositCost = 'Code deposit cost: ' + result.codeDepositCost + ' gas'
var estimatedGas = result.codeDepositCost ? `${codeDepositCost}, ${executionCost}` : `${executionCost}` var estimatedGas = result.codeDepositCost ? `${codeDepositCost}, ${executionCost}` : `${executionCost}`

Loading…
Cancel
Save