Commit 6e83b2a4 authored by yann300's avatar yann300

- reset if edtior content changed

- highlight also the declaration
parent 1aa49cc0
...@@ -290,11 +290,25 @@ input[type="file"] { ...@@ -290,11 +290,25 @@ input[type="file"] {
display: none; display: none;
} }
.highlightcall { .highlightreference {
position:absolute; position:absolute;
z-index:20; z-index:20;
background-color: lightgrey; 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 { .highlightcode {
......
...@@ -394,10 +394,10 @@ function run () { ...@@ -394,10 +394,10 @@ function run () {
getCompilationResult: () => { getCompilationResult: () => {
return compiler.lastCompilationResult return compiler.lastCompilationResult
}, },
highlight: (position, node) => { highlight: (position, node, type) => {
if (compiler.lastCompilationResult && compiler.lastCompilationResult.source && compiler.lastCompilationResult.source.target === config.get('currentFile')) { if (compiler.lastCompilationResult && compiler.lastCompilationResult.source && compiler.lastCompilationResult.source.target === config.get('currentFile')) {
position = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult) 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 return null
}, },
...@@ -405,7 +405,8 @@ function run () { ...@@ -405,7 +405,8 @@ function run () {
editor.removeMarker(event.eventId, event.fileTarget) editor.removeMarker(event.eventId, event.fileTarget)
} }
}, { }, {
compiler: compiler.event compiler: compiler.event,
editor: editor.event
}) })
// ----------------- Renderer ----------------- // ----------------- Renderer -----------------
......
...@@ -7,7 +7,7 @@ class ContextualListener { ...@@ -7,7 +7,7 @@ class ContextualListener {
this._api = api this._api = api
this._index = { this._index = {
Declarations: {}, Declarations: {},
References: [] FlatReferences: {}
} }
this._events = [] this._events = []
...@@ -15,20 +15,24 @@ class ContextualListener { ...@@ -15,20 +15,24 @@ class ContextualListener {
this._stopHighlighting() this._stopHighlighting()
this._index = { this._index = {
Declarations: {}, Declarations: {},
References: [] FlatReferences: {}
} }
if (success) { if (success) {
this._buildIndex(data, source) this._buildIndex(data, source)
} }
}) })
events.editor.register('sessionSwitched', () => { 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._highlight(api.getCursorPosition(), api.getCompilationResult()) this._highlightItems(api.getCursorPosition(), api.getCompilationResult())
}, 1000) }, 1000)
} }
_highlight (cursorPosition, compilationResult) { _highlightItems (cursorPosition, compilationResult) {
if (this.currentPosition === cursorPosition) return if (this.currentPosition === cursorPosition) return
this._stopHighlighting() this._stopHighlighting()
this.currentPosition = cursorPosition this.currentPosition = cursorPosition
...@@ -50,33 +54,39 @@ class ContextualListener { ...@@ -50,33 +54,39 @@ class ContextualListener {
self._index['Declarations'][node.attributes.referencedDeclaration] = [] self._index['Declarations'][node.attributes.referencedDeclaration] = []
} }
self._index['Declarations'][node.attributes.referencedDeclaration].push(node) self._index['Declarations'][node.attributes.referencedDeclaration].push(node)
self._index['References'].push(node)
} }
self._index['FlatReferences'][node.id] = node
return true return true
} }
this.astWalker.walk(compilationResult.sources[source.target].AST, callback) 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) { _hightlightExpressions (node, compilationResult) {
var self = this var self = this
function highlight (id) { function highlights (id) {
if (self._index['Declarations'] && self._index['Declarations'][id]) { if (self._index['Declarations'] && self._index['Declarations'][id]) {
var calls = self._index['Declarations'][id] var calls = self._index['Declarations'][id]
for (var call in calls) { for (var call in calls) {
var node = calls[call] var node = calls[call]
var position = self.sourceMappingDecoder.decode(node.src) self._highlight(node, compilationResult, 'reference')
var eventId = self._api.highlight(position, node)
if (eventId) {
self._events.push({ eventId, position, fileTarget: compilationResult.source.target })
}
} }
} }
} }
if (node.attributes && node.attributes.referencedDeclaration) { 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 { } else {
highlight(node.id) highlights(node.id, 'current')
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment