In progress: [  Issue 51  ] 	Field options should not be hard-coded in the grammar
https://code.google.com/p/protobuf-dt/issues/detail?id=51

Added field options to descriptor.proto. Renamed Globals to Descriptor. Code cleanup.
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Globals_fileOptions_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_fileOptions_Test.java
similarity index 86%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Globals_fileOptions_Test.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_fileOptions_Test.java
index cf6b556..92b0e57 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Globals_fileOptions_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_fileOptions_Test.java
@@ -20,23 +20,23 @@
 import com.google.eclipse.protobuf.protobuf.Property;
 
 /**
- * Tests for <code>{@link Globals#fileOptions()}</code>.
+ * Tests for <code>{@link Descriptor#fileOptions()}</code>.
  *
  * @author alruiz@google.com (Alex Ruiz)
  */
-public class Globals_fileOptions_Test {
+public class Descriptor_fileOptions_Test {
 
   @Rule public XtextRule xtext = new XtextRule();
-  
-  private Globals globals;
-  
+
+  private Descriptor descriptor;
+
   @Before public void setUp() {
-    globals = xtext.getInstanceOf(Globals.class);
+    descriptor = xtext.getInstanceOf(Descriptor.class);
   }
-  
+
   @Test public void should_return_all_file_options() {
-    Map<String, Property> fileOptions = mapByName(globals.fileOptions());
-    assertThat(fileOptions.get("java_package"), hasType("string"));   
+    Map<String, Property> fileOptions = mapByName(descriptor.fileOptions());
+    assertThat(fileOptions.get("java_package"), hasType("string"));
     assertThat(fileOptions.get("java_outer_classname"), hasType("string"));
     assertThat(fileOptions.get("java_multiple_files"), hasType("bool"));
     assertThat(fileOptions.get("java_generate_equals_and_hash"), hasType("bool"));
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Globals_isOptimizeForOption_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_isOptimizeForOption_Test.java
similarity index 79%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Globals_isOptimizeForOption_Test.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_isOptimizeForOption_Test.java
index eefaf37..034ed28 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Globals_isOptimizeForOption_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_isOptimizeForOption_Test.java
@@ -19,18 +19,18 @@
 import com.google.eclipse.protobuf.protobuf.Protobuf;
 
 /**
- * Tests for <code>{@link Globals#isOptimizeForOption(Option)}</code>.
+ * Tests for <code>{@link Descriptor#isOptimizeForOption(Option)}</code>.
  *
  * @author alruiz@google.com (Alex Ruiz)
  */
-public class Globals_isOptimizeForOption_Test {
+public class Descriptor_isOptimizeForOption_Test {
 
   @Rule public XtextRule xtext = new XtextRule();
   
-  private Globals globals;
+  private Descriptor descriptor;
   
   @Before public void setUp() {
-    globals = xtext.getInstanceOf(Globals.class);
+    descriptor = xtext.getInstanceOf(Descriptor.class);
   }
   
   @Test public void should_return_true_if_option_is_OptimizeForOption() {
@@ -39,7 +39,7 @@
          .append("option optimize_for = CODE_SIZE;             "); 
     Protobuf root = xtext.parse(proto);
     Option option = findOption("optimize_for", root);
-    assertThat(globals.isOptimizeForOption(option), equalTo(true));
+    assertThat(descriptor.isOptimizeForOption(option), equalTo(true));
   }
 
   @Test public void should_return_false_if_option_is_not_OptimizeForOption() {
@@ -48,10 +48,10 @@
          .append("option optimize_for = CODE_SIZE;             "); 
     Protobuf root = xtext.parse(proto);
     Option option = findOption("java_generate_equals_and_hash", root);
-    assertThat(globals.isOptimizeForOption(option), equalTo(false));
+    assertThat(descriptor.isOptimizeForOption(option), equalTo(false));
   }
 
   @Test public void should_return_false_if_option_is_null() {
-    assertThat(globals.isOptimizeForOption(null), equalTo(false));
+    assertThat(descriptor.isOptimizeForOption(null), equalTo(false));
   }
 }
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Globals_lookupFileOption_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_lookupFileOption_Test.java
similarity index 73%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Globals_lookupFileOption_Test.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_lookupFileOption_Test.java
index 48f3038..3637168 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Globals_lookupFileOption_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_lookupFileOption_Test.java
@@ -18,26 +18,26 @@
 import com.google.eclipse.protobuf.protobuf.Property;
 
 /**
- * Tests for <code>{@link Globals#lookupFileOption(String)}</code>.
+ * Tests for <code>{@link Descriptor#lookupFileOption(String)}</code>.
  *
  * @author alruiz@google.com (Alex Ruiz)
  */
-public class Globals_lookupFileOption_Test {
+public class Descriptor_lookupFileOption_Test {
 
   @Rule public XtextRule xtext = new XtextRule();
   
-  private Globals globals;
+  private Descriptor descriptor;
   
   @Before public void setUp() {
-    globals = xtext.getInstanceOf(Globals.class);
+    descriptor = xtext.getInstanceOf(Descriptor.class);
   }
 
   @Test public void should_look_up_file_option() {
-    Property option = globals.lookupFileOption("java_multiple_files");
+    Property option = descriptor.lookupFileOption("java_multiple_files");
     assertThat(option.getName(), equalTo("java_multiple_files"));
   }
   
   @Test public void should_return_null_if_option_not_found() {
-    assertThat(globals.lookupFileOption("hello"), nullValue());
+    assertThat(descriptor.lookupFileOption("hello"), nullValue());
   }
 }
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Globals_optimizedMode_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_optimizedMode_Test.java
similarity index 80%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Globals_optimizedMode_Test.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_optimizedMode_Test.java
index a69a948..60c0e17 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Globals_optimizedMode_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_optimizedMode_Test.java
@@ -18,22 +18,22 @@
 import com.google.eclipse.protobuf.protobuf.Enum;
 
 /**
- * Tests for <code>{@link Globals#optimizedMode()}</code>.
+ * Tests for <code>{@link Descriptor#optimizedMode()}</code>.
  *
  * @author alruiz@google.com (Alex Ruiz)
  */
-public class Globals_optimizedMode_Test {
+public class Descriptor_optimizedMode_Test {
 
   @Rule public XtextRule xtext = new XtextRule();
   
-  private Globals globals;
+  private Descriptor descriptor;
   
   @Before public void setUp() {
-    globals = xtext.getInstanceOf(Globals.class);
+    descriptor = xtext.getInstanceOf(Descriptor.class);
   }
   
   @Test public void should_return_enum_OptimizeMode() {
-    Enum optimizedMode = globals.optimizedMode();
+    Enum optimizedMode = descriptor.optimizedMode();
     assertThat(optimizedMode.getName(), equalTo("OptimizeMode"));
     assertThat(optimizedMode, hasLiterals("SPEED", "CODE_SIZE", "LITE_RUNTIME"));
   }
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 dab24e0..7e5dc3d 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
@@ -25,7 +25,7 @@
 import com.google.common.collect.ImmutableList;
 import com.google.eclipse.protobuf.protobuf.*;
 import com.google.eclipse.protobuf.protobuf.Enum;
-import com.google.eclipse.protobuf.scoping.Globals;
+import com.google.eclipse.protobuf.scoping.*;
 import com.google.eclipse.protobuf.ui.grammar.*;
 import com.google.eclipse.protobuf.ui.grammar.CompoundElement;
 import com.google.eclipse.protobuf.ui.labeling.Images;
@@ -43,7 +43,7 @@
   private static final String SPACE = " ";
 
   @Inject private ProtobufElementFinder finder;
-  @Inject private Globals globals;
+  @Inject private DescriptorProvider descriptorProvider;
   @Inject private PluginImageHelper imageHelper;
   @Inject private Images imageRegistry;
   @Inject private Literals literals;
@@ -76,7 +76,7 @@
   }
 
   private void proposeCommonFileOptions(ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
-    for (Property fileOption : globals.fileOptions()) {
+    for (Property fileOption : descriptorProvider.get().fileOptions()) {
       String displayString = fileOption.getName();
       String proposalText = displayString + SPACE + EQUAL + SPACE;
       boolean isStringOption = properties.isString(fileOption);
@@ -95,10 +95,11 @@
   @Override public void completeOption_Value(EObject model, Assignment assignment, ContentAssistContext context,
       ICompletionProposalAcceptor acceptor) {
     Option option = (Option) model;
-    Property fileOption = globals.lookupFileOption(option.getName());
+    Descriptor descriptor = descriptorProvider.get();
+    Property fileOption = descriptor.lookupFileOption(option.getName());
     if (fileOption == null) return;
-    if (globals.isOptimizeForOption(option)) {
-      proposeAndAccept(globals.optimizedMode(), context, acceptor);
+    if (descriptor.isOptimizeForOption(option)) {
+      proposeAndAccept(descriptor.optimizedMode(), context, acceptor);
       return;
     }
     if (properties.isString(fileOption)) {
@@ -219,7 +220,7 @@
     EObject model = context.getCurrentModel();
     if (model instanceof Property) return properties.isBool((Property) model);
     if (model instanceof Option) {
-      Property fileOption = globals.lookupFileOption(((Option) model).getName());
+      Property fileOption = descriptorProvider.get().lookupFileOption(((Option) model).getName());
       return fileOption != null && properties.isBool(fileOption);
     }
     return false;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java
index ab59060..d247e7d 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java
@@ -11,7 +11,7 @@
 import static org.eclipse.core.runtime.IStatus.ERROR;
 import static org.eclipse.emf.common.util.URI.createURI;
 import static org.eclipse.emf.ecore.resource.ContentHandler.UNSPECIFIED_CONTENT_TYPE;
-import static org.eclipse.emf.ecore.util.EcoreUtil.resolveAll;
+import static org.eclipse.xtext.EcoreUtil2.resolveLazyCrossReferences;
 import static org.eclipse.xtext.resource.XtextResource.OPTION_ENCODING;
 import static org.eclipse.xtext.util.CancelIndicator.NullImpl;
 import static org.eclipse.xtext.validation.CheckMode.FAST_ONLY;
@@ -26,19 +26,15 @@
 import org.eclipse.jface.text.source.IAnnotationModel;
 import org.eclipse.ui.IURIEditorInput;
 import org.eclipse.ui.ide.FileStoreEditorInput;
-import org.eclipse.xtext.linking.lazy.LazyLinkingResource;
 import org.eclipse.xtext.resource.XtextResource;
-import org.eclipse.xtext.ui.editor.model.XtextDocument;
-import org.eclipse.xtext.ui.editor.model.XtextDocumentProvider;
+import org.eclipse.xtext.ui.editor.model.*;
 import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider;
-import org.eclipse.xtext.ui.editor.validation.AnnotationIssueProcessor;
-import org.eclipse.xtext.ui.editor.validation.ValidationJob;
+import org.eclipse.xtext.ui.editor.validation.*;
 import org.eclipse.xtext.ui.resource.IResourceSetProvider;
 import org.eclipse.xtext.util.StringInputStream;
 import org.eclipse.xtext.validation.IResourceValidator;
 
-import com.google.eclipse.protobuf.ui.util.Closeables;
-import com.google.eclipse.protobuf.ui.util.Resources;
+import com.google.eclipse.protobuf.ui.util.*;
 import com.google.inject.Inject;
 
 /**
@@ -149,11 +145,7 @@
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
-    if (resource instanceof LazyLinkingResource) {
-      ((LazyLinkingResource) resource).resolveLazyCrossReferences(NullImpl);
-      return resource;
-    }
-    resolveAll(resource);
+    resolveLazyCrossReferences(resource, NullImpl);
     return resource;
   }
 }
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
index d7ba443..79671cb 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
@@ -32,7 +32,7 @@
   ID ('.' ID)*;
 
 Option:
-  (('option' name=ID '=' value=ValueRef ';') | ('option' '('name=ID')' '=' value=ValueRef ';') );
+  'option' name=ID '=' value=ValueRef ';';
 
 ProtobufElement:
   Type | ExtendMessage | Service;
@@ -61,6 +61,9 @@
     | ('[' 'deprecated' '=' deprecated=BooleanRef ']')
     | ('[' 'default' '=' default=ValueRef ',' 'deprecated' '=' deprecated=BooleanRef ']') )? ';';
 
+FieldOption:
+  name=ID '=' value=ValueRef;
+
 enum Modifier:
   required
   | optional
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Globals.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Descriptor.java
similarity index 78%
rename from com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Globals.java
rename to com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Descriptor.java
index abda482..e48ed6a 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Globals.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Descriptor.java
@@ -10,28 +10,26 @@
 
 import static java.util.Collections.unmodifiableCollection;
 import static org.eclipse.emf.common.util.URI.createURI;
-import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
+import static org.eclipse.xtext.EcoreUtil2.*;
+import static org.eclipse.xtext.util.CancelIndicator.NullImpl;
 
 import java.io.*;
 import java.util.*;
 
-import org.eclipse.xtext.parser.IParseResult;
-import org.eclipse.xtext.parser.IParser;
+import org.eclipse.xtext.parser.*;
 import org.eclipse.xtext.resource.XtextResource;
 import org.eclipse.xtext.util.StringInputStream;
 
 import com.google.eclipse.protobuf.protobuf.*;
 import com.google.eclipse.protobuf.protobuf.Enum;
 import com.google.inject.Inject;
-import com.google.inject.Singleton;
 
 /**
- * Protobuf elements accessible to any .proto file.
+ * Contains the elements from descriptor.proto (provided with protobuf's library.)
  *
  * @author alruiz@google.com (Alex Ruiz)
  */
-@Singleton
-public class Globals {
+public class Descriptor {
 
   private Protobuf root;
 
@@ -39,15 +37,16 @@
   private Enum optimizedMode;
 
   /**
-   * Creates a new </code>{@link Globals}</code>.
+   * Creates a new </code>{@link Descriptor}</code>.
    * @param parser the grammar parser.
    */
-  @Inject public Globals(IParser parser) {
+  @Inject public Descriptor(IParser parser) {
     try {
-      XtextResource resource = new XtextResource(createURI("globals.proto"));
+      XtextResource resource = new XtextResource(createURI("descriptor.proto"));
       IParseResult result = parser.parse(new InputStreamReader(globalScopeContents(), "UTF-8"));
       root = (Protobuf) result.getRootASTElement();
       resource.getContents().add(root);
+      resolveLazyCrossReferences(resource, NullImpl);
       initContents();
     } catch (IOException e) {
       throw new IllegalStateException("Unable to parse global scope", e);
@@ -55,10 +54,10 @@
   }
 
   private static InputStream globalScopeContents() {
-    return new StringInputStream(globalProto());
+    return new StringInputStream(descriptorContents());
   }
 
-  private static String globalProto() {
+  private static String descriptorContents() {
     StringBuilder proto = new StringBuilder();
     proto.append("message FileOptions {")
          .append("  optional string java_package = 1;")
@@ -74,7 +73,17 @@
          .append("  optional bool cc_generic_services = 16 [default=false];")
          .append("  optional bool java_generic_services = 17 [default=false];")
          .append("  optional bool py_generic_services = 18 [default=false];")
-         .append("  repeated UninterpretedOption uninterpreted_option = 999;")
+         .append("  extensions 1000 to max;")
+         .append("}")
+         .append("message FieldOptions {")
+         .append("  optional CType ctype = 1 [default = STRING];")
+         .append("  enum CType {")
+         .append("    STRING = 0;")
+         .append("    CORD = 1;")
+         .append("    STRING_PIECE = 2;")
+         .append("  }")
+         .append("  optional bool packed = 2;")
+         .append("  optional bool deprecated = 3 [default=false];")
          .append("  extensions 1000 to max;")
          .append("}");
     return proto.toString();
@@ -93,7 +102,7 @@
       }
     }
   }
-  
+
   private boolean isOptimizeModeEnum(MessageElement e) {
     if (!(e instanceof Enum)) return false;
     Enum anEnum = (Enum) e;
@@ -111,7 +120,7 @@
   }
 
   /**
-   * Returns all the file-level options available. These are the options defined in 
+   * Returns all the file-level options available. These are the options defined in
    * {@code google/protobuf/descriptor.proto} (more details can be found
    * <a href=http://code.google.com/apis/protocolbuffers/docs/proto.html#options" target="_blank">here</a>.)
    * @return all the file-level options available.
@@ -121,8 +130,8 @@
   }
 
   /**
-   * Returns the {@code enum} "OptimizeMode" (defined in {@code google/protobuf/descriptor.proto}. More details can be 
-   * found <a href=http://code.google.com/apis/protocolbuffers/docs/proto.html#options" target="_blank">here</a>.) 
+   * Returns the {@code enum} "OptimizeMode" (defined in {@code google/protobuf/descriptor.proto}. More details can be
+   * found <a href=http://code.google.com/apis/protocolbuffers/docs/proto.html#options" target="_blank">here</a>.)
    * @return the {@code enum} "OptimizeMode."
    */
   public Enum optimizedMode() {
@@ -130,9 +139,9 @@
   }
 
   /**
-   * Indicates whether the given option is the "OptimizeMode" one (defined in {@code google/protobuf/descriptor.proto}. 
-   * More details can be found 
-   * <a href=http://code.google.com/apis/protocolbuffers/docs/proto.html#options" target="_blank">here</a>.) 
+   * Indicates whether the given option is the "OptimizeMode" one (defined in {@code google/protobuf/descriptor.proto}.
+   * More details can be found
+   * <a href=http://code.google.com/apis/protocolbuffers/docs/proto.html#options" target="_blank">here</a>.)
    * @param option the given option.
    * @return {@code true} if the given option is the "OptimizeMode" one, {@code false} otherwise.
    */
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/DescriptorProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/DescriptorProvider.java
new file mode 100644
index 0000000..edc0bb1
--- /dev/null
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/DescriptorProvider.java
@@ -0,0 +1,37 @@
+/*
+ * Created on May 30, 2011
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ *
+ * Copyright @2011 the original author or authors.
+ */
+package com.google.eclipse.protobuf.scoping;
+
+import org.eclipse.xtext.parser.IParser;
+
+import com.google.inject.*;
+
+/**
+ * Provider of a singleton instance of <code>{@link Descriptor}</code>.
+ *
+ * @author Alex Ruiz
+ */
+@Singleton
+public class DescriptorProvider implements Provider<Descriptor> {
+
+  @Inject private IParser parser;
+
+  private Descriptor descriptor;
+
+  public synchronized Descriptor get() {
+    if (descriptor == null) descriptor = new Descriptor(parser);
+    return descriptor;
+  }
+}
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 05ee91e..21bf3b6 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
@@ -14,14 +14,10 @@
 
 import java.util.*;
 
-import org.eclipse.emf.common.util.TreeIterator;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.xtext.naming.IQualifiedNameProvider;
-import org.eclipse.xtext.naming.QualifiedName;
+import org.eclipse.emf.common.util.*;
+import org.eclipse.emf.ecore.*;
+import org.eclipse.emf.ecore.resource.*;
+import org.eclipse.xtext.naming.*;
 import org.eclipse.xtext.resource.IEObjectDescription;
 import org.eclipse.xtext.scoping.IScope;
 import org.eclipse.xtext.scoping.impl.*;
@@ -43,7 +39,7 @@
   private static final boolean DO_NOT_IGNORE_CASE = false;
 
   @Inject private ProtobufElementFinder finder;
-  @Inject private Globals globals;
+  @Inject private DescriptorProvider descriptorProvider;
   @Inject private IQualifiedNameProvider nameProvider;
   @Inject private ImportUriResolver uriResolver;
   @Inject private AlternativeQualifiedNamesProvider alternativeNamesProvider;
@@ -126,8 +122,9 @@
       Enum enumType = finder.enumTypeOf((Property) container);
       if (enumType != null) return scopeForLiterals(enumType);
     }
-    if (container instanceof Option && globals.isOptimizeForOption((Option) container)) {
-      Enum optimizedMode = globals.optimizedMode();
+    Descriptor descriptor = descriptorProvider.get();
+    if (container instanceof Option && descriptor.isOptimizeForOption((Option) container)) {
+      Enum optimizedMode = descriptor.optimizedMode();
       return scopeForLiterals(optimizedMode);
     }
     return null;