Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Adding Additional Parameters to ContentAssistContext
Adding Additional Parameters to ContentAssistContext [message #1723489] Tue, 16 February 2016 07:22 Go to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
Hi,
I am trying to add additional metadata (say abc) to ContentAssistContext which I want to use here.


 StatemachineWebContentProposalProvider extends IdeContentProposalProvider {

    
  override dispatch createProposals(RuleCall ruleCall, ContentAssistContext context,
    IIdeContentProposalAcceptor acceptor) {

    context.abc



    }




I though I could directly add in the context which I could retrieve as above. However I see that , it is created using Factory which restricts any additional paramter.
  val contextFactory = contextFactoryProvider.get() => [pool = Executors.newCachedThreadPool]
        contextFactory.create(text, selection, caretOffset, resource)


Could you suggest a way to modify context. Is it recommended. Basically , I wish to pass additional parameter to the method I posted above.
Re: Adding Additional Parameters to ContentAssistContext [message #1723490 is a reply to message #1723489] Tue, 16 February 2016 07:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
can you be a bit more specific what you want to do?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding Additional Parameters to ContentAssistContext [message #1723492 is a reply to message #1723490] Tue, 16 February 2016 07:48 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
I want to add an additional metadata to ContentAssistContext. Such that I can use it in createProposals . For example :context.accountNo


 StatemachineWebContentProposalProvider extends IdeContentProposalProvider {

    
  override dispatch createProposals(RuleCall ruleCall, ContentAssistContext context,
    IIdeContentProposalAcceptor acceptor) {

    



    }
Re: Adding Additional Parameters to ContentAssistContext [message #1723499 is a reply to message #1723492] Tue, 16 February 2016 08:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
hi,

what i wanted to know.

- where does this metadata come from?
- why you cannot inject/set this data into the proposalprovider itself?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding Additional Parameters to ContentAssistContext [message #1723501 is a reply to message #1723499] Tue, 16 February 2016 08:34 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
This metadata is like additional parameter that is used to invoke content assist api. For example ,

This is how I am executing the content assist

   def ContentAssistServiceResponse executeContentAssistor(ContentAssistServiceRequest request) {

            val prefix =request.getPrefix ;
            val prefixSize = prefix.length
            val accountNo=request.accountNo

            val Injector injector = new EinDslStandAloneCASetup().createInjectorAndDoEMFRegistration()
            val resourceSet = injector.getInstance(ResourceSet);
            val resource = resourceSet.createResource(URI.createURI("file:/example.eindsl")) as XtextResource

       

            resource.load(new ByteArrayInputStream(prefix.toString.getBytes(Charsets.UTF_8)),null)
            val standAloneContentAssistService = injector.getInstance(StandAloneContentAssistService)
            val selection = new TextRegion(prefixSize,0 )
            val result = standAloneContentAssistService.createProposals(resource, resource.parseResult.rootNode.text, selection,prefixSize, 1000)

            if(result==null) {
                throw new  ContentAssistFailureException("Content Assist has failed to provide proposals")
            }

            val contentAssistServiceResponse= updateResponseModelFromResultAndPrefix(prefix,result)
            return contentAssistServiceResponse
    }



This is the StandAloneContentAssistService
class StandAloneContentAssistService {

    @Inject Provider<ContentAssistContextFactory> contextFactoryProvider
    @Inject IdeContentProposalProvider proposalProvider

    def createProposals(XtextResource resource, String text, ITextRegion selection, int caretOffset, int limit) {
        val contexts = getContexts(resource, text, selection, caretOffset)
        return createProposals(Arrays.asList(contexts), limit)
    }

    def private ContentAssistContext[] getContexts(XtextResource resource, String text, ITextRegion selection,
    int caretOffset) {
        if (caretOffset > text.length)
            return #[]
        val contextFactory = contextFactoryProvider.get() => [pool = Executors.newCachedThreadPool]
        contextFactory.create(text, selection, caretOffset, resource)
    }

    def private createProposals(List<ContentAssistContext> contexts, int proposalsLimit) {
        val result = new ContentAssistResult(null)
        if (!contexts.empty) {
            val proposals = new HashSet<Pair<Integer, ContentAssistEntry>>
            val acceptor = new  IIdeContentProposalAcceptor{
                override accept(ContentAssistEntry entry, int priority) {
                    if (entry.proposal === null)
                        throw new IllegalArgumentException('proposal must not be null.')
                    proposals.add(priority -> entry)
                }

                override canAcceptMoreProposals() {
                    proposals.size < proposalsLimit
                }
            }

            proposalProvider.createProposals(contexts, acceptor)

            result.entries.addAll(proposals.sortWith [ p1, p2 |
                val prioResult = p2.key.compareTo(p1.key)
                if (prioResult != 0)
                    return prioResult
                val s1 = p1.value.label ?: p1.value.proposal
                val s2 = p2.value.label ?: p2.value.proposal
                return s1.compareTo(s2)
            ].map[value])
        }
        return result
    }


}



Notice the account Number that I had in my request .
I want to retrieve it here when

class StatemachineWebContentProposalProvider extends IdeContentProposalProvider {

    @Inject extension EinDslGrammarAccess

    @Inject SuggestionsService suggestionService
   

    override dispatch createProposals(RuleCall ruleCall, ContentAssistContext context,
    IIdeContentProposalAcceptor acceptor) {

        val prefix= context.prefix
        val accountNo=???        <------------need accountNo here.
        val rule=ruleCall.rule



I do not intend to inject the class variable of provider. Instead I wish to add in the ContentAssistContext.

[Updated on: Tue, 16 February 2016 08:39]

Report message to a moderator

Re: Adding Additional Parameters to ContentAssistContext [message #1723502 is a reply to message #1723501] Tue, 16 February 2016 08:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
id create a

@Singleton
class MyBusinessContext {
public var accountNo
}

and inject that to my proposal provider ContentAssistServiceResponse id ask the injector
for the MyBusinessContext and set its accountno


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding Additional Parameters to ContentAssistContext [message #1723518 is a reply to message #1723502] Tue, 16 February 2016 11:07 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
Could you please elaborate on "and inject that to my proposal provider ContentAssistServiceResponse id ask the injector
for the MyBusinessContext and set its accountno"

I
Re: Adding Additional Parameters to ContentAssistContext [message #1723521 is a reply to message #1723518] Tue, 16 February 2016 11:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
val myBusinessContext = injector.getInstance(MyBusinessContext);
myBusinessContext.accountNo=accountNo
.......

class StatemachineWebContentProposalProvider extends IdeContentProposalProvider {
@Inject extension MyBusinessContext
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding Additional Parameters to ContentAssistContext [message #1723643 is a reply to message #1723521] Wed, 17 February 2016 03:37 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
Thank You.I intend to have account number different for each request. Please suggest

[Updated on: Wed, 17 February 2016 03:38]

Report message to a moderator

Re: Adding Additional Parameters to ContentAssistContext [message #1723647 is a reply to message #1723643] Wed, 17 February 2016 04:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
pranay roy <forums-noreply@xxxxxxxx> wrote:
> I intend to have account number different for each request. Please suggest
>

I think you are standalone. So are you or are you not


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding Additional Parameters to ContentAssistContext [message #1723649 is a reply to message #1723647] Wed, 17 February 2016 04:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
cause if you are standalone,
(in your example you call standalone foreach request)
you can set different data into the businesscontext at each request


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding Additional Parameters to ContentAssistContext [message #1723653 is a reply to message #1723649] Wed, 17 February 2016 05:58 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
Is it a good idea to call a new standalone for each request. I am using REST api for invoking this. So each request will have a new Standalone.!What do you suggest.
Re: Adding Additional Parameters to ContentAssistContext [message #1723659 is a reply to message #1723653] Wed, 17 February 2016 07:04 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
i dont know how to handle this multithreading wise
ntl

if you want to make it multithreading enabled put a threadlocal into the businesscontext


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Load EObject with all cross-references from file path
Next Topic:IResourceDescription's URI sync
Goto Forum:
  


Current Time: Thu Mar 28 22:26:13 GMT 2024

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

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

Back to the top