我无法让提案提供商正常工作。我的目标是提供用户可以创建的所有可能导入的列表。我可以验证该类是否已正确绑定,并且正在根据编辑器的协助请求被调用。我什至可以看到正在创建提案并将其传递给接受者,但是编辑器中什么都没有显示。
所以我的问题可能是两部分:
如果有任何效果,我也在使用CodeMirror。
class mydslContentAssist extends IdeContentProposalProvider{
@Inject extension mydslGrammarAccess stAccess
@Inject mydslGlobalScopeProvider sp
@Inject extension IQualifiedNameProvider
override dispatch createProposals(Assignment assignment, ContentAssistContext context, IIdeContentProposalAcceptor acceptor) {
switch(assignment) {
case stAccess.libraryModelAccess.importsAssignment_0: {
var libs = sp.descriptionData.getExportedObjectsByType(ModelPackage.eINSTANCE.libraryModel)
for (lib : libs.filter[(EObjectOrProxy as LibraryModel).name.startsWith(context.prefix)]) {
var proposal = proposalCreator.createProposal('import ' + (lib.EObjectOrProxy as LibraryModel).name + ".*;", context) [
source = lib
description = "import entire library contents"
]
acceptor.accept(proposal, proposalPriorities.getDefaultPriority(proposal))
}
}
default : {
super._createProposals(assignment, context, acceptor)
}
}
}
override dispatch createProposals(RuleCall rulecall, ContentAssistContext context, IIdeContentProposalAcceptor acceptor) {
switch(rulecall.rule) {
case importRule: {
var libs = sp.descriptionData.getExportedObjectsByType(ModelPackage.eINSTANCE.libraryModel)
for (lib : libs) {
var proposal = proposalCreator.createProposal('import ' + (lib.EObjectOrProxy as LibraryModel).name + ".*;", context) [
source = lib
description = "import entire library contents"
]
acceptor.accept(proposal, proposalPriorities.getDefaultPriority(proposal))
}
}
default : {
super._createProposals(rulecall, context, acceptor)
}
}
}
override dispatch createProposals(Keyword keyword, ContentAssistContext context, IIdeContentProposalAcceptor acceptor) {
switch (keyword) {
case stAccess.importAccess.importKeyword_0: {
var libs = sp.descriptionData.getExportedObjectsByType(ModelPackage.eINSTANCE.libraryModel)
for (lib : libs) {
var proposal = proposalCreator.createProposal('import ' + (lib.EObjectOrProxy as LibraryModel).name + ".*;", context) [
source = lib
description = "import entire library contents"
]
acceptor.accept(proposal, proposalPriorities.getDefaultPriority(proposal))
}
}
default: {
super._createProposals(keyword, context, acceptor)
}
}
}
}
编辑:仅当键入'import'关键字时调用内容帮助时,我的代码才会被击中。但是键入importedNamespace字符串时不可以
答案 0 :(得分:0)
我尝试了一下,无法复制
语法:
Model:
imports+=Import*;
Import: 'import' importedNamespace=QualifiedNameWithWildcard ';'
;
QualifiedNameWithWildcard:
ID ("." ID)* (".*")?
;
和展示
package org.xtext.example.mydsl.web
import com.google.inject.Inject
import org.eclipse.xtext.Assignment
import org.eclipse.xtext.Keyword
import org.eclipse.xtext.RuleCall
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext
import org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor
import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider
import org.eclipse.xtext.naming.IQualifiedNameProvider
import org.xtext.example.mydsl.services.MyDslGrammarAccess
class MydslContentAssist extends IdeContentProposalProvider {
@Inject extension MyDslGrammarAccess stAccess
static val LIBS = #[
"XX1", "XX2", "YY1", "YY2"
]
override dispatch createProposals(Assignment assignment, ContentAssistContext context, IIdeContentProposalAcceptor acceptor) {
switch(assignment) {
case stAccess.importAccess.importedNamespaceAssignment_1: {
for (lib : LIBS.filter[it.startsWith(context.prefix)]) {
var proposal = proposalCreator.createProposal(lib + ".*;", context) [
source = lib
description = "import entire library contents"
]
acceptor.accept(proposal, proposalPriorities.getDefaultPriority(proposal))
}
}
default : {
super._createProposals(assignment, context, acceptor)
}
}
}
override dispatch createProposals(RuleCall rulecall, ContentAssistContext context, IIdeContentProposalAcceptor acceptor) {
switch(rulecall.rule) {
case importRule: {
for (lib : LIBS) {
var proposal = proposalCreator.createProposal('import ' + lib + ".*;", context) [
source = lib
description = "import entire library contents"
]
acceptor.accept(proposal, proposalPriorities.getDefaultPriority(proposal))
}
}
default : {
super._createProposals(rulecall, context, acceptor)
}
}
}
override dispatch createProposals(Keyword keyword, ContentAssistContext context, IIdeContentProposalAcceptor acceptor) {
switch (keyword) {
case stAccess.importAccess.importKeyword_0: {
for (lib : LIBS) {
var proposal = proposalCreator.createProposal('import ' + lib + ".*;", context) [
source = lib
description = "import entire library contents"
]
acceptor.accept(proposal, proposalPriorities.getDefaultPriority(proposal))
}
}
default: {
super._createProposals(keyword, context, acceptor)
}
}
}
}