Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
281bee23
Commit
281bee23
authored
Sep 24, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
contextuallistener
parent
94a25953
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
0 deletions
+84
-0
contextualListener.js
src/app/editor/contextualListener.js
+84
-0
No files found.
src/app/editor/contextualListener.js
0 → 100644
View file @
281bee23
'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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment