|
|
@ -6,16 +6,16 @@ class ContextualListener { |
|
|
|
constructor (api, events) { |
|
|
|
constructor (api, events) { |
|
|
|
this._api = api |
|
|
|
this._api = api |
|
|
|
this._index = { |
|
|
|
this._index = { |
|
|
|
ReferencedDeclarations: {}, |
|
|
|
Declarations: {}, |
|
|
|
Expressions: [] |
|
|
|
References: [] |
|
|
|
} |
|
|
|
} |
|
|
|
this._events = [] |
|
|
|
this._events = [] |
|
|
|
|
|
|
|
|
|
|
|
events.compiler.register('compilationFinished', (success, data, source) => { |
|
|
|
events.compiler.register('compilationFinished', (success, data, source) => { |
|
|
|
this._stopWarning() |
|
|
|
this._stopHighlighting() |
|
|
|
this._index = { |
|
|
|
this._index = { |
|
|
|
ReferencedDeclarations: {}, |
|
|
|
Declarations: {}, |
|
|
|
Expressions: [] |
|
|
|
References: [] |
|
|
|
} |
|
|
|
} |
|
|
|
if (success) { |
|
|
|
if (success) { |
|
|
|
this._buildIndex(data, source) |
|
|
|
this._buildIndex(data, source) |
|
|
@ -24,18 +24,18 @@ class ContextualListener { |
|
|
|
this.sourceMappingDecoder = new SourceMappingDecoder() |
|
|
|
this.sourceMappingDecoder = new SourceMappingDecoder() |
|
|
|
this.astWalker = new AstWalker() |
|
|
|
this.astWalker = new AstWalker() |
|
|
|
setInterval(() => { |
|
|
|
setInterval(() => { |
|
|
|
this._warnExpressions(api.getCursorPosition(), api.getCompilationResult()) |
|
|
|
this._highlight(api.getCursorPosition(), api.getCompilationResult()) |
|
|
|
}, 1000) |
|
|
|
}, 1000) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_warnExpressions (cursorPosition, compilationResult) { |
|
|
|
_highlight (cursorPosition, compilationResult) { |
|
|
|
if (this.currentPosition === cursorPosition) return |
|
|
|
if (this.currentPosition === cursorPosition) return |
|
|
|
this._stopWarning() |
|
|
|
this._stopHighlighting() |
|
|
|
this.currentPosition = cursorPosition |
|
|
|
this.currentPosition = cursorPosition |
|
|
|
if (compilationResult && compilationResult.data && compilationResult.source) { |
|
|
|
if (compilationResult && compilationResult.data && compilationResult.source) { |
|
|
|
var nodes = this.sourceMappingDecoder.nodesAtPosition(null, cursorPosition, compilationResult.data.sources[compilationResult.source.target]) |
|
|
|
var nodes = this.sourceMappingDecoder.nodesAtPosition(null, cursorPosition, compilationResult.data.sources[compilationResult.source.target]) |
|
|
|
if (nodes && nodes.length && nodes[nodes.length - 1]) { |
|
|
|
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 = {} |
|
|
|
var callback = {} |
|
|
|
callback['*'] = function (node) { |
|
|
|
callback['*'] = function (node) { |
|
|
|
if (node && node.attributes && node.attributes.referencedDeclaration) { |
|
|
|
if (node && node.attributes && node.attributes.referencedDeclaration) { |
|
|
|
if (!self._index['ReferencedDeclarations'][node.attributes.referencedDeclaration]) { |
|
|
|
if (!self._index['Declarations'][node.attributes.referencedDeclaration]) { |
|
|
|
self._index['ReferencedDeclarations'][node.attributes.referencedDeclaration] = [] |
|
|
|
self._index['Declarations'][node.attributes.referencedDeclaration] = [] |
|
|
|
} |
|
|
|
} |
|
|
|
self._index['ReferencedDeclarations'][node.attributes.referencedDeclaration].push(node) |
|
|
|
self._index['Declarations'][node.attributes.referencedDeclaration].push(node) |
|
|
|
self._index['Expressions'].push(node) |
|
|
|
self._index['References'].push(node) |
|
|
|
} |
|
|
|
} |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
@ -58,17 +58,19 @@ class ContextualListener { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_warnExpression (node, compilationResult) { |
|
|
|
_hightlightExpressions (node, compilationResult) { |
|
|
|
var self = this |
|
|
|
var self = this |
|
|
|
function highlight (id) { |
|
|
|
function highlight (id) { |
|
|
|
if (self._index['ReferencedDeclarations'] && self._index['ReferencedDeclarations'][id]) { |
|
|
|
if (self._index['Declarations'] && self._index['Declarations'][id]) { |
|
|
|
var calls = self._index['ReferencedDeclarations'][id] |
|
|
|
var calls = self._index['Declarations'][id] |
|
|
|
for (var call in calls) { |
|
|
|
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) { |
|
|
|
if (node.attributes && node.attributes.referencedDeclaration) { |
|
|
|
highlight(node.attributes.referencedDeclaration) |
|
|
|
highlight(node.attributes.referencedDeclaration) |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -76,15 +78,9 @@ class ContextualListener { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_warn (src, compilationResult) { |
|
|
|
_stopHighlighting () { |
|
|
|
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) { |
|
|
|
for (var event in this._events) { |
|
|
|
this._api.stopWarningExpression(this._events[event]) |
|
|
|
this._api.stopHighlighting(this._events[event]) |
|
|
|
} |
|
|
|
} |
|
|
|
this._events = [] |
|
|
|
this._events = [] |
|
|
|
} |
|
|
|
} |
|
|
|