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:
- Somehow read in the allowed string list from a file;
- In the above
DomainmodelProposalProvider
, get the reference to the list of allowed list; - get the current ContentPath value from xtext;
- then use #3 to filter against the list obtained from #1.
- 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!