diff --git a/src/main/java/com/tang/intellij/lua/annotator/LuaAnnotator.java b/src/main/java/com/tang/intellij/lua/annotator/LuaAnnotator.java index 271e664e0..7f5ec0eeb 100644 --- a/src/main/java/com/tang/intellij/lua/annotator/LuaAnnotator.java +++ b/src/main/java/com/tang/intellij/lua/annotator/LuaAnnotator.java @@ -109,6 +109,14 @@ public void visitNameRef(@NotNull LuaNameRef o) { if (id.getNode().getElementType() == LuaTypes.SELF) return; + //up value + PsiElement upvalue = LuaPsiResolveUtil.resolveUpvalue(o, new SearchContext(o.getProject())); + if (upvalue != null) { + Annotation annotation = myHolder.createInfoAnnotation(o, null); + annotation.setTextAttributes(LuaHighlightingData.UP_VALUE); + return; + } + PsiElement res = o.resolve(new SearchContext(o.getProject())); if (res instanceof LuaParamNameDef) { Annotation annotation = myHolder.createInfoAnnotation(o, null); diff --git a/src/main/java/com/tang/intellij/lua/editor/LuaColorSettingsPage.java b/src/main/java/com/tang/intellij/lua/editor/LuaColorSettingsPage.java index 219b8bc9a..1bea1fbfb 100644 --- a/src/main/java/com/tang/intellij/lua/editor/LuaColorSettingsPage.java +++ b/src/main/java/com/tang/intellij/lua/editor/LuaColorSettingsPage.java @@ -52,7 +52,8 @@ public class LuaColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("Local Variables", LuaHighlightingData.LOCAL_VAR), new AttributesDescriptor("Global Variables", LuaHighlightingData.GLOBAL_VAR), new AttributesDescriptor("Global Functions", LuaHighlightingData.GLOBAL_FUNCTION), - new AttributesDescriptor("Table Fields", LuaHighlightingData.TABLE_FIELD) + new AttributesDescriptor("Table Fields", LuaHighlightingData.TABLE_FIELD), + new AttributesDescriptor("Up Value", LuaHighlightingData.UP_VALUE), }; @NonNls diff --git a/src/main/java/com/tang/intellij/lua/highlighting/LuaHighlightingData.java b/src/main/java/com/tang/intellij/lua/highlighting/LuaHighlightingData.java index e8f1c5735..63fd77128 100644 --- a/src/main/java/com/tang/intellij/lua/highlighting/LuaHighlightingData.java +++ b/src/main/java/com/tang/intellij/lua/highlighting/LuaHighlightingData.java @@ -64,6 +64,8 @@ public class LuaHighlightingData { private static final String LUADOC_TAG_ID = "LUA_LUADOC_TAG"; @NonNls private static final String LUADOC_VALUE_ID = "LUA_LUADOC_VALUE"; + @NonNls + private static final String UP_VALUE_ID = "LUA_UP_VALUE"; public static TextAttributesKey DOC_COMMENT_TAG = TextAttributesKey.createTextAttributesKey(LUADOC_TAG_ID, DefaultLanguageHighlighterColors.DOC_COMMENT_TAG); @@ -103,4 +105,6 @@ public class LuaHighlightingData { TextAttributesKey.createTextAttributesKey(OPERATORS_ID, DefaultLanguageHighlighterColors.OPERATION_SIGN); public static final TextAttributesKey PRIMITIVE_TYPE = TextAttributesKey.createTextAttributesKey("LUA_PRIMITIVE_TYPE", ConsoleHighlighter.CYAN_BRIGHT); + public static TextAttributesKey UP_VALUE = + TextAttributesKey.createTextAttributesKey(UP_VALUE_ID); } \ No newline at end of file diff --git a/src/main/java/com/tang/intellij/lua/psi/LuaPsiResolveUtil.java b/src/main/java/com/tang/intellij/lua/psi/LuaPsiResolveUtil.java index 4b28c65e6..95f4ea193 100644 --- a/src/main/java/com/tang/intellij/lua/psi/LuaPsiResolveUtil.java +++ b/src/main/java/com/tang/intellij/lua/psi/LuaPsiResolveUtil.java @@ -28,6 +28,7 @@ import com.tang.intellij.lua.stubs.index.LuaGlobalFuncIndex; import com.tang.intellij.lua.stubs.index.LuaGlobalVarIndex; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -102,6 +103,25 @@ public static PsiElement resolveLocal(LuaNameRef ref, SearchContext context) { return result; } + @Nullable + public static PsiElement resolveUpvalue(@NotNull LuaNameRef ref, @NotNull SearchContext context) { + String refName = ref.getName(); + if (refName.equals(Constants.WORD_SELF)) + return null; + + LuaFuncBody funcBody = PsiTreeUtil.getParentOfType(ref, LuaFuncBody.class); + if (funcBody == null) + return null; + + PsiElement resolve = resolveLocal(ref, context); + if (resolve != null) { + if (!funcBody.getTextRange().contains(resolve.getTextRange())) + return resolve; + } + + return null; + } + private static PsiElement resolveResult; /** diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index a2523abb2..c317a1f49 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -89,8 +89,12 @@ + + + + diff --git a/src/main/resources/colorSchemes/Darcula.xml b/src/main/resources/colorSchemes/Darcula.xml new file mode 100644 index 000000000..5c62f5aba --- /dev/null +++ b/src/main/resources/colorSchemes/Darcula.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/src/main/resources/colorSchemes/Default.xml b/src/main/resources/colorSchemes/Default.xml new file mode 100644 index 000000000..f42ce1c4b --- /dev/null +++ b/src/main/resources/colorSchemes/Default.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file