[ide] added contentassistentry kinds

This commit is contained in:
Sven Efftinge 2016-06-13 16:45:00 +02:00
parent 263c833881
commit 090dac24e1
4 changed files with 68 additions and 5 deletions

View file

@ -70,4 +70,29 @@ class ContentAssistEntry {
*/
transient Object source
/**
* The kind of element that is proposed. Could be one of the constants below something specific a concrete client understands.
*/
String kind
public static val KIND_TEXT = "TEXT"
public static val KIND_METHOD = "METHOD"
public static val KIND_FUNCTION = "FUNCTION"
public static val KIND_CONSTRUCTOR = "CONSTRUCTOR"
public static val KIND_FIELD = "FIELD"
public static val KIND_VARIABLE = "VARIABLE"
public static val KIND_CLASS = "CLASS"
public static val KIND_INTERFACE = "INTERFACE"
public static val KIND_MODULE = "MODULE"
public static val KIND_PROPERTY = "PROPERTY"
public static val KIND_UNIT = "UNIT"
public static val KIND_VALUE = "VALUE"
public static val KIND_ENUM = "ENUM"
public static val KIND_KEYWORD = "KEYWORD"
public static val KIND_SNIPPET = "SNIPPET"
public static val KIND_COLOR = "COLOR"
public static val KIND_FILE = "FILE"
public static val KIND_REFERENCE = "REFERENCE"
public static val KIND_UNKOWN = "UNKOWN"
}

View file

@ -26,7 +26,7 @@ class IdeContentProposalCreator {
* Returns an entry with the given proposal and the prefix from the context, or null if the proposal is not valid.
*/
def ContentAssistEntry createProposal(String proposal, ContentAssistContext context) {
createProposal(proposal, context.prefix, context, null)
createProposal(proposal, context.prefix, context, ContentAssistEntry.KIND_UNKOWN, null)
}
/**
@ -34,19 +34,28 @@ class IdeContentProposalCreator {
* If it is valid, the initializer function is applied to it.
*/
def ContentAssistEntry createProposal(String proposal, ContentAssistContext context, (ContentAssistEntry)=>void init) {
createProposal(proposal, context.prefix, context, init)
createProposal(proposal, context.prefix, context, ContentAssistEntry.KIND_UNKOWN, init)
}
/**
* Returns an entry with the given proposal and the prefix from the context, or null if the proposal is not valid.
* If it is valid, the initializer function is applied to it.
*/
def ContentAssistEntry createProposal(String proposal, ContentAssistContext context, String kind, (ContentAssistEntry)=>void init) {
createProposal(proposal, context.prefix, context, kind, init)
}
/**
* Returns an entry with the given proposal and prefix, or null if the proposal is not valid.
* If it is valid, the initializer function is applied to it.
*/
def ContentAssistEntry createProposal(String proposal, String prefix, ContentAssistContext context,
def ContentAssistEntry createProposal(String proposal, String prefix, ContentAssistContext context, String kind,
(ContentAssistEntry)=>void init) {
if (isValidProposal(proposal, prefix, context)) {
val result = new ContentAssistEntry
result.proposal = proposal
result.prefix = prefix
result.kind = kind
if (init !== null)
init.apply(result)
return result

View file

@ -88,10 +88,13 @@ class IdeContentProposalProvider {
else
assignment.feature
val entry = proposalCreator.createProposal(proposal, context) [
if (rule.name == 'STRING')
if (rule.name == 'STRING') {
editPositions += new TextRegion(context.offset + 1, proposal.length - 2)
else
kind = ContentAssistEntry.KIND_TEXT
} else {
editPositions += new TextRegion(context.offset, proposal.length)
kind = ContentAssistEntry.KIND_VALUE
}
description = rule.name
]
acceptor.accept(entry, proposalPriorities.getDefaultPriority(entry))
@ -103,6 +106,7 @@ class IdeContentProposalProvider {
IIdeContentProposalAcceptor acceptor) {
if (filterKeyword(keyword, context)) {
val entry = proposalCreator.createProposal(keyword.value, context)
entry.kind = ContentAssistEntry.KIND_KEYWORD
acceptor.accept(entry, proposalPriorities.getKeywordPriority(keyword.value, entry))
}
}

View file

@ -275,8 +275,33 @@ import org.eclipse.xtext.resource.IMimeTypeProvider
completionItem.label = entry.label ?: entry.proposal
completionItem.detail = entry.description
completionItem.insertText = entry.proposal
completionItem.kind = translateKind(entry)
return completionItem
}
protected def translateKind(ContentAssistEntry entry) {
switch entry.kind {
case ContentAssistEntry.KIND_CLASS : CompletionItem.KIND_CLASS
case ContentAssistEntry.KIND_COLOR : CompletionItem.KIND_COLOR
case ContentAssistEntry.KIND_CONSTRUCTOR : CompletionItem.KIND_CONSTRUCTOR
case ContentAssistEntry.KIND_ENUM : CompletionItem.KIND_ENUM
case ContentAssistEntry.KIND_FIELD : CompletionItem.KIND_FIELD
case ContentAssistEntry.KIND_FILE : CompletionItem.KIND_FILE
case ContentAssistEntry.KIND_FUNCTION : CompletionItem.KIND_FUNCTION
case ContentAssistEntry.KIND_INTERFACE : CompletionItem.KIND_INTERFACE
case ContentAssistEntry.KIND_KEYWORD : CompletionItem.KIND_KEYWORD
case ContentAssistEntry.KIND_METHOD : CompletionItem.KIND_METHOD
case ContentAssistEntry.KIND_MODULE : CompletionItem.KIND_MODULE
case ContentAssistEntry.KIND_PROPERTY : CompletionItem.KIND_PROPERTY
case ContentAssistEntry.KIND_REFERENCE : CompletionItem.KIND_REFERENCE
case ContentAssistEntry.KIND_SNIPPET : CompletionItem.KIND_SNIPPET
case ContentAssistEntry.KIND_TEXT : CompletionItem.KIND_TEXT
case ContentAssistEntry.KIND_UNIT : CompletionItem.KIND_UNIT
case ContentAssistEntry.KIND_VALUE : CompletionItem.KIND_VALUE
case ContentAssistEntry.KIND_VARIABLE : CompletionItem.KIND_VARIABLE
default : CompletionItem.KIND_VALUE
}
}
// end completion stuff
// symbols