Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Code completion and include file creation

The plugin now offers code completion for the include tag.
It will list all .ss files it finds in Includes directories in the project.
If a file name is typed and it cannot be found a quick fix is offered that
will create the file for you in the directory of choice.
This will default to the closest Includes directory it can find based on the
current file you're in. It will look in the current dir and one dir up.
  • Loading branch information...
commit 23c1fc02db221fedf38ae7ff1f2dbad1b1710689 1 parent 7464d1d
@MarcusDalgren MarcusDalgren authored
Showing with 445 additions and 266 deletions.
  1. +3 −1 META-INF/plugin.xml
  2. +4 −1 gen/com/GeneratedParserUtilBase.java
  3. +6 −7 gen/com/raket/silverstripe/parser/SilverStripeParser.java
  4. +3 −2 gen/com/raket/silverstripe/psi/SilverStripeOuterWrapper.java
  5. +0 −2  gen/com/raket/silverstripe/psi/SilverStripeSsBadBlockStatement.java
  6. +0 −2  gen/com/raket/silverstripe/psi/SilverStripeSsBlockContinueStatement.java
  7. +0 −2  gen/com/raket/silverstripe/psi/SilverStripeSsBlockEndStatement.java
  8. +0 −2  gen/com/raket/silverstripe/psi/SilverStripeSsBlockSimpleStatement.java
  9. +0 −2  gen/com/raket/silverstripe/psi/SilverStripeSsBlockStartStatement.java
  10. +0 −2  gen/com/raket/silverstripe/psi/SilverStripeSsBlockStatement.java
  11. +0 −2  gen/com/raket/silverstripe/psi/SilverStripeSsCommentStatement.java
  12. +0 −2  gen/com/raket/silverstripe/psi/SilverStripeSsFragment.java
  13. +0 −2  gen/com/raket/silverstripe/psi/SilverStripeSsVarStatement.java
  14. +2 −3 gen/com/raket/silverstripe/psi/SilverStripeTypes.java
  15. +2 −2 gen/com/raket/silverstripe/psi/SilverStripeVisitor.java
  16. +4 −6 gen/com/raket/silverstripe/psi/impl/SilverStripeOuterWrapperImpl.java
  17. +2 −7 gen/com/raket/silverstripe/psi/impl/SilverStripeSsBadBlockStatementImpl.java
  18. +2 −7 gen/com/raket/silverstripe/psi/impl/SilverStripeSsBlockContinueStatementImpl.java
  19. +2 −7 gen/com/raket/silverstripe/psi/impl/SilverStripeSsBlockEndStatementImpl.java
  20. +2 −7 gen/com/raket/silverstripe/psi/impl/SilverStripeSsBlockSimpleStatementImpl.java
  21. +2 −7 gen/com/raket/silverstripe/psi/impl/SilverStripeSsBlockStartStatementImpl.java
  22. +2 −7 gen/com/raket/silverstripe/psi/impl/SilverStripeSsBlockStatementImpl.java
  23. +2 −7 gen/com/raket/silverstripe/psi/impl/SilverStripeSsCommentStatementImpl.java
  24. +2 −7 gen/com/raket/silverstripe/psi/impl/SilverStripeSsFragmentImpl.java
  25. +2 −7 gen/com/raket/silverstripe/psi/impl/SilverStripeSsVarStatementImpl.java
  26. BIN  idea-silverstripe.jar
  27. +2 −2 src/com/raket/silverstripe/SilverStripeLexer.java
  28. +26 −0 src/com/raket/silverstripe/editor/actions/SilverStripeTypedHandler.java
  29. +90 −0 src/com/raket/silverstripe/editor/annotations/CreateIncludeQuickFix.java
  30. +22 −30 src/com/raket/silverstripe/editor/annotations/SilverStripeIncludeAnnotator.java
  31. +1 −0  src/com/raket/silverstripe/editor/braces/SilverStripeBraceMatcher.java
  32. +43 −0 src/com/raket/silverstripe/editor/completions/SilverStripeCompletionContributor.java
  33. +5 −6 src/com/raket/silverstripe/editor/lines/SilverStripeLineMarkerProvider.java
  34. +18 −14 src/com/raket/silverstripe/file/SilverStripeFileUtil.java
  35. +9 −5 src/com/raket/silverstripe/parser/SilverStripeBaseParser.java
  36. +4 −14 src/com/raket/silverstripe/parser/SilverStripeParserDefinition.java
  37. +11 −0 src/com/raket/silverstripe/psi/SilverStripeIncludeFile.java
  38. +13 −0 src/com/raket/silverstripe/psi/SilverStripeNamedElement.java
  39. +1 −0  src/com/raket/silverstripe/psi/SilverStripeTypes.java
  40. +62 −0 src/com/raket/silverstripe/psi/impl/SilverStripeIncludeImpl.java
  41. +12 −0 src/com/raket/silverstripe/psi/impl/SilverStripeNamedElementImpl.java
  42. +64 −0 src/com/raket/silverstripe/psi/references/SilverStripeReference.java
  43. +0 −75 src/com/raket/silverstripe/references/SilverStripePsiReferenceProvider.java
  44. +20 −17 src/com/raket/silverstripe/references/SilverStripeReferenceContributor.java
