|
|
|
|
|
Re: How to write Content Assist [message #758452 is a reply to message #758152] |
Wed, 23 November 2011 10:43 |
Zeeshan Safder Messages: 27 Registered: November 2011 |
Junior Member |
|
|
hi,
This is my langauge
Domainmodel :
(elements += Type
| variables+=VariableDeclaration
| actions+=ActionStatement)*
;
Type:
ClassDeclaration
;
ClassDeclaration returns classs:
name = ID '=' '{'
(feature += Feature)*
'}'
;
Feature:
Function
;
Function returns function:
name = ID ':' 'function''(' ( parameters+=ID (','parameters+=ID)* )? ')''{'
'}'
;
VariableDeclaration:
'var' name=ID '=' 'new' resource=[classs] '('')'
;
ResourcePathHead:
variable=[VariableDeclaration]
;
ActionStatement:
path=ResourcePathHead '.' action=[function]
;
And this is the simple 'AbstractDeclarativeScopeProvider' extended class method
public IScope scope_ActionStatement_action(final ActionStatement context, EReference ref) {
//get the tail end of the resource path
classs tailResource = context.getPath().getVariable().getResource();
return Scopes.scopeFor (tailResource.getFeature());
}
Suppose the follwing language code
a = {
abc: function(t1, t2){
}
xyz: function(){
}
zst: function(){
}
}
var ab = new a()
Now when I do
'ab.' it will list all functions defined. But I want more information. It must show how many parameter it receives.
Currenlt 'ab.' will assist 'abc', 'xyz', 'zst' it should assist like 'abs(t1,t2)', 'xyz()' etc
For that point I just come to know that I have to implement a custom IScope Providor, but have got the idea how to implement it. After almost 5 hrz of google, I have decided to post here and hope will got the best possible help...
|
|
|
|
|
Re: How to write Content Assist [message #759324 is a reply to message #758457] |
Mon, 28 November 2011 11:36 |
Zeeshan Safder Messages: 27 Registered: November 2011 |
Junior Member |
|
|
Hi This is my grammer
grammar org.gvs.ngcore.dsl.NGCore with org.eclipse.xtext.common.Terminals
generate nGCore "http://www.gvs.org/ngcore/dsl/NGCore"
//file extension = .js
Domainmodel :
(elements += ClassDeclaration
| variables+=VariableDeclaration
| actions+=ActionStatement | requireStatements += RequireStatements
| globalFunction += GlobalFunction)*
;
//var Element = exports.Element = Class.subclass
ClassDeclaration returns NGClass:
('var' localFileName = ID '=')? 'exports' '.' name = ID '='
(
(
super = [NGClass] '.' ('subclass' | 'singleton') '(' '{'( (features += Feature)(','features += Feature)* )? ','?'}' ')'
)
|
(
'{' ( (features += Feature)(','features += Feature)* )? ','? '}'
)
)
';'?
;
RequireStatements:
'var'? name = ID '=' 'require''(' STRING ')' ('.'ID)*';'?
;
AbstractType:
Function | MemberVariable | ThisVariable
;
Feature:
Function | MemberVariable
;
Function returns NGFunction:
'$'?name = ID ':' 'function''(' ( param+=ID (','param+=ID)* )? ')''{'
(features += FuntionFeatures)*
'}'
;
FuntionFeatures:
ThisFeatures
;
ThisFeatures:
('this''.' ClassMembers) | ('this''+'ThisVariable)
;
ClassMembers:
memberFeatures = [Feature]
;
ThisVariable:
varName = ID ('=' INT)? ';'?
;
MemberVariable:
'$'?name = ID ':' (STRING | ID('.'ID)* | INT)
;
VariableDeclaration:
'var' name=ID '=' 'new' resource=[NGClass] '('')' ';'?
;
ClassObject:
variable=[VariableDeclaration]
;
ActionStatement:
path=ClassObject '.' action=[AbstractType] ( '(' ( ID (','ID)* )? ')' )? ';'?
;
GlobalFunction:
name = ID '=' 'function''(' ( param+=ID (','param+=ID)* )? ')''{'
'}'';'?
;
I have define scope for Action Statement like -
public IScope scope_ActionStatement_action(final ActionStatement context, EReference ref){...}
And it is working fine
Now I want to define scope for 'ClassMembers' and have wrote function like
public IScope scope_ClassMembers_memberFeatures(final ActionStatement context, EReference ref){...}
but it is not working...
|
|
|
|
|
Re: How to write Content Assist [message #759546 is a reply to message #759536] |
Tue, 29 November 2011 06:27 |
|
Hi,
Xtext creates Objects as Lazy as Possible, thus the context of the scope method may be a parent of the object and not the object itself during content assist. so you have to add an additional scoping method
scope_ClassMembers_memberFeatures(final ActionStatement context, EReference ref){...}
i have no idea why you think the parent is an action statement and have put the action statement as context.
you should debug the getscope method to find out which method
is actually called during content assist with which parent
see polymorphicFindScopeForReferenceName in AbstractDeclarativeScopeProvider
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04949 seconds