Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to write Content Assist(How to write content assit for a language)
How to write Content Assist [message #757725] Mon, 21 November 2011 11:08 Go to next message
Zeeshan Safder is currently offline Zeeshan SafderFriend
Messages: 27
Registered: November 2011
Junior Member
Hi,

I like to wirte content assist for my language. Where I am employeed, they are using there custom langauge framework. But it lacks the IDE enviroment. My task is to write content assist for their framework, so that development gets bit easier.

Language is javascript based and adopted to objected oriented paradigm. Now I have to write content assistant for it.

I have posted a similer thread before. At that time I was tring to write complete grammer again. But now I have been said to not write the actuall grammer, just somehow provide the contenet assistant for it.

Now need your support to start the task, as I still have no idea how to do it...

Regards
Zeeshan Safder
Re: How to write Content Assist [message #757730 is a reply to message #757725] Mon, 21 November 2011 11:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

you will do not get any new answer: fill YourdslProposalprovider (overwrite methods from abstract superclass) with "life" but as i said before - with a dynamic language this will be pain in the ass - with a static typed you will get most for free.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to write Content Assist [message #758145 is a reply to message #757730] Tue, 22 November 2011 06:23 Go to previous messageGo to next message
Zeeshan Safder is currently offline Zeeshan SafderFriend
Messages: 27
Registered: November 2011
Junior Member
But I have to find some way to do the task, as it is must task not a choice. Please guide me how to accomplish it...
Re: How to write Content Assist [message #758146 is a reply to message #758145] Tue, 22 November 2011 06:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi, a such unspecific question is not answerable. Did you have a look
at the docs and api at all. Maybe you should start learning with some
more simple grammars.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to write Content Assist [message #758152 is a reply to message #758145] Tue, 22 November 2011 07:47 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

if I understand your question correctly, the files are currently not edited using an Xtext editor (and you don't even say what kind of IDE/edidor is used). If your task is to implement code completion without implementing an Xtext grammar, the Xtext framework cannot help you to implement code completion (of course you can browse the source code in order to see how code completion is realised).

Also, this forum deals with Xtext. If that is not the editor's basis, don't expect too much help.

Alex
Re: How to write Content Assist [message #758452 is a reply to message #758152] Wed, 23 November 2011 10:43 Go to previous messageGo to next message
Zeeshan Safder is currently offline Zeeshan SafderFriend
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 #758455 is a reply to message #758452] Wed, 23 November 2011 10:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
no double posts please

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to write Content Assist [message #758457 is a reply to message #758455] Wed, 23 November 2011 10:58 Go to previous messageGo to next message
Zeeshan Safder is currently offline Zeeshan SafderFriend
Messages: 27
Registered: November 2011
Junior Member
Sorry Christian Dietrich, will take care of it in future...
Re: How to write Content Assist [message #759324 is a reply to message #758457] Mon, 28 November 2011 11:36 Go to previous messageGo to next message
Zeeshan Safder is currently offline Zeeshan SafderFriend
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 #759338 is a reply to message #759324] Mon, 28 November 2011 12:25 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
"it is not working..." - could you be a bit more specific? As in: it's never called, or it throws an Exception, or it somehow doesn't return what I expect, or it doesn't compile??

Re: How to write Content Assist [message #759536 is a reply to message #759338] Tue, 29 November 2011 04:28 Go to previous messageGo to next message
Zeeshan Safder is currently offline Zeeshan SafderFriend
Messages: 27
Registered: November 2011
Junior Member
its never called...
Re: How to write Content Assist [message #759546 is a reply to message #759536] Tue, 29 November 2011 06:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
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
Re: How to write Content Assist [message #759552 is a reply to message #759546] Tue, 29 November 2011 07:15 Go to previous messageGo to next message
Zeeshan Safder is currently offline Zeeshan SafderFriend
Messages: 27
Registered: November 2011
Junior Member
I have pasted he wrong prototype, sorry for that. It was actually

scope_ClassMembers_memberFeatures(final ClassMembers context, EReference ref)

I have removed that method and when goingto post here copied the other prototype and forget to change the parameter
Re: How to write Content Assist [message #759561 is a reply to message #759552] Tue, 29 November 2011 08:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
still the same,

if you debug it you will notice that during ca the method maybe should be
scope_ClassMembers_memberFeatures(final SomeParentOfClassMember context, EReference ref)

use debugger to find it out

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to write Content Assist [message #759567 is a reply to message #759561] Tue, 29 November 2011 08:41 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Some detailed hints: http://dslmeinte.wordpress.com/2010/09/06/tricks-for-implementing-scoping/
(Written for Xtext 1.x, but also valid for Xtext 2.y.z.)


Re: How to write Content Assist [message #759915 is a reply to message #759567] Wed, 30 November 2011 14:54 Go to previous message
Zeeshan Safder is currently offline Zeeshan SafderFriend
Messages: 27
Registered: November 2011
Junior Member
With help of all of you, now my grammer and content assist start making some sense. I always thanks all of you for such a nice support. I have stuck again in grammer wrting. Consider the following case

Function:
'$'?name = ID':' 'function''('
( params+=ID(',' params+=ID)* )?
')''{'
.......................
'}'
;

A Simple java script function.
abc: function( p1, p2 ){
return p1 + p2
}

I like to know grammer of it. That use parameter in function local scope. Just want grammer to accept that parameters inside the function
Previous Topic:qulified names
Next Topic:extending Xbase expression syntax and possible ambiguities
Goto Forum:
  


Current Time: Thu Mar 28 15:16:01 GMT 2024

Powered by FUDForum. Page generated in 0.03484 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top