0

I am new to Xtext and Xtend, and need advice how to best solve the issue below.

I am trying to create a customized autocompletion provider using the following code:

class DomainmodelProposalProvider extends AbstractDomainmodelProposalProvider {
    def override completePath_ContentPath(EObject model,
        Assignment assignment, 
        ContentAssistContext context, 
        ICompletionProposalAcceptor acceptor) {
            acceptor.accept(createCompletionProposal("/Root/hello/world", context))
            acceptor.accept(createCompletionProposal("/Root/hello/xtext", context))
            ....
            ....
    }
}

where contentPath can be from a list of xpath like strings, and the list can be big. More importantly, I want to do progressive autocompletion, that is if the user enters /Root/h it will provide both Root/hello/world and /Root/hello/xtext. But if he enters /Root/hello/x, it would only provide /Root/hello/xtext.

The battle plan is as below:

  1. Somehow read in the allowed string list from a file;
  2. In the above DomainmodelProposalProvider, get the reference to the list of allowed list;
  3. get the current ContentPath value from xtext;
  4. then use #3 to filter against the list obtained from #1.
  5. Return the resultant list.

But I am stuck at the first step. Where do I put the code of reading the external file in the xtext project ( I am using eclipse)? It should be act as a Singleton and only do the reading once, if I want to program in Xtend, how do I implement a singleton?

Any help will be appreciated!

gwang
  • 153
  • 1
  • 7
  • Beside the answer already given by @Jon. As of today. You don't need .4. It is filtered for you already. – davidmpaz Feb 25 '23 at 14:51

1 Answers1

0

Bind it for injection in YourLanguageRuntimeModule.java then @Inject it into the proposal provider. Guice will only create one by default so don't worry about implementing it as a singleton.

Jon
  • 398
  • 1
  • 11