From 232648077e3b2bf65faa5ec00763c8903a700a89 Mon Sep 17 00:00:00 2001 From: Kayler Renslow Date: Fri, 22 Jul 2016 20:09:32 -0500 Subject: [PATCH] 1.0.5 release --- META-INF/plugin.xml | 2 +- src/CHANGES | 9 ++- src/TODO | 2 +- src/VERSION changelog | 4 +- .../lang/header/codeStyle/headerSampleCode.h | 2 +- .../highlighting/HeaderColorSettingsPage.java | 10 ++- .../a3plugin/lang/sqf/SQFStatic.java | 68 +++++++++---------- .../SQFDocTagsCompletionProvider.java | 7 +- .../providers/SQFDocumentationProvider.java | 36 +++++----- .../sqf/psi/SQFPsiImplUtilForGrammar.java | 1 + .../kaylerrenslow/a3plugin/plugin.properties | 2 +- 11 files changed, 74 insertions(+), 69 deletions(-) diff --git a/META-INF/plugin.xml b/META-INF/plugin.xml index 3fbf990..44c2bb7 100644 --- a/META-INF/plugin.xml +++ b/META-INF/plugin.xml @@ -40,7 +40,7 @@ - + diff --git a/src/CHANGES b/src/CHANGES index 01f5f6a..b728ccc 100644 --- a/src/CHANGES +++ b/src/CHANGES @@ -12,17 +12,16 @@ Shared between languages CHANGED: none FIXED: - none + Stringtable Value color not properly being displayed in color settings page SQF ADDED: none CHANGED: - removed optimizations to finding variable scope (cached declaration scope and privatization) because they resulted in wrong values - variables set to nil will now be marked as uninitialized - variables declared in params command that have no default value will be marked as "may be uninitialized" instead of more definitive "not initialized" + none FIXED: - params [["_var", nil]];//was saying _var was defined when it shouldn't be + https://github.com/kayler-renslow/arma-intellij-plugin/issues/17 + quick documentation lookup not working for commands while still typing the command Header ADDED: diff --git a/src/TODO b/src/TODO index 5271289..0b32dd8 100644 --- a/src/TODO +++ b/src/TODO @@ -4,7 +4,7 @@ features: check if function exists when doing call or spawn renaming files will rename them in includes and if a SQF function, will rename the class decl -THIS IS BROKEN AGAIN +THIS IS BROKEN AGAIN (scope) _i = 100; for [{private _i = 0}, {_i < 5}, {_i = _i + 1}] do {}; hint str _i; // 100 diff --git a/src/VERSION changelog b/src/VERSION changelog index 08cedc5..632c5c5 100644 --- a/src/VERSION changelog +++ b/src/VERSION changelog @@ -1,5 +1,5 @@ Version: 1.0.5 -Release date: tbd +Release date: July 22 2016 Plugin ADDED: @@ -25,6 +25,8 @@ SQF variables declared in params command that have no default value will be marked as "may be uninitialized" instead of more definitive "not initialized" FIXED: params [["_var", nil]];//was saying _var was defined when it shouldn't be + https://github.com/kayler-renslow/arma-intellij-plugin/issues/17 + quick documentation lookup not working for commands while still typing the command Header ADDED: diff --git a/src/com/kaylerrenslow/a3plugin/lang/header/codeStyle/headerSampleCode.h b/src/com/kaylerrenslow/a3plugin/lang/header/codeStyle/headerSampleCode.h index b35f577..31ac048 100644 --- a/src/com/kaylerrenslow/a3plugin/lang/header/codeStyle/headerSampleCode.h +++ b/src/com/kaylerrenslow/a3plugin/lang/header/codeStyle/headerSampleCode.h @@ -12,7 +12,7 @@ class TestClass { /*Another block comment*/ array[] = {var, 1, 1e1, "", 42, 43}; math = 1 + 69 * 1; - stringtable_value = $str_myTag_Yes; + stringtable_value = $str_myTag_Yes; }; thingy = 0; /*hi*/ diff --git a/src/com/kaylerrenslow/a3plugin/lang/header/codeStyle/highlighting/HeaderColorSettingsPage.java b/src/com/kaylerrenslow/a3plugin/lang/header/codeStyle/highlighting/HeaderColorSettingsPage.java index 81beea4..36474ac 100644 --- a/src/com/kaylerrenslow/a3plugin/lang/header/codeStyle/highlighting/HeaderColorSettingsPage.java +++ b/src/com/kaylerrenslow/a3plugin/lang/header/codeStyle/highlighting/HeaderColorSettingsPage.java @@ -11,6 +11,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.util.HashMap; import java.util.Map; /** @@ -33,7 +34,12 @@ public class HeaderColorSettingsPage implements ColorSettingsPage{ new AttributesDescriptor("Comma", HeaderSyntaxHighlighter.COMMA), new AttributesDescriptor("Stringtable Value", HeaderSyntaxHighlighter.STRINGTABLE_VALUE) }; - + + private static final Map map = new HashMap<>(); + static { + map.put("stringtableValue", HeaderSyntaxHighlighter.STRINGTABLE_VALUE); + } + @Nullable @Override public Icon getIcon() { @@ -55,7 +61,7 @@ public String getDemoText() { @Nullable @Override public Map getAdditionalHighlightingTagToDescriptorMap() { - return null; + return map; } @NotNull diff --git a/src/com/kaylerrenslow/a3plugin/lang/sqf/SQFStatic.java b/src/com/kaylerrenslow/a3plugin/lang/sqf/SQFStatic.java index 7c19731..0f7b187 100644 --- a/src/com/kaylerrenslow/a3plugin/lang/sqf/SQFStatic.java +++ b/src/com/kaylerrenslow/a3plugin/lang/sqf/SQFStatic.java @@ -23,43 +23,41 @@ public class SQFStatic { public static final String DESCRIPTION = Plugin.resources.getString("lang.sqf.description"); static final String FILE_EXTENSION = Plugin.resources.getString("lang.sqf.file_extension"); static final String FILE_EXTENSION_DEFAULT = Plugin.resources.getString("lang.sqf.file_extension_default"); - + private static final String COMMANDS_DOC_FILE_DIR = "/com/kaylerrenslow/a3plugin/lang/sqf/raw_doc/commands-doc/"; private static final String BIS_FUNCTIONS_DOC_FILE_DIR = "/com/kaylerrenslow/a3plugin/lang/sqf/raw_doc/bis-functions-doc/"; - + private static final String COMMANDS_DOC_FILE_LOOKUP = COMMANDS_DOC_FILE_DIR + "lookup.list"; private static final String BIS_FUNCTIONS_DOC_FILE_LOOKUP = BIS_FUNCTIONS_DOC_FILE_DIR + "lookup.list"; - + public static final List LIST_COMMANDS = TextFileListToList.getListFromStream(ResourceGetter.getResourceAsStream(COMMANDS_DOC_FILE_LOOKUP), new ArrayList<>()); public static final List LIST_BIS_FUNCTIONS = TextFileListToList.getListFromStream(ResourceGetter.getResourceAsStream(BIS_FUNCTIONS_DOC_FILE_LOOKUP), new ArrayList<>()); - + public static final String SQF_SAMPLE_CODE_TEXT = FileReader.getText("/com/kaylerrenslow/a3plugin/lang/sqf/codeStyle/sqfSampleCode.sqf"); - + private static final String FUNCTION_NAMING_RULE_REGEX = "[a-zA-z_0-9]+_fnc_[a-zA-z_0-9]+"; //don't need to check if the function name starts with a number since that is asserted with the lexer - + public static final IElementType[] OPERATORS = {SQFTypes.EQEQ, SQFTypes.EQ, SQFTypes.ASTERISK, SQFTypes.NE, SQFTypes.PERC, SQFTypes.PLUS, SQFTypes.MINUS, SQFTypes.FSLASH, SQFTypes.CARET, SQFTypes.GTGT, SQFTypes.GT, SQFTypes.GE, SQFTypes.LT, SQFTypes.LE, SQFTypes.EXCL, SQFTypes.AMPAMP, SQFTypes.BARBAR, SQFTypes.QUEST, SQFTypes.COLON}; - + public static final TokenSet COMMENTS = TokenSet.create(SQFTypes.INLINE_COMMENT); public static final TokenSet NUMBER_LITERALS = TokenSet.create(SQFTypes.DEC_LITERAL, SQFTypes.INTEGER_LITERAL); public static final TokenSet IDENTIFIERS = TokenSet.create(SQFTypes.GLOBAL_VAR, SQFTypes.LOCAL_VAR, SQFTypes.VARIABLE); - - + + static { Collections.sort(LIST_COMMANDS); Collections.sort(LIST_BIS_FUNCTIONS); } - - public static boolean hasDocumentation(IElementType type) { - if (type == SQFTypes.COMMAND_TOKEN) { - return true; - } - return false; + + /** Return true if the given type refers to a command, false otherwise */ + public static boolean isCommand(IElementType type) { + return type == SQFTypes.COMMAND_TOKEN || type == SQFTypes.COMMAND; } - + /** Fetch command syntax for given command. This method will fetch the syntax and params from file and make it readable. Example: "paramName COMMAND paramName2" to "paramName:Number COMMAND paramName2:Number" - + @param command command String name @return syntax with params and param types, or null if the command doesn't have a known syntax */ @@ -88,11 +86,11 @@ public static String getCommandDocSyntax(@NotNull String command) { // return syntax; return null; } - - + + /** Parses a full function name (e.g. tag_fnc_functionClass) and returns a pair containing the tag name and function class name. Pair first = tag, pair second = function class name - + @param fullFunctionName full function name @return SQFFunctionTagAndName instance @throws IllegalArgumentException when the function name doesn't follow the function naming requirements @@ -107,10 +105,10 @@ public static SQFFunctionTagAndName getFunctionTagAndName(String fullFunctionNam String functionClassName = fullFunctionName.substring(_fnc_Index + 5); //function's class name. return new SQFFunctionTagAndName(tagName, functionClassName); } - + /** Takes a tag and class name and returns the full SQF callable function name (e.g. tag_fnc_className) - + @param tag tag @param functionClassName class name @return full callable function name @@ -118,29 +116,29 @@ Takes a tag and class name and returns the full SQF callable function name (e.g. public static String getFullFunctionName(String tag, String functionClassName) { return tag + "_fnc_" + functionClassName; } - + /** Returns the file name for the given sqf config function class name - + @param functionClassName name to get file name for @return fn_functionClassName.sqf */ public static String getConfigFunctionFileName(String functionClassName) { return "fn_" + functionClassName + ".sqf"; } - + /** Checks if the given variable name follows the general rules of function naming (requires tag, _fnc_ and then an identifier).

