Skip to content

Commit

Permalink
1.0.5_2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
kayler-renslow committed Aug 12, 2016
1 parent ca7889b commit a5d4453
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 52 deletions.
2 changes: 1 addition & 1 deletion META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin version="2">
<id>com.kaylerrenslow.plugin.armaplugin.id</id>
<name>Arma Intellij Plugin</name>
<version>1.0.5_1</version>
<version>1.0.5_2</version>
<!--<vendor email="[email protected]" url="http://www.yourcompany.com">YourCompany</vendor>-->
<description>
Plugin that offers syntax checking of SQF files, syntax highlighting, find usages, refactor renaming, and more various features.
Expand Down
5 changes: 3 additions & 2 deletions src/CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Header
ADDED:
none
CHANGED:
none
sqm files are no longer parsed by the Header parser
FIXED:
none
https://github.com/kayler-renslow/arma-intellij-plugin/issues/25
https://github.com/kayler-renslow/arma-intellij-plugin/issues/23
5 changes: 3 additions & 2 deletions src/TODO
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FIX FINDING SCOPE FOR SQF VARIABLES, ESPECIALLY WITH LOOPS
//http://pasting.io/#dardo/477

features:
check if function exists when doing call or spawn
Expand All @@ -14,4 +13,6 @@ for header preprocessors, you will have to implement the lexer both times. Howev
We would also have a shared annotator that would look for these tokens and provide proper coloring and error checking
We need to figure out how to provide references for them though

parse through mission.sqm for function calls and such to see if variables are defined outside SQF (useful for unused inspection)
parse through mission.sqm for function calls and such to see if variables are defined outside SQF (useful for unused inspection)

header lexer could not match input when doing analyze->inspect code
14 changes: 7 additions & 7 deletions src/VERSION changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Version: 1.0.5_1
Release date: August 3 2016
Version: 1.0.5_2
Release date: August 12, 2016

Plugin
ADDED:
Expand All @@ -19,17 +19,17 @@ Shared between languages