View
4 META-INF/plugin.xml
@@ -94,8 +94,10 @@
<enterHandlerDelegate implementation="com.raket.silverstripe.editor.actions.SilverStripeEnterHandler"/>
<!--
<lang.syntaxHighlighterFactory key="SilverStripe" implementationClass="com.raket.silverstripe.editor.highlighting.SilverStripeSyntaxHighlighterFactory"/>
- -->
+ <psi.referenceContributor language="SilverStripe" implementation="com.raket.silverstripe.references.SilverStripeReferenceContributor"/>
+ -->
<codeInsight.lineMarkerProvider language="SilverStripe" implementationClass="com.raket.silverstripe.editor.lines.SilverStripeLineMarkerProvider"/>
+ <completion.contributor language="SilverStripe" implementationClass="com.raket.silverstripe.editor.completions.SilverStripeCompletionContributor"/>
<annotator language="SilverStripe" implementationClass="com.raket.silverstripe.editor.annotations.SilverStripeIncludeAnnotator"/>
</extensions>
</idea-plugin>
View
5 gen/com/GeneratedParserUtilBase.java
@@ -25,7 +25,10 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedList;
/**
* @author gregsh
View
13 gen/com/raket/silverstripe/parser/SilverStripeParser.java
@@ -1,17 +1,16 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.parser;
-import org.jetbrains.annotations.*;
-import com.intellij.lang.LighterASTNode;
+import com.intellij.lang.ASTNode;
import com.intellij.lang.PsiBuilder;
import com.intellij.lang.PsiBuilder.Marker;
+import com.intellij.lang.PsiParser;
import com.intellij.openapi.diagnostic.Logger;
-import static com.raket.silverstripe.psi.SilverStripeTypes.*;
-import static com.raket.silverstripe.parser.GeneratedParserUtilBase.*;
import com.intellij.psi.tree.IElementType;
-import com.intellij.lang.ASTNode;
-import com.intellij.psi.tree.TokenSet;
-import com.intellij.lang.PsiParser;
+import org.jetbrains.annotations.NotNull;
+
+import static com.raket.silverstripe.parser.GeneratedParserUtilBase.*;
+import static com.raket.silverstripe.psi.SilverStripeTypes.*;
@SuppressWarnings({"SimplifiableIfStatement", "UnusedAssignment"})
public class SilverStripeParser implements PsiParser {
View
5 gen/com/raket/silverstripe/psi/SilverStripeOuterWrapper.java
@@ -1,9 +1,10 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi;
-import java.util.List;
-import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
public interface SilverStripeOuterWrapper extends PsiElement {
View
2  gen/com/raket/silverstripe/psi/SilverStripeSsBadBlockStatement.java
@@ -1,8 +1,6 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi;
-import java.util.List;
-import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface SilverStripeSsBadBlockStatement extends PsiElement {
View
2  gen/com/raket/silverstripe/psi/SilverStripeSsBlockContinueStatement.java
@@ -1,8 +1,6 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi;
-import java.util.List;
-import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface SilverStripeSsBlockContinueStatement extends PsiElement {
View
2  gen/com/raket/silverstripe/psi/SilverStripeSsBlockEndStatement.java
@@ -1,8 +1,6 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi;
-import java.util.List;
-import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface SilverStripeSsBlockEndStatement extends PsiElement {
View
2  gen/com/raket/silverstripe/psi/SilverStripeSsBlockSimpleStatement.java
@@ -1,8 +1,6 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi;
-import java.util.List;
-import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface SilverStripeSsBlockSimpleStatement extends PsiElement {
View
2  gen/com/raket/silverstripe/psi/SilverStripeSsBlockStartStatement.java
@@ -1,8 +1,6 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi;
-import java.util.List;
-import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface SilverStripeSsBlockStartStatement extends PsiElement {
View
2  gen/com/raket/silverstripe/psi/SilverStripeSsBlockStatement.java
@@ -1,8 +1,6 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi;
-import java.util.List;
-import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface SilverStripeSsBlockStatement extends PsiElement {
View
2  gen/com/raket/silverstripe/psi/SilverStripeSsCommentStatement.java
@@ -1,8 +1,6 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi;
-import java.util.List;
-import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface SilverStripeSsCommentStatement extends PsiElement {
View
2  gen/com/raket/silverstripe/psi/SilverStripeSsFragment.java
@@ -1,8 +1,6 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi;
-import java.util.List;
-import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface SilverStripeSsFragment extends PsiElement {
View
2  gen/com/raket/silverstripe/psi/SilverStripeSsVarStatement.java
@@ -1,8 +1,6 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi;
-import java.util.List;
-import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface SilverStripeSsVarStatement extends PsiElement {
View
5 gen/com/raket/silverstripe/psi/SilverStripeTypes.java
@@ -1,10 +1,9 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi;
-import com.intellij.psi.tree.IElementType;
-import com.intellij.psi.PsiElement;
import com.intellij.lang.ASTNode;
-import com.raket.silverstripe.psi.impl.*;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.tree.IElementType;
public interface SilverStripeTypes {
View
4 gen/com/raket/silverstripe/psi/SilverStripeVisitor.java
@@ -1,9 +1,9 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi;
-import org.jetbrains.annotations.*;
-import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiElementVisitor;
+import org.jetbrains.annotations.NotNull;
public class SilverStripeVisitor extends PsiElementVisitor {
View
10 gen/com/raket/silverstripe/psi/impl/SilverStripeOuterWrapperImpl.java
@@ -1,15 +1,13 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi.impl;
-import java.util.List;
-import org.jetbrains.annotations.*;
+import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
-import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
-import static com.raket.silverstripe.psi.SilverStripeTypes.*;
-import com.intellij.extapi.psi.ASTWrapperPsiElement;
-import com.raket.silverstripe.psi.*;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
public class SilverStripeOuterWrapperImpl extends ASTWrapperPsiElement implements SilverStripeOuterWrapper {
View
9 gen/com/raket/silverstripe/psi/impl/SilverStripeSsBadBlockStatementImpl.java
@@ -1,15 +1,10 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi.impl;
-import java.util.List;
-import org.jetbrains.annotations.*;
+import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
-import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
-import com.intellij.psi.util.PsiTreeUtil;
-import static com.raket.silverstripe.psi.SilverStripeTypes.*;
-import com.intellij.extapi.psi.ASTWrapperPsiElement;
-import com.raket.silverstripe.psi.*;
+import org.jetbrains.annotations.NotNull;
public class SilverStripeSsBadBlockStatementImpl extends ASTWrapperPsiElement implements SilverStripeSsBadBlockStatement {
View
9 gen/com/raket/silverstripe/psi/impl/SilverStripeSsBlockContinueStatementImpl.java
@@ -1,15 +1,10 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi.impl;
-import java.util.List;
-import org.jetbrains.annotations.*;
+import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
-import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
-import com.intellij.psi.util.PsiTreeUtil;
-import static com.raket.silverstripe.psi.SilverStripeTypes.*;
-import com.intellij.extapi.psi.ASTWrapperPsiElement;
-import com.raket.silverstripe.psi.*;
+import org.jetbrains.annotations.NotNull;
public class SilverStripeSsBlockContinueStatementImpl extends ASTWrapperPsiElement implements SilverStripeSsBlockContinueStatement {
View
9 gen/com/raket/silverstripe/psi/impl/SilverStripeSsBlockEndStatementImpl.java
@@ -1,15 +1,10 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi.impl;
-import java.util.List;
-import org.jetbrains.annotations.*;
+import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
-import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
-import com.intellij.psi.util.PsiTreeUtil;
-import static com.raket.silverstripe.psi.SilverStripeTypes.*;
-import com.intellij.extapi.psi.ASTWrapperPsiElement;
-import com.raket.silverstripe.psi.*;
+import org.jetbrains.annotations.NotNull;
public class SilverStripeSsBlockEndStatementImpl extends ASTWrapperPsiElement implements SilverStripeSsBlockEndStatement {
View
9 gen/com/raket/silverstripe/psi/impl/SilverStripeSsBlockSimpleStatementImpl.java
@@ -1,15 +1,10 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi.impl;
-import java.util.List;
-import org.jetbrains.annotations.*;
+import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
-import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
-import com.intellij.psi.util.PsiTreeUtil;
-import static com.raket.silverstripe.psi.SilverStripeTypes.*;
-import com.intellij.extapi.psi.ASTWrapperPsiElement;
-import com.raket.silverstripe.psi.*;
+import org.jetbrains.annotations.NotNull;
public class SilverStripeSsBlockSimpleStatementImpl extends ASTWrapperPsiElement implements SilverStripeSsBlockSimpleStatement {
View
9 gen/com/raket/silverstripe/psi/impl/SilverStripeSsBlockStartStatementImpl.java
@@ -1,15 +1,10 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi.impl;
-import java.util.List;
-import org.jetbrains.annotations.*;
+import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
-import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
-import com.intellij.psi.util.PsiTreeUtil;
-import static com.raket.silverstripe.psi.SilverStripeTypes.*;
-import com.intellij.extapi.psi.ASTWrapperPsiElement;
-import com.raket.silverstripe.psi.*;
+import org.jetbrains.annotations.NotNull;
public class SilverStripeSsBlockStartStatementImpl extends ASTWrapperPsiElement implements SilverStripeSsBlockStartStatement {
View
9 gen/com/raket/silverstripe/psi/impl/SilverStripeSsBlockStatementImpl.java
@@ -1,15 +1,10 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi.impl;
-import java.util.List;
-import org.jetbrains.annotations.*;
+import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
-import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
-import com.intellij.psi.util.PsiTreeUtil;
-import static com.raket.silverstripe.psi.SilverStripeTypes.*;
-import com.intellij.extapi.psi.ASTWrapperPsiElement;
-import com.raket.silverstripe.psi.*;
+import org.jetbrains.annotations.NotNull;
public class SilverStripeSsBlockStatementImpl extends ASTWrapperPsiElement implements SilverStripeSsBlockStatement {
View
9 gen/com/raket/silverstripe/psi/impl/SilverStripeSsCommentStatementImpl.java
@@ -1,15 +1,10 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi.impl;
-import java.util.List;
-import org.jetbrains.annotations.*;
+import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
-import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
-import com.intellij.psi.util.PsiTreeUtil;
-import static com.raket.silverstripe.psi.SilverStripeTypes.*;
-import com.intellij.extapi.psi.ASTWrapperPsiElement;
-import com.raket.silverstripe.psi.*;
+import org.jetbrains.annotations.NotNull;
public class SilverStripeSsCommentStatementImpl extends ASTWrapperPsiElement implements SilverStripeSsCommentStatement {
View
9 gen/com/raket/silverstripe/psi/impl/SilverStripeSsFragmentImpl.java
@@ -1,15 +1,10 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi.impl;
-import java.util.List;
-import org.jetbrains.annotations.*;
+import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
-import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
-import com.intellij.psi.util.PsiTreeUtil;
-import static com.raket.silverstripe.psi.SilverStripeTypes.*;
-import com.intellij.extapi.psi.ASTWrapperPsiElement;
-import com.raket.silverstripe.psi.*;
+import org.jetbrains.annotations.NotNull;
public class SilverStripeSsFragmentImpl extends ASTWrapperPsiElement implements SilverStripeSsFragment {
View
9 gen/com/raket/silverstripe/psi/impl/SilverStripeSsVarStatementImpl.java
@@ -1,15 +1,10 @@
// This is a generated file. Not intended for manual editing.
package com.raket.silverstripe.psi.impl;
-import java.util.List;
-import org.jetbrains.annotations.*;
+import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
-import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
-import com.intellij.psi.util.PsiTreeUtil;
-import static com.raket.silverstripe.psi.SilverStripeTypes.*;
-import com.intellij.extapi.psi.ASTWrapperPsiElement;
-import com.raket.silverstripe.psi.*;
+import org.jetbrains.annotations.NotNull;
public class SilverStripeSsVarStatementImpl extends ASTWrapperPsiElement implements SilverStripeSsVarStatement {
View
BIN  idea-silverstripe.jar
Binary file not shown
View
4 src/com/raket/silverstripe/SilverStripeLexer.java
@@ -1,4 +1,4 @@
-/* The following code was generated by JFlex 1.4.3 on 2013-03-31 22:12 */
+/* The following code was generated by JFlex 1.4.3 on 2013-04-01 22:36 */
package com.raket.silverstripe;
@@ -17,7 +17,7 @@
/**
* This class is a scanner generated by
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3
- * on 2013-03-31 22:12 from the specification file
+ * on 2013-04-01 22:36 from the specification file
* <tt>C:/IdeaProjects/idea-silverstripe/src/com/raket/silverstripe/SilverStripe.flex</tt>
*/
public class SilverStripeLexer implements FlexLexer {
View
26 src/com/raket/silverstripe/editor/actions/SilverStripeTypedHandler.java
@@ -29,6 +29,20 @@
* To change this template use File | Settings | File Templates.
*/
public class SilverStripeTypedHandler extends TypedHandlerDelegate {
+ /*
+ @Override
+ public Result checkAutoPopup(char charTyped, Project project, Editor editor, PsiFile file) {
+ //if (!(file instanceof SilverStripeFile)) return Result.CONTINUE;
+ int offset = editor.getCaretModel().getOffset();
+
+ String isInclude = editor.getDocument().getText(new TextRange(offset - 9, offset -1));
+ if (isInclude.equals("include")) {
+ CompletionAutoPopupHandler.invokeCompletion(CompletionType.BASIC, true, project, editor, 0, false);
+ return Result.STOP;
+ }
+
+ return Result.CONTINUE;
+ }*/
@Override
public TypedHandlerDelegate.Result charTyped(char c, Project project, Editor editor, @NotNull PsiFile file) {
@@ -40,6 +54,7 @@
}
String previousChar = editor.getDocument().getText(new TextRange(offset - 2, offset - 1));
+ String isInclude = editor.getDocument().getText(new TextRange(offset - 8, offset - 1));
if (file.getViewProvider() instanceof SilverStripeFileViewProvider) {
// if we're looking at a close stache, we may have some business too attend to
@@ -47,6 +62,17 @@
autoInsertCloseTag(project, offset, editor, provider);
adjustMustacheFormatting(project, offset, editor, file, provider);
}
+
+ if (c == '%' && previousChar.equals("<")) {
+
+ }
+ if (isInclude.equals("include")) { /*
+ ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(file.getVirtualFile());
+ CodeCompletionHandlerBase codeCompleter = new CodeCompletionHandlerBase(CompletionType.BASIC);
+ codeCompleter.invokeCompletion(project, editor); */
+ }
+ /*
+ EditorEventMulticaster.add */
}
return TypedHandlerDelegate.Result.CONTINUE;
View
90 src/com/raket/silverstripe/editor/annotations/CreateIncludeQuickFix.java
@@ -0,0 +1,90 @@
+package com.raket.silverstripe.editor.annotations;
+
+import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.fileChooser.FileChooser;
+import com.intellij.openapi.fileChooser.FileChooserDescriptor;
+import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
+import com.intellij.openapi.fileEditor.FileEditorManager;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.PsiDirectory;
+import com.intellij.psi.PsiFile;
+import com.intellij.util.IncorrectOperationException;
+import com.raket.silverstripe.file.SilverStripeFileType;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.IOException;
+
+public class CreateIncludeQuickFix extends BaseIntentionAction {
+ private String key;
+
+ CreateIncludeQuickFix(String key) {
+ this.key = key;
+ }
+
+ @NotNull
+ @Override
+ public String getText() {
+ return "Create Include File";
+ }
+
+ @NotNull
+ @Override
+ public String getFamilyName() {
+ return "Include Files";
+ }
+
+ @Override
+ public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
+ return true;
+ }
+
+ @Override
+ public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
+ ApplicationManager.getApplication().invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ final VirtualFile currentFile = file.getVirtualFile();
+ PsiDirectory currentDir = file.getContainingDirectory();
+ PsiDirectory includeDir = currentDir.findSubdirectory("Includes");
+ VirtualFile selectDir = null;
+ if (includeDir == null) {
+ PsiDirectory parentDir = currentDir.getParentDirectory();
+ if (parentDir != null) {
+ includeDir = parentDir.findSubdirectory("Includes");
+ currentDir = parentDir;
+ }
+ }
+ if (includeDir != null)
+ selectDir = includeDir.getVirtualFile();
+
+ final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
+ descriptor.setRoots(currentDir.getVirtualFile());
+ final VirtualFile myFolder = FileChooser.chooseFile(descriptor, project, selectDir);
+
+ if (myFolder != null) {
+
+ ApplicationManager.getApplication().runWriteAction(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ VirtualFile createdFile = myFolder.createChildData(this, key+"."+SilverStripeFileType.DEFAULT_EXTENSION);
+ FileEditorManager.getInstance(project).openFile(createdFile, false);
+ // Move back focus to the original file
+ FileEditorManager.getInstance(project).openFile(currentFile, true);
+ //OpenFileDescriptor editorOpenFile = new OpenFileDescriptor(project, createdFile, 0);
+ /*
+ PsiFileFactory.getInstance(project).
+ createFileFromText(key, SilverStripeFileType.INSTANCE, "");*/
+ } catch (IOException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+ });
+ }
+ }
+ });
+ }
+}
View
52 src/com/raket/silverstripe/editor/annotations/SilverStripeIncludeAnnotator.java
@@ -1,51 +1,43 @@
package com.raket.silverstripe.editor.annotations;
-import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.lang.annotation.Annotation;
import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.lang.annotation.Annotator;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.SyntaxHighlighterColors;
import com.intellij.openapi.editor.colors.CodeInsightColors;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
-import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
-import com.intellij.psi.PsiLiteralExpression;
-import com.intellij.psi.tree.IElementType;
-import com.intellij.util.IncorrectOperationException;
import com.raket.silverstripe.file.SilverStripeFileUtil;
import com.raket.silverstripe.psi.SilverStripeFile;
-import com.raket.silverstripe.psi.SilverStripePsiElement;
-import static com.raket.silverstripe.psi.SilverStripeTypes.*;
-import static com.raket.silverstripe.SilverStripeBundle.message;
+import com.raket.silverstripe.psi.impl.SilverStripeIncludeImpl;
import org.jetbrains.annotations.NotNull;
import java.util.List;
+
+import static com.raket.silverstripe.SilverStripeBundle.message;
public class SilverStripeIncludeAnnotator implements Annotator {
@Override
public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) {
- if (element instanceof SilverStripePsiElement) {
- SilverStripePsiElement ssElement = (SilverStripePsiElement) element;
- IElementType nodeType = ssElement.getNode().getElementType();
- if (nodeType == SS_INCLUDE_FILE) {
- String fileName = ssElement.getText();
- Project project = element.getProject();
- PsiFile currentFile = ssElement.getContainingFile();
- String fileExtension = currentFile.getFileType().getDefaultExtension();
- String fullFileName = fileName + "." + fileExtension;
- List<SilverStripeFile> properties = SilverStripeFileUtil.findFiles(project, fullFileName);
- TextRange range = new TextRange(element.getTextRange().getStartOffset(),
- element.getTextRange().getStartOffset());
- if (properties.size() >= 1) {
- Annotation annotation = holder.createInfoAnnotation(ssElement.getNode(), null);
- //annotation.setTextAttributes(SyntaxHighlighterColors.LINE_COMMENT);
- }
- if (properties.size() == 0) {
- Annotation annotation = holder.createErrorAnnotation(ssElement.getNode(), message("ss.annotations.file.not.found", fullFileName));
- annotation.setTextAttributes(CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
- }
+ if (element instanceof SilverStripeIncludeImpl) {
+ SilverStripeIncludeImpl ssElement = (SilverStripeIncludeImpl) element;
+ String fileName = ssElement.getName();
+ Project project = element.getProject();
+ PsiFile currentFile = ssElement.getContainingFile();
+ String fileExtension = currentFile.getFileType().getDefaultExtension();
+ String fullFileName = fileName + "." + fileExtension;
+ List<SilverStripeFile> properties = SilverStripeFileUtil.findFiles(project, fullFileName);
+ TextRange range = new TextRange(element.getTextRange().getStartOffset(),
+ element.getTextRange().getStartOffset());
+ if (properties.size() >= 1) {
+ Annotation annotation = holder.createInfoAnnotation(ssElement.getNode(), null);
+ //annotation.setTextAttributes(SyntaxHighlighterColors.LINE_COMMENT);
+ }
+ if (properties.size() == 0) {
+ Annotation annotation = holder
+ .createErrorAnnotation(ssElement.getNameIdentifier(), message("ss.annotations.file.not.found", fullFileName));
+ annotation.setTextAttributes(CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
+ annotation.registerFix(new CreateIncludeQuickFix(fileName));
}
}
}
View
1  src/com/raket/silverstripe/editor/braces/SilverStripeBraceMatcher.java
@@ -39,6 +39,7 @@
private static final TokenSet ALWAYS_BRACES = TokenSet.create(
SS_SIMPLE_KEYWORD,
+ SS_INCLUDE_KEYWORD,
SS_ELSE_KEYWORD,
SS_BAD_BLOCK_STATEMENT,
SS_TRANSLATION_CONTENT,
View
43 src/com/raket/silverstripe/editor/completions/SilverStripeCompletionContributor.java
@@ -0,0 +1,43 @@
+package com.raket.silverstripe.editor.completions;
+
+import com.intellij.codeInsight.completion.*;
+import com.intellij.codeInsight.lookup.LookupElementBuilder;
+import com.intellij.openapi.project.Project;
+import com.intellij.patterns.PlatformPatterns;
+import com.intellij.psi.PsiFile;
+import com.intellij.util.ProcessingContext;
+import com.raket.silverstripe.SilverStripeLanguage;
+import com.raket.silverstripe.file.SilverStripeFileType;
+import com.raket.silverstripe.file.SilverStripeFileUtil;
+import com.raket.silverstripe.psi.SilverStripeFile;
+import com.raket.silverstripe.psi.SilverStripeTypes;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+
+public class SilverStripeCompletionContributor extends CompletionContributor {
+ public SilverStripeCompletionContributor() {
+ extend(CompletionType.BASIC,
+ PlatformPatterns.psiElement(SilverStripeTypes.SS_INCLUDE_FILE).withLanguage(SilverStripeLanguage.INSTANCE),
+ new CompletionProvider<CompletionParameters>() {
+ public void addCompletions(@NotNull CompletionParameters parameters,
+ ProcessingContext context,
+ @NotNull CompletionResultSet resultSet) {
+ PsiFile currentFile = parameters.getOriginalFile();
+ Project project = currentFile.getProject();
+ List<SilverStripeFile> files = SilverStripeFileUtil.findFilesByDir(project, "Includes");
+ for (SilverStripeFile file : files) {
+ String fileName = file.getName();
+ fileName = fileName.substring(0, fileName.length()-3);
+ resultSet.addElement(LookupElementBuilder.create(" "+fileName).withIcon(SilverStripeFileType.FILE_ICON)
+ .withTypeText(file.getName()));
+ }
+ }
+ }
+ );
+ }
+
+ public void fillCompletionVariants(final CompletionParameters parameters, CompletionResultSet result) {
+ super.fillCompletionVariants(parameters, result);
+ }
+}
View
11 src/com/raket/silverstripe/editor/lines/SilverStripeLineMarkerProvider.java
@@ -10,7 +10,6 @@
import com.raket.silverstripe.file.SilverStripeFileType;
import com.raket.silverstripe.file.SilverStripeFileUtil;
import com.raket.silverstripe.psi.SilverStripeFile;
-import com.raket.silverstripe.psi.SilverStripePsiElement;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@@ -21,13 +20,13 @@
public class SilverStripeLineMarkerProvider extends RelatedItemLineMarkerProvider {
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, Collection<? super RelatedItemLineMarkerInfo> result) {
- if (element instanceof SilverStripePsiElement) {
- SilverStripePsiElement ssElement = (SilverStripePsiElement) element;
- IElementType nodeType = ssElement.getNode().getElementType();
+ if (element instanceof PsiElement) {
+ //SilverStripePsiElement ssElement = (SilverStripePsiElement) element;
+ IElementType nodeType = element.getNode().getElementType();
if (nodeType == SS_INCLUDE_FILE) {
- String fileName = ssElement.getText();
+ String fileName = element.getText();
Project project = element.getProject();
- PsiFile currentFile = ssElement.getContainingFile();
+ PsiFile currentFile = element.getContainingFile();
String fileExtension = currentFile.getFileType().getDefaultExtension();
final List<SilverStripeFile> properties = SilverStripeFileUtil.findFiles(project, fileName+"."+fileExtension);
if (properties.size() > 0) {
View
32 src/com/raket/silverstripe/file/SilverStripeFileUtil.java
@@ -15,22 +15,14 @@
public class SilverStripeFileUtil {
public static List<SilverStripeFile> findFiles(Project project, String key) {
- List<SilverStripeFile> result = null;
- Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SilverStripeFileType.INSTANCE,
- GlobalSearchScope.allScope(project));
- for (VirtualFile virtualFile : virtualFiles) {
- SilverStripeFile simpleFile = (SilverStripeFile) PsiManager.getInstance(project).findFile(virtualFile);
- String fileName = simpleFile.getName();
- if (simpleFile != null) {
- if (result == null) {
- result = new ArrayList<SilverStripeFile>();
- }
- if (simpleFile.getName().matches(key)) {
- result.add(simpleFile);
- }
+ List<SilverStripeFile> result = new ArrayList<SilverStripeFile>();
+ List<SilverStripeFile> files = findFiles(project);
+ for (SilverStripeFile file : files) {
+ if (file.getName().matches(key)) {
+ result.add(file);
}
}
- return result != null ? result : Collections.<SilverStripeFile>emptyList();
+ return result;
}
public static List<SilverStripeFile> findFiles(Project project) {
@@ -45,4 +37,16 @@
}
return result;
}
+
+ public static List<SilverStripeFile> findFilesByDir(Project project, String key) {
+ List<SilverStripeFile> result = new ArrayList<SilverStripeFile>();
+ List<SilverStripeFile> files = findFiles(project);
+ for (SilverStripeFile file : files) {
+ if (file.getContainingDirectory().getName().matches(key)) {
+ result.add(file);
+ }
+ }
+ return result;
+ }
+
}
View
14 src/com/raket/silverstripe/parser/SilverStripeBaseParser.java
@@ -284,13 +284,17 @@ else if (nextToken == SS_END_KEYWORD && endingToken == SS_BLOCK_END) {
errorMessage = message("ss.parsing.unexpected.end.statement");
}
}
+ else if (nextToken == SS_INCLUDE_KEYWORD) {
+ IElementType[] tokensToConsume = {SS_BLOCK_START, nextToken, SS_INCLUDE_FILE, SS_BLOCK_END};
+ result = createBlock(builder, SS_INCLUDE_STATEMENT, tokensToConsume, TokenSet.create());
+ }
+
else if (nextToken == SS_SIMPLE_KEYWORD) {
- //builder.remapCurrentToken(SS_BLOCK_SIMPLE_START);
- IElementType[] tokensToConsume = {SS_BLOCK_START, SS_SIMPLE_KEYWORD, SS_BLOCK_VAR, SS_BLOCK_END};
+ IElementType[] tokensToConsume = {SS_BLOCK_START, nextToken, SS_BLOCK_VAR, SS_BLOCK_END};
result = createBlock(builder, SS_BLOCK_SIMPLE_STATEMENT, tokensToConsume, TokenSet.create(SS_BLOCK_VAR));
}
else if (nextToken == SS_BAD_BLOCK_STATEMENT) {
- IElementType[] tokensToConsume = {SS_BLOCK_START, SS_BAD_BLOCK_STATEMENT, SS_BLOCK_END};
+ IElementType[] tokensToConsume = {SS_BLOCK_START, nextToken, SS_BLOCK_END};
result = createBlock(builder, SS_BAD_BLOCK, tokensToConsume, TokenSet.create());
}
else if (nextToken == SS_TRANSLATION_CONTENT) {
@@ -434,9 +438,9 @@ private void consumeToken(PsiBuilder builder, IElementType token) {
errorMarker.error(ERROR_TOKEN_MESSAGES.get(token));
}
else {
- PsiBuilder.Marker tokenMarker = builder.mark();
+// PsiBuilder.Marker tokenMarker = builder.mark();
builder.advanceLexer();
- tokenMarker.done(token);
+// tokenMarker.done(token);
}
if (!blockLevelStack.isEmpty()) {
blockLevelStack.peek().hasContent = true;
View
18 src/com/raket/silverstripe/parser/SilverStripeParserDefinition.java
@@ -11,6 +11,7 @@
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.TokenType;
+import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.IFileElementType;
import com.intellij.psi.tree.TokenSet;
import com.raket.silverstripe.SilverStripeLanguage;
@@ -18,6 +19,7 @@
import com.raket.silverstripe.psi.SilverStripeFile;
import com.raket.silverstripe.psi.SilverStripePsiElement;
import com.raket.silverstripe.psi.SilverStripeTypes;
+import com.raket.silverstripe.psi.impl.SilverStripeIncludeImpl;
import org.jetbrains.annotations.NotNull;
import java.io.Reader;
@@ -70,22 +72,10 @@ public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode r
@NotNull
public PsiElement createElement(ASTNode node) {
- /*
- return SilverStripeTypes.Factory.createElement(node);
IElementType type = node.getElementType();
- if (type == SilverStripeTypes.OUTER_WRAPPER) {
- return new SilverStripeOuterWrapperImpl(node);
+ if (type == SilverStripeTypes.SS_INCLUDE_STATEMENT) {
+ return new SilverStripeIncludeImpl(node);
}
- else if (type == SilverStripeTypes.SS_BLOCK_END_STATEMENT) {
- return new SilverStripeSsBlockEndStatementImpl(node);
- }
- else if (type == SilverStripeTypes.SS_BLOCK_SIMPLE_STATEMENT) {
- return new SilverStripeSsBlockSimpleStatementImpl(node);
- }
- else if (type == SilverStripeTypes.SS_BLOCK_START_STATEMENT) {
- return new SilverStripeSsBlockStartStatementImpl(node);
- }
- */
return new SilverStripePsiElement(node);
}
}
View
11 src/com/raket/silverstripe/psi/SilverStripeIncludeFile.java
@@ -0,0 +1,11 @@
+package com.raket.silverstripe.psi;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: Marcus Dalgren
+ * Date: 2013-04-01
+ * Time: 01:44
+ * To change this template use File | Settings | File Templates.
+ */
+public interface SilverStripeIncludeFile extends SilverStripeNamedElement {
+}
View
13 src/com/raket/silverstripe/psi/SilverStripeNamedElement.java
@@ -0,0 +1,13 @@
+package com.raket.silverstripe.psi;
+
+import com.intellij.psi.PsiNameIdentifierOwner;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: Marcus Dalgren
+ * Date: 2013-04-01
+ * Time: 01:24
+ * To change this template use File | Settings | File Templates.
+ */
+public interface SilverStripeNamedElement extends PsiNameIdentifierOwner {
+}
View
1  src/com/raket/silverstripe/psi/SilverStripeTypes.java
@@ -19,6 +19,7 @@
IElementType SS_ELSE_STATEMENT = new SilverStripeElementType("SS_ELSE_STATEMENT");
IElementType SS_TRANSLATION_STATEMENT = new SilverStripeElementType("SS_TRANSLATION_STATEMENT");
IElementType SS_STATEMENTS = new SilverStripeElementType("SS_STATEMENTS");
+ IElementType SS_INCLUDE_STATEMENT = new SilverStripeElementType("SS_INCLUDE_STATEMENT");
IElementType COMMENT = new SilverStripeTokenType("COMMENT");
IElementType CONTENT = new SilverStripeTokenType("CONTENT");
View
62 src/com/raket/silverstripe/psi/impl/SilverStripeIncludeImpl.java
@@ -0,0 +1,62 @@
+package com.raket.silverstripe.psi.impl;
+
+import com.intellij.lang.ASTNode;
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import com.raket.silverstripe.psi.SilverStripeNamedElement;
+import com.raket.silverstripe.psi.SilverStripeTypes;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public class SilverStripeIncludeImpl extends SilverStripeNamedElementImpl implements SilverStripeNamedElement {
+
+ public SilverStripeIncludeImpl(@NotNull ASTNode node) {
+ super(node);
+ }
+
+ @Nullable
+ @Override
+ public PsiElement getNameIdentifier() {
+ ASTNode keyNode = this.getNode().findChildByType(SilverStripeTypes.SS_INCLUDE_FILE);
+ if (keyNode != null) {
+ return keyNode.getPsi();
+ } else {
+ return null;
+ }
+ }
+
+ public String getName() {
+ ASTNode keyNode = this.getNode().findChildByType(SilverStripeTypes.SS_INCLUDE_FILE);
+ if (keyNode != null) {
+ return keyNode.getText();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
+ return this;
+ }
+
+ /*
+ @Override
+ public PsiReference[] getReferences() {
+ Project project = getProject();
+ String key = this.getName();
+ final List<SilverStripeFile> properties = SilverStripeFileUtil.findFiles(project, key+"."+ SilverStripeFileType.DEFAULT_EXTENSION);
+ List<PsiReference> results = new ArrayList<PsiReference>();
+ for (SilverStripeFile property : properties) {
+ results.add(new SilverStripeReference(property, new TextRange(0, property.getTextLength())));
+ }
+ PsiReference[] returnValues = results.toArray(new PsiReference[results.size()]);
+ return results.toArray(new PsiReference[results.size()]);
+ }
+
+ @Override
+ public PsiReference getReference() {
+ PsiReference[] resolveResults = getReferences();
+ return resolveResults.length == 1 ? resolveResults[0] : null;
+ }*/
+}
View
12 src/com/raket/silverstripe/psi/impl/SilverStripeNamedElementImpl.java
@@ -0,0 +1,12 @@
+package com.raket.silverstripe.psi.impl;
+
+import com.intellij.extapi.psi.ASTWrapperPsiElement;
+import com.intellij.lang.ASTNode;
+import com.raket.silverstripe.psi.SilverStripeNamedElement;
+import org.jetbrains.annotations.NotNull;
+
+public abstract class SilverStripeNamedElementImpl extends ASTWrapperPsiElement implements SilverStripeNamedElement {
+ public SilverStripeNamedElementImpl(@NotNull ASTNode node) {
+ super(node);
+ }
+}
View
64 src/com/raket/silverstripe/psi/references/SilverStripeReference.java
@@ -0,0 +1,64 @@
+package com.raket.silverstripe.psi.references;
+
+import com.intellij.codeInsight.lookup.LookupElement;
+import com.intellij.codeInsight.lookup.LookupElementBuilder;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.TextRange;
+import com.intellij.psi.*;
+import com.raket.silverstripe.file.SilverStripeFileType;
+import com.raket.silverstripe.file.SilverStripeFileUtil;
+import com.raket.silverstripe.psi.SilverStripeFile;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SilverStripeReference extends PsiReferenceBase<PsiElement> implements PsiPolyVariantReference {
+ private String key;
+
+ public SilverStripeReference(@NotNull PsiElement element, TextRange textRange) {
+ super(element, textRange);
+ key = element.getText();
+ }
+
+ public SilverStripeReference(@NotNull PsiElement element) {
+ super(element);
+ key = element.getText();
+ }
+
+ @NotNull
+ @Override
+ public ResolveResult[] multiResolve(boolean incompleteCode) {
+
+ Project project = myElement.getProject();
+ final List<SilverStripeFile> properties = SilverStripeFileUtil.findFiles(project, key+".ss");
+ List<ResolveResult> results = new ArrayList<ResolveResult>();
+ for (SilverStripeFile property : properties) {
+ results.add(new PsiElementResolveResult(property));
+ }
+ return results.toArray(new ResolveResult[results.size()]);
+ }
+
+ @Nullable
+ @Override
+ public PsiElement resolve() {
+ ResolveResult[] resolveResults = multiResolve(false);
+ return resolveResults.length == 1 ? resolveResults[0].getElement() : null;
+ }
+
+ @NotNull
+ @Override
+ public Object[] getVariants() {
+ Project project = myElement.getProject();
+ List<SilverStripeFile> properties = SilverStripeFileUtil.findFiles(project);
+ List<LookupElement> variants = new ArrayList<LookupElement>();
+ for (final SilverStripeFile property : properties) {
+ variants.add(LookupElementBuilder.create(property).
+ withIcon(SilverStripeFileType.FILE_ICON).
+ withTypeText(property.getContainingFile().getName())
+ );
+ }
+ return variants.toArray();
+ }
+}
View
75 src/com/raket/silverstripe/references/SilverStripePsiReferenceProvider.java
@@ -1,75 +0,0 @@
-package com.raket.silverstripe.references;
-
-import com.intellij.ide.util.PropertiesComponent;
-import com.intellij.openapi.project.Project;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiFile;
-import com.intellij.psi.PsiReference;
-import com.intellij.psi.PsiReferenceProvider;
-import com.intellij.util.ProcessingContext;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * Created with IntelliJ IDEA.
- * User: Marcus Dalgren
- * Date: 2013-03-30
- * Time: 21:42
- * To change this template use File | Settings | File Templates.
- */
-public class SilverStripePsiReferenceProvider extends PsiReferenceProvider {
-
- public static final PsiReferenceProvider[] EMPTY_ARRAY = new PsiReferenceProvider[0];
- public static String projectPath;
- public static Project project;
- public static PropertiesComponent properties;
-
- public SilverStripePsiReferenceProvider() {
- }
-
- /**
- * Return reference or empty array
- *
- * @param element PsiElement
- * @param context ProcessingContext
- * @return PsiReference[]
- */
- @NotNull
- @Override
- public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
- project = element.getProject();
- String elname = element.getClass().getName();
- properties = PropertiesComponent.getInstance(project);
- if (elname.endsWith("StringLiteralExpressionImpl")) {
-
- try {
- PsiFile file = element.getContainingFile();
- String path = file.getVirtualFile().getPath();
- projectPath = project.getBasePath().replace("\\", "/");
- /*
- int ProviderType = YiiRefsHelper.getYiiObjectType(path, element);
- switch (ProviderType) {
- case YiiRefsHelper.YII_TYPE_CONTROLLER_TO_VIEW_RENDER:
- return ControllerRenderViewReferenceProvider.getReference(path, element);
- case YiiRefsHelper.YII_TYPE_AR_RELATION:
- return ARRelationReferenceProvider.getReference(path, element);
- case YiiRefsHelper.YII_TYPE_VIEW_TO_VIEW_RENDER:
- return ViewRenderViewReferenceProvider.getReference(path, element);
- case YiiRefsHelper.YII_TYPE_WIDGET_CALL:
- return WidgetCallReferenceProvider.getReference(path, element);
- case YiiRefsHelper.YII_TYPE_CACTION_TO_VIEW_RENDER:
- return CActionRenderViewReferenceProvider.getReference(path, element);
- case YiiRefsHelper.YII_TYPE_WIDGET_VIEW_RENDER:
- return WidgetRenderViewReferenceProvider.getReference(path, element);
- case YiiRefsHelper.YII_TYPE_CONTROLLER_ACTIONS_CACTION:
- return ControlleActionsClassReferenceProvider.getReference(path, element);
- }
- */
- } catch (Exception e) {
- //System.err.println("error" + e.getMessage());
- }
- }
- return PsiReference.EMPTY_ARRAY;
- }
-
-
-}
View
37 src/com/raket/silverstripe/references/SilverStripeReferenceContributor.java
@@ -1,25 +1,28 @@
package com.raket.silverstripe.references;
-import com.intellij.patterns.StandardPatterns;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiReferenceContributor;
-import com.intellij.psi.PsiReferenceRegistrar;
+import com.intellij.patterns.PlatformPatterns;
+import com.intellij.psi.*;
+import com.intellij.psi.tree.IElementType;
+import com.intellij.util.ProcessingContext;
+import com.raket.silverstripe.SilverStripeLanguage;
+import com.raket.silverstripe.psi.SilverStripeTypes;
+import com.raket.silverstripe.psi.references.SilverStripeReference;
+import org.jetbrains.annotations.NotNull;
-/**
- * Created with IntelliJ IDEA.
- * User: Marcus Dalgren
- * Date: 2013-03-30
- * Time: 21:41
- * To change this template use File | Settings | File Templates.
- */
public class SilverStripeReferenceContributor extends PsiReferenceContributor {
@Override
public void registerReferenceProviders(PsiReferenceRegistrar registrar) {
- SilverStripePsiReferenceProvider provider = new SilverStripePsiReferenceProvider();
-
- //registrar.registerReferenceProvider(StandardPatterns.instanceOf(XmlAttributeValue.class), provider);
- //registrar.registerReferenceProvider(StandardPatterns.instanceOf(XmlTag.class), provider);
-
- registrar.registerReferenceProvider(StandardPatterns.instanceOf(PsiElement.class), provider);
+ registrar.registerReferenceProvider(PlatformPatterns.psiElement(SilverStripeTypes.SS_INCLUDE_FILE).withLanguage(SilverStripeLanguage.INSTANCE),
+ new PsiReferenceProvider() {
+ @NotNull
+ @Override
+ public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
+ IElementType nodeType = element.getNode().getElementType();
+ if (nodeType == SilverStripeTypes.SS_INCLUDE_FILE) {
+ return new PsiReference[]{new SilverStripeReference(element)};
+ }
+ return new PsiReference[0];
+ }
+ });
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.