Fixed: [Issue 118] Add support for spell checking
Removed spell checking from imports.
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/SmartSemicolonHandler.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/SmartSemicolonHandler.java
index c693769..dfe06d3 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/SmartSemicolonHandler.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/SmartSemicolonHandler.java
@@ -92,7 +92,7 @@
int offset = styledText.getCaretOffset();
ContentAssistContext[] context = contextFactory.create(editor.getInternalSourceViewer(), offset, resource);
for (ContentAssistContext c : context) {
- if (nodes.isCommentOrString(c.getCurrentNode())) continue;
+ if (nodes.wasCreatedByAnyCommentOrString(c.getCurrentNode())) continue;
EObject model = c.getCurrentModel();
if (model instanceof Message || model instanceof Enum || model instanceof Protobuf) {
// need to retry, parsing may not be finished yet.
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufSpelling.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufSpelling.java
index 2b482dd..70a12f4 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufSpelling.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufSpelling.java
@@ -8,11 +8,11 @@
*/
package com.google.eclipse.protobuf.ui.editor.spelling;
-import static org.eclipse.xtext.nodemodel.util.NodeModelUtils.findLeafNodeAtOffset;
-import static org.eclipse.xtext.util.Strings.isEmpty;
+import static org.eclipse.xtext.nodemodel.util.NodeModelUtils.*;
import java.util.Iterator;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.*;
import org.eclipse.jface.text.source.*;
import org.eclipse.ui.texteditor.spelling.*;
@@ -22,6 +22,7 @@
import org.eclipse.xtext.ui.editor.model.XtextDocument;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
+import com.google.eclipse.protobuf.protobuf.Import;
import com.google.eclipse.protobuf.util.ModelNodes;
/**
@@ -83,8 +84,11 @@
private boolean shouldSpellCheck(INode node) {
if (node == null) return false;
- String text = node.getText();
- if (isEmpty(text) || isEmpty(text.trim())) return false;
- return nodes.isCommentOrString(node);
+ if (nodes.wasCreatedByAnyComment(node)) return true;
+ if (nodes.wasCreatedByString(node)) {
+ EObject o = findActualSemanticObjectFor(node);
+ return !(o instanceof Import);
+ }
+ return false;
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/ModelNodes.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/ModelNodes.java
index e8c5d31..6c8fb35 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/ModelNodes.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/ModelNodes.java
@@ -47,7 +47,7 @@
* @return {@code true} if the given node was created by a string, or a single- or multi-line comment; {@code false}
* otherwise.
*/
- public boolean isCommentOrString(INode node) {
+ public boolean wasCreatedByAnyCommentOrString(INode node) {
return wasCreatedByAnyComment(node) || wasCreatedByString(node);
}
@@ -60,7 +60,12 @@
return wasCreatedByRule(node, SINGLE_LINE_COMMENT_RULE_NAME, "ML_COMMENT");
}
- private boolean wasCreatedByString(INode node) {
+ /**
+ * Indicates whether the given node was created by a string.
+ * @param node the node to check.
+ * @return {@code true} if the given node was created by a string; {@code false} otherwise.
+ */
+ public boolean wasCreatedByString(INode node) {
EObject grammarElement = node.getGrammarElement();
if (!(grammarElement instanceof RuleCall)) return false;
AbstractRule rule = ((RuleCall) grammarElement).getRule();