Skip to content

Commit

Permalink
up value
Browse files Browse the repository at this point in the history
  • Loading branch information
tangzx committed Feb 16, 2017
1 parent 6aeff95 commit 8df1c8a
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
20 changes: 20 additions & 0 deletions src/main/java/com/tang/intellij/lua/psi/LuaPsiResolveUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@
<typedHandler implementation="com.tang.intellij.lua.editor.LuaAutoPopupHandler"/>
<typedHandler implementation="com.tang.intellij.lua.editor.LuaAutoIndentHandler"/>

<!-- color -->
<colorSettingsPage implementation="com.tang.intellij.lua.editor.LuaColorSettingsPage"/>
<additionalTextAttributes scheme="Default" file="colorSchemes/Default.xml"/>
<additionalTextAttributes scheme="Darcula" file="colorSchemes/Darcula.xml"/>

<!-- debugger -->
<programRunner implementation="com.tang.intellij.lua.debugger.LuaDebuggerRunner"/>
<configurationType implementation="com.tang.intellij.lua.debugger.LuaConfigurationType"/>
<xdebugger.breakpointType implementation="com.tang.intellij.lua.debugger.LuaLineBreakpointType"/>
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/colorSchemes/Darcula.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version='1.0'?>
<list>
<option name="LUA_UP_VALUE">
<value>
<option name="FOREGROUND" value="A8C023"/>
<option name="FONT_TYPE" value="3"/>
<option name="EFFECT_COLOR" value="A8C023"/>
<option name="EFFECT_TYPE" value="1"/>
</value>
</option>
</list>
11 changes: 11 additions & 0 deletions src/main/resources/colorSchemes/Default.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version='1.0'?>
<list>
<option name="LUA_UP_VALUE">
<value>
<option name="FOREGROUND" value="50505"/>
<option name="FONT_TYPE" value="3"/>
<option name="EFFECT_COLOR" value="50505"/>
<option name="EFFECT_TYPE" value="1"/>
</value>
</option>
</list>

0 comments on commit 8df1c8a

Please sign in to comment.