Examples: tag_fnc_function, sj_fnc_function2

Counter Examples: tag_fn_c_function, sj_nc_function2, potatoes, _fnc_function

- + @param variable Variable to test @return true if matches, false if it doesn't */ public static boolean followsSQFFunctionNameRules(@NotNull String variable) { return variable.matches(FUNCTION_NAMING_RULE_REGEX); //don't need to explicitly check if a number starts the variable name since that is asserted by the lexer } - + /** Return true if the given var name is a BIS function, false if it isn't. */ @@ -150,10 +148,10 @@ public static boolean isBisFunction(String varName) { } return Collections.binarySearch(LIST_BIS_FUNCTIONS, varName) >= 0; } - + /** Checks if the given variable name is possibly a BIS function (varName starts with BIS_). - + @param varName variable name to check @return true if starts with BIS_, false otherwise */ @@ -161,24 +159,24 @@ public static boolean isMaybeBISFunction(String varName) { String bis = "BIS_"; return varName.startsWith(bis); } - + public static String getCommandDocumentation(String commandName) { return FileReader.getText(getDocumentationFilePath(commandName)); } - + private static String getDocumentationFilePath(String commandName) { return COMMANDS_DOC_FILE_DIR + commandName; } - + public static String getBISFunctionDocumentation(String bisFunction) { return FileReader.getText(BIS_FUNCTIONS_DOC_FILE_DIR + bisFunction); } - - + + public static class SQFFunctionTagAndName { public final String tagName; public final String functionClassName; - + public SQFFunctionTagAndName(String tagName, String functionClassName) { this.tagName = tagName; this.functionClassName = functionClassName; diff --git a/src/com/kaylerrenslow/a3plugin/lang/sqf/providers/SQFDocTagsCompletionProvider.java b/src/com/kaylerrenslow/a3plugin/lang/sqf/providers/SQFDocTagsCompletionProvider.java index 42be87d..29e0214 100644 --- a/src/com/kaylerrenslow/a3plugin/lang/sqf/providers/SQFDocTagsCompletionProvider.java +++ b/src/com/kaylerrenslow/a3plugin/lang/sqf/providers/SQFDocTagsCompletionProvider.java @@ -20,10 +20,9 @@ protected void addCompletions(@NotNull CompletionParameters parameters, Processi if (cursor == null) { return; } - int caretPos = parameters.getEditor().getCaretModel().getPrimaryCaret().getOffset(); - String docText = parameters.getEditor().getDocument().getText(); - String subText = docText.substring(caretPos - 1, cursor.getTextLength()); - if (subText.startsWith("@")) { + String commentText = cursor.getText(); + int caretPos = parameters.getEditor().getCaretModel().getPrimaryCaret().getOffset() - cursor.getTextOffset(); + if (commentText.charAt(caretPos - 1) == '@') { result.addElement(new CompletionElementWithTextReplace("@command", "command", 7, Plugin.resources.getString("lang.shared.auto_completion.tags.trail_text.command")).getLookupElement(parameters, context, result)); result.addElement(new CompletionElementWithTextReplace("@bis", "bis", 3, Plugin.resources.getString("lang.shared.auto_completion.tags.trail_text.bis")).getLookupElement(parameters, context, result)); result.addElement(new CompletionElementWithTextReplace("@fnc", "fnc", 3, Plugin.resources.getString("lang.shared.auto_completion.tags.trail_text.fnc")).getLookupElement(parameters, context, result)); diff --git a/src/com/kaylerrenslow/a3plugin/lang/sqf/providers/SQFDocumentationProvider.java b/src/com/kaylerrenslow/a3plugin/lang/sqf/providers/SQFDocumentationProvider.java index 4fbcb37..9b602bb 100644 --- a/src/com/kaylerrenslow/a3plugin/lang/sqf/providers/SQFDocumentationProvider.java +++ b/src/com/kaylerrenslow/a3plugin/lang/sqf/providers/SQFDocumentationProvider.java @@ -36,31 +36,31 @@ public class SQFDocumentationProvider extends DocumentationProviderEx { public static final String DOC_LINK_PREFIX_COMMAND = "command:"; /** Used for CfgFunction documentation links. This comes after the psi element protocol in anchor tags. For functions defined in CfgFunctions. Example use case: <a href='psi-element://function:f_fnc_test'>f_fnc_test</a> */ public static final String DOC_LINK_PREFIX_USER_FUNCTION = "function:"; - + @Nullable @Override public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) { return generateDoc(element, originalElement); } - + @Nullable @Override public List getUrlFor(PsiElement element, PsiElement originalElement) { List lst = new ArrayList<>(); - if (SQFStatic.hasDocumentation(element.getNode().getElementType()) || SQFStatic.isBisFunction(element.getText())) { + if (SQFStatic.isCommand(element.getNode().getElementType()) || SQFStatic.isBisFunction(element.getText())) { lst.add(getWikiUrl(element.getText())); return lst; } return null; } - + @Nullable @Override public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) { if (element instanceof XmlTag) { return Stringtable.getKeyDoc((XmlTag) element); } - if (SQFStatic.hasDocumentation(element.getNode().getElementType())) { + if (SQFStatic.isCommand(element.getNode().getElementType())) { return generateCommandDoc(element.getText()); } if (SQFStatic.isBisFunction(element.getText())) { @@ -87,14 +87,14 @@ public String generateDoc(PsiElement element, @Nullable PsiElement originalEleme } return null; } - + @Nullable @Override public PsiElement getDocumentationElementForLookupItem(PsiManager psiManager, Object object, PsiElement element) { if (object instanceof StringtableLookupElementDataObject) { return ((StringtableLookupElementDataObject) object).getTargetTag(); } - if (SQFStatic.hasDocumentation(element.getNode().getElementType())) { + if (SQFStatic.isCommand(element.getNode().getElementType())) { return element; } if (element instanceof PsiFile) { @@ -106,11 +106,11 @@ public PsiElement getDocumentationElementForLookupItem(PsiManager psiManager, Ob return function.getClassDeclaration(); } return function.getPsiFile(); - + } return null; } - + @Nullable @Override public PsiElement getDocumentationElementForLink(PsiManager psiManager, String link, PsiElement context) { @@ -144,17 +144,17 @@ public PsiElement getDocumentationElementForLink(PsiManager psiManager, String l } return null; } - + @Override @Nullable public PsiElement getCustomDocumentationElement(@NotNull final Editor editor, @NotNull final PsiFile file, @Nullable PsiElement contextElement) { if (contextElement == null) { return null; } - if (SQFStatic.hasDocumentation(contextElement.getNode().getElementType())) { + if (SQFStatic.isCommand(contextElement.getNode().getElementType())) { return contextElement; } - + if (PsiUtil.isOfElementType(contextElement, SQFTypes.LOCAL_VAR)) { //this code works, but only when the selected statement has the comment SQFVariable var = (SQFVariable) (contextElement.getParent()); PsiReference[] references = var.getReferences(); @@ -168,10 +168,10 @@ public PsiElement getCustomDocumentationElement(@NotNull final Editor editor, @N } } } - + return null; } - + @Nullable private PsiElement getInlineComment(@NotNull Editor editor, ASTNode statementNode) { ASTNode commentNode = PsiUtil.getNextSiblingNotWhitespace(statementNode); @@ -183,7 +183,7 @@ private PsiElement getInlineComment(@NotNull Editor editor, ASTNode statementNod } return null; } - + private static String generateCommandDoc(String commandName) { String doc = String.format(EXTERNAL_LINK_NOTIFICATION, getWikiUrl(commandName)); try { @@ -193,7 +193,7 @@ private static String generateCommandDoc(String commandName) { } return doc; } - + private static String generateFunctionDoc(String functionName) { String doc = String.format(EXTERNAL_LINK_NOTIFICATION, getWikiUrl(functionName)); try { @@ -203,9 +203,9 @@ private static String generateFunctionDoc(String functionName) { } return doc; } - + private static String getWikiUrl(String wikiLinkName) { return BIS_WIKI_URL_PREFIX + wikiLinkName; } - + } diff --git a/src/com/kaylerrenslow/a3plugin/lang/sqf/psi/SQFPsiImplUtilForGrammar.java b/src/com/kaylerrenslow/a3plugin/lang/sqf/psi/SQFPsiImplUtilForGrammar.java index 575253a..e86faa1 100644 --- a/src/com/kaylerrenslow/a3plugin/lang/sqf/psi/SQFPsiImplUtilForGrammar.java +++ b/src/com/kaylerrenslow/a3plugin/lang/sqf/psi/SQFPsiImplUtilForGrammar.java @@ -231,6 +231,7 @@ public static SQFPrivatization getPrivatization(SQFVariable var) { } } } + if (array != null) { //definitely not the for spec loop if null SQFCodeBlock firstCodeBlock = array.getArrayEntryList().get(0).getCodeBlock(); if (firstCodeBlock != null) { diff --git a/src/com/kaylerrenslow/a3plugin/plugin.properties b/src/com/kaylerrenslow/a3plugin/plugin.properties index dc531f7..1f1690d 100644 --- a/src/com/kaylerrenslow/a3plugin/plugin.properties +++ b/src/com/kaylerrenslow/a3plugin/plugin.properties @@ -1,7 +1,7 @@ #resource bundle for the plugin #version of the plugin -plugin.version = 1.0.4_1 +plugin.version = 1.0.5 #folder name inside the appdata/roaming folder plugin.appdata.folderName = Arma Intellij Plugin