SQF
ADDED:
Inspection that you can turn on/off for: checks to see if variables are defined, being used, and private (this functionality has been in place for a while, but now it can be turned off if you like)
none
CHANGED:
none
FIXED:
bad performance for case statements (https://github.com/kayler-renslow/arma-intellij-plugin/issues/22)
external annotator being very slow
none

Header
ADDED:
none
CHANGED:
none
sqm files are no longer parsed by the Header parser
FIXED:
none
https://github.com/kayler-renslow/arma-intellij-plugin/issues/25
https://github.com/kayler-renslow/arma-intellij-plugin/issues/23
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ public static List<HeaderStringtableKey> findAllStringtableKeys(@NotNull Project
List<HeaderStringtableKey> result = new ArrayList<>();
Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, HeaderFileType.INSTANCE, module.getModuleContentScope());
for (VirtualFile virtualFile : files) {
HeaderFile headerFile = (HeaderFile) PsiManager.getInstance(project).findFile(virtualFile);
if (headerFile == null) {
PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
if(!(file instanceof HeaderFile)){
continue;
}
HeaderFile headerFile = (HeaderFile) file;
ArrayList<HeaderStringtableKey> strings = PsiUtil.findDescendantElementsOfInstance(headerFile, HeaderStringtableKey.class, null);
if (strings == null) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ public void visitScope(@NotNull SQFScope scope) {
if (matchedIndex >= 0) {
matchedNode = privateVars.get(matchedIndex).getVarElement().getNode();
if (currentPrivateVarNode.getPsi() instanceof SQFString) {
rangeCurrentNode = ((SQFString) (currentPrivateVarNode.getPsi())).getNonQuoteRangeRelativeToFile();
rangeCurrentNode = ((SQFString) (currentPrivateVarNode.getPsi())).getNonQuoteRangeRelativeToElement();
} else {
rangeCurrentNode = TextRange.from(currentPrivateVarNode.getStartOffset(), currentPrivateVarNode.getTextLength());
}
if (matchedNode.getPsi() instanceof SQFString) {
rangeMatchedNode = ((SQFString) (matchedNode.getPsi())).getNonQuoteRangeRelativeToFile();
rangeMatchedNode = ((SQFString) (matchedNode.getPsi())).getNonQuoteRangeRelativeToElement();
} else {
rangeMatchedNode = TextRange.from(matchedNode.getStartOffset(), matchedNode.getTextLength());
}
Expand All @@ -190,7 +190,7 @@ public void visitScope(@NotNull SQFScope scope) {
}
if (currentPrivateVar.getVarElement() instanceof SQFString) { //usage check already handled for variables, so only need to check for strings
if (currentPrivateVar.getVarElement().getReferences().length == 0) {
TextRange range = ((SQFString) currentPrivateVar.getVarElement()).getNonQuoteRangeRelativeToFile();
TextRange range = ((SQFString) currentPrivateVar.getVarElement()).getNonQuoteRangeRelativeToElement();
holder.registerProblem(currentPrivateVar.getVarElement(), range, Plugin.resources.getString("lang.sqf.annotator.variable_unused"));
}
}
Expand Down
70 changes: 37 additions & 33 deletions src/com/kaylerrenslow/a3plugin/lang/sqf/psi/SQFPsiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiFileFactory;
import com.intellij.psi.PsiManager;
import com.intellij.psi.search.FileTypeIndex;
Expand All @@ -30,18 +31,18 @@
Psi utilities for SQF
Created on 03/20/2016. */
public class SQFPsiUtil {


/**
Check if the given element is inside a [] spawn {}. For spawn, all variables are created in a different environment
We must iterate over all upper code blocks and see if they are part of a spawn statement. Unlike scope.checkIfSpawn(), this will traverse the tree upwards to the file scope to make sure that the element isn't inside the spawn scope
@return the scope that starts the spawn scope ([] spawn {}), or null if not inside spawn
*/
@Nullable
public static SQFScope checkIfInsideSpawn(@NotNull PsiElement element) {
SQFScope containingScope = SQFPsiUtil.getContainingScope(element);

PsiElement codeBlock = containingScope.getParent();
SQFScope spawnScope = containingScope;
ASTNode previous;
Expand All @@ -57,10 +58,10 @@ public static SQFScope checkIfInsideSpawn(@NotNull PsiElement element) {
}
return null;
}

/**
Checks if the given PsiElement is a BIS function (is of type SQFTypes.VARIABLE or SQFTypes.GLOBAL_VAR and is defined in documentation, false otherwise).
@param element element
@return true if the given PsiElement is a BIS function, false otherwise
*/
Expand All @@ -73,17 +74,17 @@ public static boolean isBisFunction(@NotNull PsiElement element) {
}
return false;
}


@NotNull
public static SQFFileScope getFileScope(@NotNull SQFFile containingFile) {
return (SQFFileScope) containingFile.getNode().getChildren(TokenSet.create(SQFTypes.FILE_SCOPE))[0].getPsi();
}


/**
Gets the containing scope of the psi element. Scope is determined by what code block element is in, or if not in a code block then the file's file scope is returned
@param element element to get scope of
@return scope
*/
Expand All @@ -98,10 +99,10 @@ public static SQFScope getContainingScope(@NotNull PsiElement element) {
}
return (SQFScope) parent;
}

/**
Adds all SQFVariables in the current module that is equal to findVar into a list and returns it
@param project project
@param findVar global variable
@return list
Expand All @@ -110,16 +111,17 @@ public static SQFScope getContainingScope(@NotNull PsiElement element) {
public static List<SQFVariable> findGlobalVariables(@NotNull Project project, @NotNull SQFVariable findVar) {
List<SQFVariable> result = new ArrayList<>();
Module m = PluginUtil.getModuleForPsiFile(findVar.getContainingFile());
if(m == null){
if (m == null) {
return result;
}
GlobalSearchScope searchScope = m.getModuleContentScope();
Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SQFFileType.INSTANCE, searchScope);
for (VirtualFile virtualFile : files) {
SQFFile sqfFile = (SQFFile) PsiManager.getInstance(project).findFile(virtualFile);
if (sqfFile == null) {
PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
if(!(file instanceof SQFFile)){
continue;
}
SQFFile sqfFile = (SQFFile) file;
ArrayList<SQFVariable> vars = PsiUtil.findDescendantElementsOfInstance(sqfFile, SQFVariable.class, null);
if (vars == null) {
continue;
Expand All @@ -135,10 +137,10 @@ public static List<SQFVariable> findGlobalVariables(@NotNull Project project, @N
}
return result;
}

/**
Finds all SQFStrings in the module in all SQF files with text equal to quoteText
@param project project
@param module current module
@param quoteText text to search for (including quotes)
Expand All @@ -149,10 +151,11 @@ public static List<SQFString> findAllStrings(@NotNull Project project, @NotNull
List<SQFString> result = new ArrayList<>();
Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SQFFileType.INSTANCE, module.getModuleContentScope());
for (VirtualFile virtualFile : files) {
SQFFile sqfFile = (SQFFile) PsiManager.getInstance(project).findFile(virtualFile);
if (sqfFile == null) {
PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
if (!(file instanceof SQFFile)) {
continue;
}
SQFFile sqfFile = (SQFFile) file;
ArrayList<SQFString> strings = PsiUtil.findDescendantElementsOfInstance(sqfFile, SQFString.class, null);
if (strings == null) {
continue;
Expand All @@ -165,10 +168,10 @@ public static List<SQFString> findAllStrings(@NotNull Project project, @NotNull
}
return result;
}

/**
Adds all SQFVariables in the current module where the variable name is a config function and the function tag is equal to parameter tag
@param module module
@param tag tag to search for
@return list
Expand All @@ -179,10 +182,11 @@ public static List<SQFVariable> findConfigFunctionVariablesWithTag(@NotNull Modu
GlobalSearchScope searchScope = module.getModuleContentScope();
Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SQFFileType.INSTANCE, searchScope);
for (VirtualFile virtualFile : files) {
SQFFile sqfFile = (SQFFile) PsiManager.getInstance(module.getProject()).findFile(virtualFile);
if (sqfFile == null) {
PsiFile file = PsiManager.getInstance(module.getProject()).findFile(virtualFile);
if (!(file instanceof SQFFile)) {
continue;
}
SQFFile sqfFile = (SQFFile) file;
ArrayList<SQFVariable> vars = PsiUtil.<SQFVariable>findDescendantElementsOfInstance(sqfFile, SQFVariable.class, null);
if (vars == null) {
continue;
Expand All @@ -202,10 +206,10 @@ public static List<SQFVariable> findConfigFunctionVariablesWithTag(@NotNull Modu
}
return result;
}

/**
Creates a new SQFCommandExpression that is a private[] syntax with new vars appended and returns it
@param project project
@param decl the private declaration to append to
@param varNames the names of the new variables to put inside the declaration
Expand All @@ -223,28 +227,28 @@ public static SQFCommandExpression createPrivateDeclFromExisting(@NotNull Projec
}
return (SQFCommandExpression) createElement(project, text, SQFTypes.COMMAND_EXPRESSION);
}

@NotNull
public static SQFVariable createVariable(@NotNull Project project, @NotNull String text) {
return (SQFVariable) createElement(project, text, SQFTypes.VARIABLE);
}

@NotNull
public static SQFFile createFile(@NotNull Project project, @NotNull String text) {
String fileName = "fake_sqf_file.sqf";
return (SQFFile) PsiFileFactory.getInstance(project).createFileFromText(fileName, SQFFileType.INSTANCE, text);
}

@NotNull
public static PsiElement createElement(@NotNull Project project, @NotNull String text, @NotNull IElementType type) {
SQFFile file = createFile(project, text);
return PsiUtil.findDescendantElements(file, type, null).get(0).getPsi();
}

public static SQFString createNewStringLiteral(Project project, String textWithoutQuotes) {
return (SQFString) createElement(project, "\"" + textWithoutQuotes + "\"", SQFTypes.STRING);
}

@SuppressWarnings("unchecked")
/** Get all array entries in the array where the expression type is of class type. Do not make this a utility method for the grammar because the generic type parameter won't work */
public static <T extends SQFExpression> List<T> getExpressionsOfType(SQFArrayVal array, Class<T> type) {
Expand All @@ -259,11 +263,11 @@ public static <T extends SQFExpression> List<T> getExpressionsOfType(SQFArrayVal
}
return items;
}

/**
Get a postfix argument of class type. This method will traverse as far right until the end of the expression (for instance, searching expression 'vehicle player setPos' will search all the way to setPos)<br>
Do not
@param commandExpression command expression
@return the first element of matched type, or null if none could be found.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/com/kaylerrenslow/a3plugin/plugin.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#resource bundle for the plugin

#version of the plugin
plugin.version = 1.0.5_1
plugin.version = 1.0.5_2
#folder name inside the appdata/roaming folder
plugin.appdata.folderName = Arma Intellij Plugin

Expand Down Expand Up @@ -83,7 +83,7 @@ lang.sqf.refactoring.dialog.functions.rename_root_tag.tooltip = Rename all funct
#------------Header------------#
lang.header.name_for_display = Arma Header
lang.header.description = Arma - Header/Config
lang.header.file_extension = h;hh;hpp;ext;sqm
lang.header.file_extension = h;hh;hpp;ext
lang.header.file_extension_default = .h
lang.header.code_style_settings.display_name = Arma Header

Expand Down

0 comments on commit a5d4453

Please sign in to comment.