Fixed: [Issue 158] Content assist for types does not respect scoping.
diff --git a/com.google.eclipse.protobuf.ui/plugin.xml b/com.google.eclipse.protobuf.ui/plugin.xml
index 4e44ea8..c169404 100644
--- a/com.google.eclipse.protobuf.ui/plugin.xml
+++ b/com.google.eclipse.protobuf.ui/plugin.xml
@@ -220,7 +220,7 @@
</extension>
<extension point="org.eclipse.xtext.builder.participant">
<participant
- class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.builder.ProtobufBuildParticipant">
+ class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.builder.protoc.ProtobufBuildParticipant">
</participant>
</extension>
<extension id="protocMarker" name="%protoc.marker.name" point="org.eclipse.core.resources.markers">
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java
index f2fef10..871298d 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java
@@ -73,11 +73,24 @@
proposeAndAccept(proposal, imageHelper.getImage(images.imageFor(Syntax.class)), context, acceptor);
}
- @Override public void complete_TypeRef(EObject model, RuleCall ruleCall, ContentAssistContext context,
+ @Override public void completeTypeRef_Type(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
- System.out.println("Hello");
+ Collection<IEObjectDescription> scope = scoping().findMessageScope(model);
+ for (IEObjectDescription d : descriptionChooser.shortestQualifiedNamesIn(scope)) {
+ Image image = imageHelper.getImage(images.imageFor(d.getEObjectOrProxy()));
+ proposeAndAccept(d, image, context, acceptor);
+ }
}
+ @Override public void completeMessageRef_Type(EObject model, Assignment assignment, ContentAssistContext context,
+ ICompletionProposalAcceptor acceptor) {
+ Collection<IEObjectDescription> scope = scoping().findTypeScope(model);
+ for (IEObjectDescription d : descriptionChooser.shortestQualifiedNamesIn(scope)) {
+ Image image = imageHelper.getImage(images.imageFor(d.getEObjectOrProxy()));
+ proposeAndAccept(d, image, context, acceptor);
+ }
+ }
+
@Override public void completeNativeOption_Source(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
ProtoDescriptor descriptor = descriptorProvider.primaryDescriptor();
@@ -411,7 +424,7 @@
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
if (!(model instanceof CustomOption)) return;
CustomOption option = (CustomOption) model;
- Collection<IEObjectDescription> scope = scoping().findSources(option);
+ Collection<IEObjectDescription> scope = scoping().findScope(option);
proposeAndAcceptOptions(scope, context, acceptor);
}
@@ -419,7 +432,7 @@
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
if (!(model instanceof CustomFieldOption)) return;
CustomFieldOption option = (CustomFieldOption) model;
- Collection<IEObjectDescription> scope = scoping().findSources(option);
+ Collection<IEObjectDescription> scope = scoping().findScope(option);
proposeAndAcceptOptions(scope, context, acceptor);
}
@@ -456,15 +469,15 @@
Collection<IEObjectDescription> scope = emptySet();
if (e instanceof CustomOption) {
CustomOption option = (CustomOption) e;
- scope = scoping().findNextMessageFieldSources(option);
+ scope = scoping().findMessageFieldScope(option);
}
if (e instanceof CustomFieldOption) {
CustomFieldOption option = (CustomFieldOption) e;
- scope = scoping().findNextMessageFieldSources(option);
+ scope = scoping().findMessageFieldScope(option);
}
if (e instanceof OptionMessageFieldSource) {
OptionMessageFieldSource source = (OptionMessageFieldSource) e;
- scope = scoping().findSources(source);
+ scope = scoping().findScope(source);
}
for (IEObjectDescription d : descriptionChooser.shortestQualifiedNamesIn(scope)) {
Image image = imageHelper.getImage(images.imageFor(d.getEObjectOrProxy()));
@@ -479,15 +492,15 @@
Collection<IEObjectDescription> scope = emptySet();
if (e instanceof CustomOption) {
CustomOption option = (CustomOption) e;
- scope = scoping().findNextExtendMessageFieldSources(option);
+ scope = scoping().findExtendMessageFieldScope(option);
}
if (e instanceof CustomFieldOption) {
CustomFieldOption option = (CustomFieldOption) e;
- scope = scoping().findNextExtendMessageFieldSources(option);
+ scope = scoping().findExtendMessageFieldScope(option);
}
if (e instanceof OptionExtendMessageFieldSource) {
OptionExtendMessageFieldSource source = (OptionExtendMessageFieldSource) e;
- scope = scoping().findSources(source);
+ scope = scoping().findScope(source);
}
for (IEObjectDescription d : descriptionChooser.shortestQualifiedNamesIn(scope)) {
Image image = imageHelper.getImage(images.imageFor(d.getEObjectOrProxy()));
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver.java
index 163188d..3cbec0a 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver.java
@@ -34,7 +34,9 @@
private String resolveUri(URI importUri, URI declaringResourceUri) {
StringBuilder pathBuilder = new StringBuilder();
- String firstSegment = importUri.segments()[0];
+ String[] segments = importUri.segments();
+ if (segments.length == 0) return null;
+ String firstSegment = segments[0];
for (String segment : removeFirstAndLast(declaringResourceUri)) {
if (segment.equals(firstSegment)) break;
pathBuilder.append(segment).append(SEPARATOR);
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java
index 3f744fa..08ee78f 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java
@@ -46,25 +46,32 @@
@Inject private TypeScopeFinder typeScopeFinder;
@SuppressWarnings("unused")
- public IScope scope_TypeRef_type(TypeRef typeRef, EReference reference) {
- EObject c = typeRef.eContainer();
+ public IScope scope_TypeRef_type(TypeRef t, EReference r) {
+ EObject c = t.eContainer();
if (c instanceof Property) {
- Property property = (Property) c;
- return createScope(astWalker.traverseAst(property, typeScopeFinder, Type.class));
+ return createScope(findTypeScope(c));
}
Set<IEObjectDescription> descriptions = emptySet();
return createScope(descriptions);
}
-
- @SuppressWarnings("unused")
- public IScope scope_MessageRef_type(MessageRef messageRef, EReference reference) {
- Protobuf root = modelFinder.rootOf(messageRef);
- return createScope(astWalker.traverseAst(root, typeScopeFinder, Message.class));
+
+ @Override public Collection<IEObjectDescription> findTypeScope(EObject o) {
+ return astWalker.traverseAst(o, typeScopeFinder, Type.class);
}
@SuppressWarnings("unused")
- public IScope scope_LiteralRef_literal(LiteralRef literalRef, EReference reference) {
- EObject container = literalRef.eContainer();
+ public IScope scope_MessageRef_type(MessageRef m, EReference r) {
+ return createScope(findMessageScope(m));
+ }
+
+ @Override public Collection<IEObjectDescription> findMessageScope(EObject o) {
+ Protobuf root = modelFinder.rootOf(o);
+ return astWalker.traverseAst(root, typeScopeFinder, Message.class);
+ }
+
+ @SuppressWarnings("unused")
+ public IScope scope_LiteralRef_literal(LiteralRef l, EReference r) {
+ EObject container = l.eContainer();
Enum anEnum = null;
if (container instanceof DefaultValueFieldOption) {
EObject optionContainer = container.eContainer();
@@ -97,8 +104,8 @@
}
@SuppressWarnings("unused")
- public IScope scope_OptionSource_optionField(OptionSource optionSource, EReference reference) {
- EObject c = optionSource.eContainer();
+ public IScope scope_OptionSource_optionField(OptionSource s, EReference r) {
+ EObject c = s.eContainer();
if (c instanceof NativeOption) {
NativeOption option = (NativeOption) c;
return createScope(nativeOptionDescriptions.properties(option));
@@ -109,98 +116,97 @@
}
if (c instanceof CustomOption) {
CustomOption option = (CustomOption) c;
- return createScope(findSources(option));
+ return createScope(findScope(option));
}
if (c instanceof CustomFieldOption) {
CustomFieldOption option = (CustomFieldOption) c;
- return createScope(findSources(option));
+ return createScope(findScope(option));
}
Set<IEObjectDescription> descriptions = emptySet();
return createScope(descriptions);
}
- @Override public Collection<IEObjectDescription> findSources(CustomOption option) {
- OptionType optionType = typeOf(option);
+ @Override public Collection<IEObjectDescription> findScope(CustomOption o) {
+ OptionType optionType = typeOf(o);
Collection<IEObjectDescription> descriptions = emptySet();
if (optionType != null) {
- descriptions = astWalker.traverseAst(option, customOptionScopeFinder, optionType);
+ descriptions = astWalker.traverseAst(o, customOptionScopeFinder, optionType);
}
return descriptions;
}
- @Override public Collection<IEObjectDescription> findSources(CustomFieldOption option) {
- OptionType optionType = typeOf(option);
+ @Override public Collection<IEObjectDescription> findScope(CustomFieldOption o) {
+ OptionType optionType = typeOf(o);
Collection<IEObjectDescription> descriptions = emptySet();
if (optionType != null) {
- descriptions = astWalker.traverseAst(option, customOptionScopeFinder, optionType);
+ descriptions = astWalker.traverseAst(o, customOptionScopeFinder, optionType);
}
return descriptions;
}
@SuppressWarnings("unused")
- public IScope scope_OptionMessageFieldSource_optionMessageField(OptionMessageFieldSource source,
- EReference reference) {
- return createScope(findSources(source));
+ public IScope scope_OptionMessageFieldSource_optionMessageField(OptionMessageFieldSource s, EReference r) {
+ return createScope(findScope(s));
}
- @Override public Collection<IEObjectDescription> findSources(OptionMessageFieldSource source) {
- EObject container = source.eContainer();
+ @Override public Collection<IEObjectDescription> findScope(OptionMessageFieldSource s) {
+ EObject container = s.eContainer();
if (container instanceof CustomOption) {
- return findSources((CustomOption) container, source);
+ return findSources((CustomOption) container, s);
}
if (container instanceof CustomFieldOption) {
- return findSources((CustomFieldOption) container, source);
+ return findSources((CustomFieldOption) container, s);
}
return emptySet();
}
- @Override public Collection<IEObjectDescription> findNextMessageFieldSources(CustomOption option) {
- return findSources(option, (OptionMessageFieldSource) null);
+ @Override public Collection<IEObjectDescription> findMessageFieldScope(CustomOption o) {
+ return findSources(o, (OptionMessageFieldSource) null);
}
- @Override public Collection<IEObjectDescription> findNextMessageFieldSources(CustomFieldOption option) {
- return findSources(option, (OptionMessageFieldSource) null);
+ @Override public Collection<IEObjectDescription> findMessageFieldScope(CustomFieldOption o) {
+ return findSources(o, (OptionMessageFieldSource) null);
}
- private Collection<IEObjectDescription> findSources(CustomOption option, OptionMessageFieldSource source) {
- return customOptionFieldScopeFinder.findScope(option, source);
+ private Collection<IEObjectDescription> findSources(CustomOption o, OptionMessageFieldSource s) {
+ return customOptionFieldScopeFinder.findScope(o, s);
}
- private Collection<IEObjectDescription> findSources(CustomFieldOption option, OptionMessageFieldSource source) {
- return customOptionFieldScopeFinder.findScope(option, source);
+ private Collection<IEObjectDescription> findSources(CustomFieldOption o, OptionMessageFieldSource s) {
+ return customOptionFieldScopeFinder.findScope(o, s);
}
@SuppressWarnings("unused")
- public IScope scope_OptionExtendMessageFieldSource_optionExtendMessageField(OptionExtendMessageFieldSource source,
- EReference reference) {
- return createScope(findSources(source));
+ public IScope scope_OptionExtendMessageFieldSource_optionExtendMessageField(OptionExtendMessageFieldSource s,
+ EReference r) {
+ return createScope(findScope(s));
}
- @Override public Collection<IEObjectDescription> findSources(OptionExtendMessageFieldSource source) {
- EObject container = source.eContainer();
+ @Override public Collection<IEObjectDescription> findScope(OptionExtendMessageFieldSource s) {
+ EObject container = s.eContainer();
if (container instanceof CustomOption) {
- return findSources((CustomOption) container, source);
+ return findSources((CustomOption) container, s);
}
if (container instanceof CustomFieldOption) {
- return findSources((CustomFieldOption) container, source);
+ return findSources((CustomFieldOption) container, s);
}
return emptySet();
}
- @Override public Collection<IEObjectDescription> findNextExtendMessageFieldSources(CustomOption option) {
- return findSources(option, (OptionExtendMessageFieldSource) null);
+ @Override public Collection<IEObjectDescription> findExtendMessageFieldScope(CustomOption o) {
+ return findSources(o, (OptionExtendMessageFieldSource) null);
}
- @Override public Collection<IEObjectDescription> findNextExtendMessageFieldSources(CustomFieldOption option) {
- return findSources(option, (OptionExtendMessageFieldSource) null);
+ @Override public Collection<IEObjectDescription> findExtendMessageFieldScope(CustomFieldOption o) {
+ return findSources(o, (OptionExtendMessageFieldSource) null);
}
- private Collection<IEObjectDescription> findSources(CustomOption option, OptionExtendMessageFieldSource source) {
- return customOptionFieldScopeFinder.findScope(option, source);
+ private Collection<IEObjectDescription> findSources(CustomOption option, OptionExtendMessageFieldSource s) {
+ return customOptionFieldScopeFinder.findScope(option, s);
}
- private Collection<IEObjectDescription> findSources(CustomFieldOption option, OptionExtendMessageFieldSource source) {
- return customOptionFieldScopeFinder.findScope(option, source);
+ private Collection<IEObjectDescription> findSources(CustomFieldOption option, OptionExtendMessageFieldSource o) {
+ return customOptionFieldScopeFinder.findScope(option, o);
}
private static IScope createScope(Iterable<IEObjectDescription> descriptions) {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Scoping.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Scoping.java
index ec65bc4..813a810 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Scoping.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Scoping.java
@@ -10,6 +10,7 @@
import com.google.eclipse.protobuf.protobuf.*;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.resource.IEObjectDescription;
import java.util.Collection;
@@ -19,20 +20,23 @@
*/
public interface Scoping {
- Collection<IEObjectDescription> findSources(CustomOption option);
+ Collection<IEObjectDescription> findScope(CustomOption o);
- Collection<IEObjectDescription> findSources(CustomFieldOption option);
+ Collection<IEObjectDescription> findScope(CustomFieldOption o);
- Collection<IEObjectDescription> findSources(OptionMessageFieldSource source);
+ Collection<IEObjectDescription> findScope(OptionMessageFieldSource s);
- Collection<IEObjectDescription> findSources(OptionExtendMessageFieldSource source);
+ Collection<IEObjectDescription> findScope(OptionExtendMessageFieldSource s);
- Collection<IEObjectDescription> findNextMessageFieldSources(CustomOption option);
+ Collection<IEObjectDescription> findMessageFieldScope(CustomOption o);
- Collection<IEObjectDescription> findNextMessageFieldSources(CustomFieldOption option);
+ Collection<IEObjectDescription> findMessageFieldScope(CustomFieldOption o);
- Collection<IEObjectDescription> findNextExtendMessageFieldSources(CustomOption option);
+ Collection<IEObjectDescription> findExtendMessageFieldScope(CustomOption o);
- Collection<IEObjectDescription> findNextExtendMessageFieldSources(CustomFieldOption option);
+ Collection<IEObjectDescription> findExtendMessageFieldScope(CustomFieldOption o);
+ Collection<IEObjectDescription> findTypeScope(EObject o);
+
+ Collection<IEObjectDescription> findMessageScope(EObject o);
}