mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
Merge pull request #40 from adelf/find-usages
Find usages refactoring GitOrigin-RevId: 128c27a3a6e06f163570169a3be5dd0670c56e52
This commit is contained in:
2
plugins/env-files-support/.gitignore
vendored
2
plugins/env-files-support/.gitignore
vendored
@@ -3,6 +3,6 @@
|
||||
/dotenv.jar
|
||||
/idea-flex.skeleton
|
||||
/jflex-1.7.0.jar
|
||||
/gen/ru/adelf/idea/dotenv/grammars/_DotEnvLexer.java~
|
||||
/src/main/gen/ru/adelf/idea/dotenv/grammars/_DotEnvLexer.java~
|
||||
/build/
|
||||
/.gradle/
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||
}
|
||||
maven {
|
||||
url 'https://dl.bintray.com/jetbrains/intellij-plugin-service'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "org.jetbrains.intellij" version "0.3.11"
|
||||
id "org.jetbrains.intellij" version "0.4.9"
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@@ -24,22 +30,27 @@ apply plugin: 'org.jetbrains.intellij'
|
||||
apply plugin: 'java'
|
||||
|
||||
intellij {
|
||||
version 'IU-182.4129.33'
|
||||
version 'IU-191.7479.19'
|
||||
plugins = [
|
||||
'com.jetbrains.php:182.3208.33',
|
||||
'com.jetbrains.php:191.7479.51',
|
||||
'JavaScriptLanguage',
|
||||
'yaml',
|
||||
'org.jetbrains.plugins.go:182.4129.55.890',
|
||||
'Docker:182.3684.90',
|
||||
'pythonid:2018.2.182.4129.33',
|
||||
'org.jetbrains.plugins.ruby:2018.2.20180716',
|
||||
'org.jetbrains.plugins.go:191.7479.19.213',
|
||||
'Docker',
|
||||
'pythonid:2019.1.191.7479.19',
|
||||
'org.jetbrains.plugins.ruby:2019.1.20190528',
|
||||
'coverage',
|
||||
'CSS',
|
||||
'java-i18n',
|
||||
'properties',
|
||||
]
|
||||
pluginName '.env files support'
|
||||
}
|
||||
|
||||
patchPluginXml {
|
||||
sinceBuild '182'
|
||||
sinceBuild '191'
|
||||
}
|
||||
|
||||
group 'org.jetbrains'
|
||||
version '0.7' // Plugin version
|
||||
group 'ru.adelf'
|
||||
version '0.8' // Plugin version
|
||||
sourceCompatibility = 1.8
|
||||
@@ -99,7 +99,7 @@ class _DotEnvLexer implements FlexLexer {
|
||||
private static final String ZZ_ROWMAP_PACKED_0 =
|
||||
"\0\0\0\13\0\26\0\41\0\54\0\67\0\102\0\115"+
|
||||
"\0\130\0\143\0\156\0\171\0\204\0\102\0\143\0\217"+
|
||||
"\0\232\0\156\0\245\0\260\0\143\0\273\0\306\0\321"+
|
||||
"\0\232\0\143\0\245\0\260\0\143\0\273\0\306\0\321"+
|
||||
"\0\334\0\115\0\347\0\362\0\171\0\375\0\321";
|
||||
|
||||
private static int [] zzUnpackRowMap() {
|
||||
@@ -185,8 +185,8 @@ class _DotEnvLexer implements FlexLexer {
|
||||
private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
|
||||
|
||||
private static final String ZZ_ATTRIBUTE_PACKED_0 =
|
||||
"\4\0\5\1\1\11\4\1\1\11\5\1\1\11\4\1"+
|
||||
"\1\0\5\1";
|
||||
"\4\0\5\1\1\11\4\1\1\11\2\1\1\11\2\1"+
|
||||
"\1\11\4\1\1\0\5\1";
|
||||
|
||||
private static int [] zzUnpackAttribute() {
|
||||
int [] result = new int[31];
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.intellij.lang.PsiBuilder.Marker;
|
||||
import static ru.adelf.idea.dotenv.psi.DotEnvTypes.*;
|
||||
import static com.intellij.lang.parser.GeneratedParserUtilBase.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.IFileElementType;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.lang.PsiParser;
|
||||
@@ -23,17 +24,11 @@ public class DotEnvParser implements PsiParser, LightPsiParser {
|
||||
boolean r;
|
||||
b = adapt_builder_(t, b, this, null);
|
||||
Marker m = enter_section_(b, 0, _COLLAPSE_, null);
|
||||
if (t == KEY) {
|
||||
r = key(b, 0);
|
||||
}
|
||||
else if (t == PROPERTY) {
|
||||
r = property(b, 0);
|
||||
}
|
||||
else if (t == VALUE) {
|
||||
r = value(b, 0);
|
||||
if (t instanceof IFileElementType) {
|
||||
r = parse_root_(t, b, 0);
|
||||
}
|
||||
else {
|
||||
r = parse_root_(t, b, 0);
|
||||
r = false;
|
||||
}
|
||||
exit_section_(b, 0, m, t, r, true, TRUE_CONDITION);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public interface DotEnvTypes {
|
||||
class Factory {
|
||||
public static PsiElement createElement(ASTNode node) {
|
||||
IElementType type = node.getElementType();
|
||||
if (type == KEY) {
|
||||
if (type == KEY) {
|
||||
return new DotEnvKeyImpl(node);
|
||||
}
|
||||
else if (type == PROPERTY) {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
// This is a generated file. Not intended for manual editing.
|
||||
package ru.adelf.idea.dotenv.psi.impl;
|
||||
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.*;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import static ru.adelf.idea.dotenv.psi.DotEnvTypes.*;
|
||||
import ru.adelf.idea.dotenv.psi.DotEnvNamedElementImpl;
|
||||
import ru.adelf.idea.dotenv.psi.*;
|
||||
|
||||
@@ -35,22 +38,27 @@ public class DotEnvPropertyImpl extends DotEnvNamedElementImpl implements DotEnv
|
||||
return findChildByClass(DotEnvValue.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeyText() {
|
||||
return DotEnvPsiUtil.getKeyText(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueText() {
|
||||
return DotEnvPsiUtil.getValueText(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return DotEnvPsiUtil.getName(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement setName(@NotNull String newName) {
|
||||
return DotEnvPsiUtil.setName(this, newName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement getNameIdentifier() {
|
||||
return DotEnvPsiUtil.getNameIdentifier(this);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@ package ru.adelf.idea.dotenv;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiRecursiveElementVisitor;
|
||||
import ru.adelf.idea.dotenv.models.EnvironmentKeyValue;
|
||||
import ru.adelf.idea.dotenv.models.KeyValuePsiElement;
|
||||
import ru.adelf.idea.dotenv.psi.DotEnvProperty;
|
||||
import ru.adelf.idea.dotenv.util.EnvironmentVariablesUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
@@ -12,16 +12,16 @@ import ru.adelf.idea.dotenv.psi.DotEnvTypes;
|
||||
|
||||
import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey;
|
||||
|
||||
public class DotEnvSyntaxHighlighter extends SyntaxHighlighterBase {
|
||||
public static final TextAttributesKey SEPARATOR =
|
||||
class DotEnvSyntaxHighlighter extends SyntaxHighlighterBase {
|
||||
private static final TextAttributesKey SEPARATOR =
|
||||
createTextAttributesKey("DOTENV_SEPARATOR", DefaultLanguageHighlighterColors.OPERATION_SIGN);
|
||||
public static final TextAttributesKey KEY =
|
||||
private static final TextAttributesKey KEY =
|
||||
createTextAttributesKey("DOTENV_KEY", DefaultLanguageHighlighterColors.KEYWORD);
|
||||
public static final TextAttributesKey VALUE =
|
||||
private static final TextAttributesKey VALUE =
|
||||
createTextAttributesKey("DOTENV_VALUE", DefaultLanguageHighlighterColors.STRING);
|
||||
public static final TextAttributesKey COMMENT =
|
||||
private static final TextAttributesKey COMMENT =
|
||||
createTextAttributesKey("DOTENV_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT);
|
||||
public static final TextAttributesKey BAD_CHARACTER =
|
||||
private static final TextAttributesKey BAD_CHARACTER =
|
||||
createTextAttributesKey("DOTENV_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER);
|
||||
|
||||
private static final TextAttributesKey[] BAD_CHAR_KEYS = new TextAttributesKey[]{BAD_CHARACTER};
|
||||
|
||||
@@ -89,7 +89,7 @@ public class EnvironmentVariablesApi {
|
||||
return true;
|
||||
}, GlobalSearchScope.allScope(project));
|
||||
|
||||
return (targets.size() > 0 ? targets : secondaryTargets).toArray(new PsiElement[0]);
|
||||
return (targets.size() > 0 ? targets : secondaryTargets).toArray(PsiElement.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,7 +116,7 @@ public class EnvironmentVariablesApi {
|
||||
return true;
|
||||
}, GlobalSearchScope.allScope(project));
|
||||
|
||||
return targets.toArray(new PsiElement[0]);
|
||||
return targets.toArray(PsiElement.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
private static FileAcceptResult getFileAcceptResult(VirtualFile virtualFile) {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package ru.adelf.idea.dotenv.extension;
|
||||
package ru.adelf.idea.dotenv.docker;
|
||||
|
||||
import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.yaml.psi.YAMLKeyValue;
|
||||
import org.jetbrains.yaml.psi.YAMLMapping;
|
||||
@@ -19,32 +20,32 @@ public class DockerComposeKeyGotoHandler implements GotoDeclarationHandler {
|
||||
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
|
||||
|
||||
if(psiElement == null) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
if(!psiElement.getContainingFile().getName().equals("docker-compose.yml") && !psiElement.getContainingFile().getName().equals("docker-compose.yaml")) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
if(psiElement.getParent() == null || psiElement.getParent().getParent() == null || psiElement.getParent().getParent().getParent() == null) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
psiElement = psiElement.getParent();
|
||||
|
||||
if(psiElement instanceof YAMLScalar) {
|
||||
if(!(psiElement.getParent() instanceof YAMLSequenceItem)) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
PsiElement yamlKeyValue = psiElement.getParent().getParent().getParent();
|
||||
|
||||
if(!(yamlKeyValue instanceof YAMLKeyValue)) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
if(!"environment".equals(((YAMLKeyValue) yamlKeyValue).getKeyText())) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
return EnvironmentVariablesApi.getKeyUsages(psiElement.getProject(), EnvironmentVariablesUtil.getKeyFromString(((YAMLScalar) psiElement).getTextValue()));
|
||||
@@ -52,28 +53,28 @@ public class DockerComposeKeyGotoHandler implements GotoDeclarationHandler {
|
||||
|
||||
if(psiElement instanceof YAMLKeyValue) {
|
||||
if(!(psiElement.getParent() instanceof YAMLMapping)) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
PsiElement yamlKeyValue = psiElement.getParent().getParent();
|
||||
|
||||
if(!(yamlKeyValue instanceof YAMLKeyValue)) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
if(!"environment".equals(((YAMLKeyValue) yamlKeyValue).getKeyText())) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
return EnvironmentVariablesApi.getKeyUsages(psiElement.getProject(), ((YAMLKeyValue) psiElement).getKeyText());
|
||||
}
|
||||
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getActionText(DataContext dataContext) {
|
||||
public String getActionText(@NotNull DataContext dataContext) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ class DockerComposeYamlPsiElementsVisitor extends PsiRecursiveElementVisitor {
|
||||
}
|
||||
|
||||
for(YAMLKeyValue keyValue : getMappingItems(yamlKeyValue)) {
|
||||
collectedItems.add(new KeyValuePsiElement(keyValue.getKeyText(), keyValue.getValueText(), keyValue.getKey()));
|
||||
collectedItems.add(new KeyValuePsiElement(keyValue.getKeyText(), keyValue.getValueText(), keyValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package ru.adelf.idea.dotenv.extension;
|
||||
package ru.adelf.idea.dotenv.docker;
|
||||
|
||||
import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.plugins.docker.dockerFile.parser.psi.DockerFileEnvRegularDeclaration;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi;
|
||||
import ru.adelf.idea.dotenv.util.EnvironmentVariablesUtil;
|
||||
@@ -16,17 +17,17 @@ public class DockerfileKeyGotoHandler implements GotoDeclarationHandler {
|
||||
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
|
||||
|
||||
if(psiElement == null || psiElement.getParent() == null) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
if(!psiElement.getContainingFile().getName().equals("Dockerfile")) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
psiElement = psiElement.getParent();
|
||||
|
||||
if(!(psiElement instanceof DockerFileEnvRegularDeclaration)) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
return EnvironmentVariablesApi.getKeyUsages(psiElement.getProject(), EnvironmentVariablesUtil.getKeyFromString((((DockerFileEnvRegularDeclaration) psiElement).getDeclaredName().getText())));
|
||||
@@ -34,7 +35,7 @@ public class DockerfileKeyGotoHandler implements GotoDeclarationHandler {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getActionText(DataContext dataContext) {
|
||||
public String getActionText(@NotNull DataContext dataContext) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -4,25 +4,27 @@ import com.intellij.lang.cacheBuilder.DefaultWordsScanner;
|
||||
import com.intellij.lang.cacheBuilder.WordsScanner;
|
||||
import com.intellij.lang.findUsages.FindUsagesProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.adelf.idea.dotenv.grammars.DotEnvLexerAdapter;
|
||||
import ru.adelf.idea.dotenv.psi.DotEnvProperty;
|
||||
import ru.adelf.idea.dotenv.psi.DotEnvTypes;
|
||||
|
||||
public class DotEnvFindUsagesProvider implements FindUsagesProvider {
|
||||
@Nullable
|
||||
@Override
|
||||
public WordsScanner getWordsScanner() {
|
||||
return null;/*new DefaultWordsScanner(new DotEnvLexerAdapter(),
|
||||
TokenSet.create(DotEnvTypes.KEY),
|
||||
return new DefaultWordsScanner(new DotEnvLexerAdapter(),
|
||||
TokenSet.create(DotEnvTypes.PROPERTY),
|
||||
TokenSet.create(DotEnvTypes.COMMENT),
|
||||
TokenSet.EMPTY);*/
|
||||
TokenSet.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFindUsagesFor(@NotNull PsiElement psiElement) {
|
||||
return true;//psiElement instanceof PsiNamedElement;
|
||||
return psiElement instanceof PsiNamedElement;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -34,33 +36,30 @@ public class DotEnvFindUsagesProvider implements FindUsagesProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getType(@NotNull PsiElement element) {
|
||||
// if (element instanceof SimpleProperty) {
|
||||
// return "simple property";
|
||||
// } else {
|
||||
if (element instanceof DotEnvProperty) {
|
||||
return "Environment variable";
|
||||
} else {
|
||||
return "";
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescriptiveName(@NotNull PsiElement element) {
|
||||
// if (element instanceof SimpleProperty) {
|
||||
// return ((SimpleProperty) element).getKey();
|
||||
// } else {
|
||||
// return "";
|
||||
// }
|
||||
return "";
|
||||
if (element instanceof DotEnvProperty) {
|
||||
return ((DotEnvProperty) element).getKeyText();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
|
||||
// if (element instanceof SimpleProperty) {
|
||||
// return ((SimpleProperty) element).getKey() + ":" + ((SimpleProperty) element).getValue();
|
||||
// } else {
|
||||
// return "";
|
||||
// }
|
||||
|
||||
return "";
|
||||
if (element instanceof DotEnvProperty) {
|
||||
return ((DotEnvProperty) element).getKeyText() + ":" + ((DotEnvProperty) element).getValueText();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,10 @@ import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi;
|
||||
import ru.adelf.idea.dotenv.psi.DotEnvKey;
|
||||
import ru.adelf.idea.dotenv.psi.DotEnvProperty;
|
||||
import ru.adelf.idea.dotenv.util.EnvironmentVariablesUtil;
|
||||
|
||||
public class DotEnvKeyGotoHandler implements GotoDeclarationHandler {
|
||||
|
||||
@@ -17,13 +16,13 @@ public class DotEnvKeyGotoHandler implements GotoDeclarationHandler {
|
||||
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
|
||||
|
||||
if(psiElement == null || psiElement.getParent() == null) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
psiElement = psiElement.getParent();
|
||||
|
||||
if(!(psiElement instanceof DotEnvKey)) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
return EnvironmentVariablesApi.getKeyUsages(psiElement.getProject(), psiElement.getText());
|
||||
@@ -31,7 +30,7 @@ public class DotEnvKeyGotoHandler implements GotoDeclarationHandler {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getActionText(DataContext dataContext) {
|
||||
public String getActionText(@NotNull DataContext dataContext) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package ru.adelf.idea.dotenv.extension;
|
||||
|
||||
import com.intellij.lang.refactoring.RefactoringSupportProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import ru.adelf.idea.dotenv.psi.DotEnvProperty;
|
||||
|
||||
public class DotEnvRefactoringSupportProvider extends RefactoringSupportProvider {
|
||||
@Override
|
||||
public boolean isMemberInplaceRenameAvailable(@NotNull PsiElement element, PsiElement context) {
|
||||
return element instanceof DotEnvProperty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package ru.adelf.idea.dotenv.extension;
|
||||
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class DotEnvReference extends PsiReferenceBase<PsiElement> implements PsiPolyVariantReference {
|
||||
private final String key;
|
||||
|
||||
public DotEnvReference(@NotNull PsiElement element, TextRange textRange) {
|
||||
super(element, textRange);
|
||||
key = element.getText().substring(textRange.getStartOffset(), textRange.getEndOffset());
|
||||
}
|
||||
|
||||
public DotEnvReference(@NotNull PsiElement element, TextRange textRange, String key) {
|
||||
super(element, textRange);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ResolveResult[] multiResolve(boolean incompleteCode) {
|
||||
final PsiElement[] elements = EnvironmentVariablesApi.getKeyDeclarations(myElement.getProject(), key);
|
||||
|
||||
return Arrays.stream(elements)
|
||||
.filter(psiElement -> psiElement instanceof PsiNamedElement)
|
||||
.map(PsiElementResolveResult::new)
|
||||
.toArray(ResolveResult[]::new);
|
||||
}
|
||||
|
||||
@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();
|
||||
final PsiElement[] elements = EnvironmentVariablesApi.getKeyDeclarations(project, key);
|
||||
|
||||
return Arrays.stream(elements)
|
||||
.filter(psiElement -> psiElement instanceof PsiNamedElement)
|
||||
.map(psiElement -> LookupElementBuilder.create(psiElement).
|
||||
withTypeText(psiElement.getContainingFile().getName()))
|
||||
.toArray(LookupElement[]::new);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package ru.adelf.idea.dotenv.extension;
|
||||
|
||||
import com.intellij.openapi.application.QueryExecutorBase;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.search.SearchRequestCollector;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
import com.intellij.psi.search.UsageSearchContext;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import ru.adelf.idea.dotenv.psi.DotEnvProperty;
|
||||
|
||||
public class DotEnvReferencesSearcher extends QueryExecutorBase<PsiReference, ReferencesSearch.SearchParameters> {
|
||||
public DotEnvReferencesSearcher() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<? super PsiReference> consumer) {
|
||||
PsiElement refElement = queryParameters.getElementToSearch();
|
||||
if (!(refElement instanceof DotEnvProperty)) return;
|
||||
|
||||
addPropertyUsages((DotEnvProperty)refElement, queryParameters.getEffectiveSearchScope(), queryParameters.getOptimizer());
|
||||
}
|
||||
|
||||
private static void addPropertyUsages(@NotNull DotEnvProperty property, @NotNull SearchScope scope, @NotNull SearchRequestCollector collector) {
|
||||
final String propertyName = property.getName();
|
||||
if (StringUtil.isNotEmpty(propertyName)) {
|
||||
/*SearchScope additional = GlobalSearchScope.EMPTY_SCOPE;
|
||||
for (CustomPropertyScopeProvider provider : CustomPropertyScopeProvider.EP_NAME.getExtensionList()) {
|
||||
additional = additional.union(provider.getScope(property.getProject()));
|
||||
}
|
||||
|
||||
SearchScope propScope = scope.intersectWith(property.getUseScope()).intersectWith(additional);*/
|
||||
collector.searchWord(propertyName, scope, UsageSearchContext.ANY, true, property);
|
||||
collector.searchWord("process.env." + propertyName, scope, UsageSearchContext.ANY, true, property);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class GoEnvCompletionProvider extends BaseEnvCompletionProvider implement
|
||||
public GoEnvCompletionProvider() {
|
||||
extend(CompletionType.BASIC, PlatformPatterns.psiElement(), new CompletionProvider<CompletionParameters>() {
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
|
||||
PsiElement psiElement = completionParameters.getOriginalPosition();
|
||||
if(psiElement == null || getStringLiteral(psiElement) == null) {
|
||||
@@ -36,15 +36,14 @@ public class GoEnvCompletionProvider extends BaseEnvCompletionProvider implement
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
|
||||
|
||||
if(psiElement == null) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
GoStringLiteral stringLiteral = getStringLiteral(psiElement);
|
||||
|
||||
if(stringLiteral == null) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), stringLiteral.getDecodedText());
|
||||
@@ -73,7 +72,7 @@ public class GoEnvCompletionProvider extends BaseEnvCompletionProvider implement
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getActionText(DataContext dataContext) {
|
||||
public String getActionText(@NotNull DataContext dataContext) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package ru.adelf.idea.dotenv.go;
|
||||
|
||||
import com.goide.psi.GoCallExpr;
|
||||
import com.goide.psi.GoStringLiteral;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiRecursiveElementVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import ru.adelf.idea.dotenv.models.KeyUsagePsiElement;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
class GoEnvironmentCallsVisitor extends PsiRecursiveElementVisitor {
|
||||
final private Collection<KeyUsagePsiElement> collectedItems = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public void visitElement(PsiElement element) {
|
||||
if(element instanceof GoCallExpr) {
|
||||
this.visitCall((GoCallExpr) element);
|
||||
}
|
||||
|
||||
super.visitElement(element);
|
||||
}
|
||||
|
||||
private void visitCall(GoCallExpr expression) {
|
||||
GoStringLiteral stringLiteral = GoPsiHelper.getEnvironmentGoLiteral(expression);
|
||||
if(stringLiteral != null) {
|
||||
collectedItems.add(new KeyUsagePsiElement(stringLiteral.getDecodedText(), stringLiteral));
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
Collection<KeyUsagePsiElement> getCollectedItems() {
|
||||
return collectedItems;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package ru.adelf.idea.dotenv.go;
|
||||
|
||||
import com.goide.GoFileType;
|
||||
import com.goide.psi.GoFile;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesUsagesProvider;
|
||||
import ru.adelf.idea.dotenv.models.KeyUsagePsiElement;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class GoEnvironmentVariablesUsagesProvider implements EnvironmentVariablesUsagesProvider {
|
||||
@Override
|
||||
public boolean acceptFile(VirtualFile file) {
|
||||
return file.getFileType().equals(GoFileType.INSTANCE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
|
||||
if(psiFile instanceof GoFile) {
|
||||
GoEnvironmentCallsVisitor visitor = new GoEnvironmentCallsVisitor();
|
||||
psiFile.acceptChildren(visitor);
|
||||
|
||||
return visitor.getCollectedItems();
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ class GoPsiHelper {
|
||||
* @param callExpression checking element
|
||||
* @return GoStringLiteral
|
||||
*/
|
||||
public static GoStringLiteral getEnvironmentGoLiteral(GoCallExpr callExpression) {
|
||||
static GoStringLiteral getEnvironmentGoLiteral(GoCallExpr callExpression) {
|
||||
GoReferenceExpression ref = GoPsiUtil.getCallReference(callExpression);
|
||||
if (ref == null) return null;
|
||||
|
||||
@@ -39,7 +39,7 @@ class GoPsiHelper {
|
||||
if (!ENV_FUNCTIONS.containsKey(functionName)) return null;
|
||||
|
||||
int position = ENV_FUNCTIONS.get(functionName);
|
||||
if (callExpression.getArgumentList().getExpressionList().size() < position+1) return null;
|
||||
if (callExpression.getArgumentList().getExpressionList().size() < position + 1) return null;
|
||||
|
||||
GoExpression expr = callExpression.getArgumentList().getExpressionList().get(position);
|
||||
if(!(expr instanceof GoStringLiteral)) return null;
|
||||
|
||||
@@ -17,7 +17,7 @@ import static ru.adelf.idea.dotenv.psi.DotEnvTypes.*;
|
||||
|
||||
CRLF=\R
|
||||
WHITE_SPACE=[\ \t\f]
|
||||
FIRST_VALUE_CHARACTER=[^ \n\f\r\"\\] | "\\".
|
||||
FIRST_VALUE_CHARACTER=[^ \n\f\r\"\\\#] | "\\".
|
||||
VALUE_CHARACTER=[^\r\n\#]
|
||||
QUOTED_VALUE_CHARACTER=[^\r\n\"]
|
||||
QUOTED_QUOTE="\\\""
|
||||
|
||||
@@ -19,7 +19,7 @@ public class JsEnvCompletionProvider extends BaseEnvCompletionProvider implement
|
||||
public JsEnvCompletionProvider() {
|
||||
extend(CompletionType.BASIC, PlatformPatterns.psiElement(), new CompletionProvider<CompletionParameters>() {
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
|
||||
PsiElement psiElement = completionParameters.getOriginalPosition();
|
||||
if(psiElement == null || !JsPsiHelper.checkPsiElement(psiElement)) {
|
||||
@@ -36,11 +36,11 @@ public class JsEnvCompletionProvider extends BaseEnvCompletionProvider implement
|
||||
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
|
||||
|
||||
if(psiElement == null) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
if(!JsPsiHelper.checkPsiElement(psiElement)) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), psiElement.getText());
|
||||
@@ -48,7 +48,7 @@ public class JsEnvCompletionProvider extends BaseEnvCompletionProvider implement
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getActionText(DataContext dataContext) {
|
||||
public String getActionText(@NotNull DataContext dataContext) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package ru.adelf.idea.dotenv.js;
|
||||
|
||||
import com.intellij.lang.javascript.psi.JSReferenceExpression;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.patterns.PlatformPatterns;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import ru.adelf.idea.dotenv.extension.DotEnvReference;
|
||||
|
||||
public class JsEnvReferenceContributor extends PsiReferenceContributor {
|
||||
@Override
|
||||
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
|
||||
registrar.registerReferenceProvider(PlatformPatterns.psiElement(JSReferenceExpression.class),
|
||||
new PsiReferenceProvider() {
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
|
||||
@NotNull ProcessingContext context) {
|
||||
JSReferenceExpression reference = (JSReferenceExpression) element;
|
||||
|
||||
if (!reference.getCanonicalText().startsWith("process.env.")) {
|
||||
return PsiReference.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
String value = reference.getCanonicalText();
|
||||
|
||||
return new PsiReference[]{new DotEnvReference(element, new TextRange(0, value.length()), value.substring(12))};
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package ru.adelf.idea.dotenv.extension;
|
||||
package ru.adelf.idea.dotenv.php;
|
||||
|
||||
import com.intellij.codeInsight.completion.*;
|
||||
import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler;
|
||||
@@ -12,13 +12,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi;
|
||||
import ru.adelf.idea.dotenv.common.BaseEnvCompletionProvider;
|
||||
import ru.adelf.idea.dotenv.util.PsiUtil;
|
||||
|
||||
public class DotEnvCompletionContributor extends BaseEnvCompletionProvider implements GotoDeclarationHandler {
|
||||
public DotEnvCompletionContributor() {
|
||||
public class PhpEnvCompletionContributor extends BaseEnvCompletionProvider implements GotoDeclarationHandler {
|
||||
public PhpEnvCompletionContributor() {
|
||||
extend(CompletionType.BASIC, PlatformPatterns.psiElement(), new CompletionProvider<CompletionParameters>() {
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
|
||||
PsiElement psiElement = completionParameters.getOriginalPosition();
|
||||
if(psiElement == null || getStringLiteral(psiElement) == null) {
|
||||
@@ -35,13 +34,13 @@ public class DotEnvCompletionContributor extends BaseEnvCompletionProvider imple
|
||||
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
|
||||
|
||||
if(psiElement == null) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
StringLiteralExpression stringLiteral = getStringLiteral(psiElement);
|
||||
|
||||
if(stringLiteral == null) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), stringLiteral.getContents());
|
||||
@@ -55,7 +54,7 @@ public class DotEnvCompletionContributor extends BaseEnvCompletionProvider imple
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!PsiUtil.isEnvFunctionParameter(parent)) {
|
||||
if(!PhpPsiHelper.isEnvFunctionParameter(parent)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -64,7 +63,7 @@ public class DotEnvCompletionContributor extends BaseEnvCompletionProvider imple
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getActionText(DataContext dataContext) {
|
||||
public String getActionText(@NotNull DataContext dataContext) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package ru.adelf.idea.dotenv.php;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.patterns.PlatformPatterns;
|
||||
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import ru.adelf.idea.dotenv.extension.DotEnvReference;
|
||||
|
||||
public class PhpEnvReferenceContributor extends PsiReferenceContributor {
|
||||
@Override
|
||||
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
|
||||
registrar.registerReferenceProvider(PlatformPatterns.psiElement(StringLiteralExpression.class),
|
||||
new PsiReferenceProvider() {
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
|
||||
@NotNull ProcessingContext context) {
|
||||
StringLiteralExpression literal = (StringLiteralExpression) element;
|
||||
|
||||
if (!PhpPsiHelper.isEnvFunctionParameter(literal)) {
|
||||
return PsiReference.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
String value = literal.getContents();
|
||||
|
||||
return new PsiReference[]{new DotEnvReference(element, new TextRange(1, value.length() + 1))};
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import com.jetbrains.php.lang.psi.elements.FunctionReference;
|
||||
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import ru.adelf.idea.dotenv.models.KeyUsagePsiElement;
|
||||
import ru.adelf.idea.dotenv.util.PsiUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -24,7 +23,7 @@ class PhpEnvironmentCallsVisitor extends PsiRecursiveElementVisitor {
|
||||
|
||||
private void visitFunction(FunctionReference expression) {
|
||||
|
||||
if(!PsiUtil.isEnvFunction(expression)) return;
|
||||
if(!PhpPsiHelper.isEnvFunction(expression)) return;
|
||||
|
||||
PsiElement[] parameters = expression.getParameters();
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package ru.adelf.idea.dotenv.util;
|
||||
package ru.adelf.idea.dotenv.php;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.php.lang.psi.elements.FunctionReference;
|
||||
@@ -6,7 +6,7 @@ import com.jetbrains.php.lang.psi.elements.ParameterList;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class PsiUtil {
|
||||
class PhpPsiHelper {
|
||||
|
||||
/**
|
||||
* Checks that this element is first parameter of needed functions, like env('element')
|
||||
@@ -14,7 +14,7 @@ public class PsiUtil {
|
||||
* @param psiElement Checking psi element
|
||||
* @return true if it's needed parameter in needed function
|
||||
*/
|
||||
public static boolean isEnvFunctionParameter(PsiElement psiElement) {
|
||||
static boolean isEnvFunctionParameter(PsiElement psiElement) {
|
||||
return isFunctionParameter(psiElement, 0, "getenv", "env");
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class PsiUtil {
|
||||
* @param functionReference Checking reference
|
||||
* @return true if condition filled
|
||||
*/
|
||||
public static boolean isEnvFunction(FunctionReference functionReference) {
|
||||
static boolean isEnvFunction(FunctionReference functionReference) {
|
||||
|
||||
String name = functionReference.getName();
|
||||
|
||||
@@ -4,13 +4,13 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import ru.adelf.idea.dotenv.DotEnvFileType;
|
||||
|
||||
public class DotEnvElementFactory {
|
||||
public static DotEnvProperty createProperty(Project project, String name) {
|
||||
class DotEnvElementFactory {
|
||||
static DotEnvProperty createProperty(Project project, String name) {
|
||||
final DotEnvFile file = createFile(project, name);
|
||||
return (DotEnvProperty) file.getFirstChild();
|
||||
}
|
||||
|
||||
public static DotEnvFile createFile(Project project, String text) {
|
||||
private static DotEnvFile createFile(Project project, String text) {
|
||||
String name = "dummy.env";
|
||||
return (DotEnvFile) PsiFileFactory.getInstance(project).
|
||||
createFileFromText(name, DotEnvFileType.INSTANCE, text);
|
||||
|
||||
@@ -17,7 +17,7 @@ public class PythonEnvCompletionProvider extends BaseEnvCompletionProvider imple
|
||||
public PythonEnvCompletionProvider() {
|
||||
extend(CompletionType.BASIC, PlatformPatterns.psiElement(), new CompletionProvider<CompletionParameters>() {
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
|
||||
PsiElement psiElement = completionParameters.getOriginalPosition();
|
||||
if(psiElement == null || getStringLiteral(psiElement) == null) {
|
||||
@@ -34,13 +34,13 @@ public class PythonEnvCompletionProvider extends BaseEnvCompletionProvider imple
|
||||
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
|
||||
|
||||
if(psiElement == null) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
PyStringLiteralExpression stringLiteral = getStringLiteral(psiElement);
|
||||
|
||||
if(stringLiteral == null) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), stringLiteral.getStringValue());
|
||||
@@ -89,7 +89,7 @@ public class PythonEnvCompletionProvider extends BaseEnvCompletionProvider imple
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getActionText(DataContext dataContext) {
|
||||
public String getActionText(@NotNull DataContext dataContext) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class RubyEnvCompletionProvider extends BaseEnvCompletionProvider impleme
|
||||
public RubyEnvCompletionProvider() {
|
||||
extend(CompletionType.BASIC, PlatformPatterns.psiElement(), new CompletionProvider<CompletionParameters>() {
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
|
||||
PsiElement psiElement = completionParameters.getOriginalPosition();
|
||||
if(psiElement == null || getStringLiteral(psiElement) == null) {
|
||||
@@ -38,13 +38,13 @@ public class RubyEnvCompletionProvider extends BaseEnvCompletionProvider impleme
|
||||
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
|
||||
|
||||
if(psiElement == null) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
RStringLiteral stringLiteral = getStringLiteral(psiElement);
|
||||
|
||||
if(stringLiteral == null) {
|
||||
return new PsiElement[0];
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), stringLiteral.getContent());
|
||||
@@ -87,7 +87,7 @@ public class RubyEnvCompletionProvider extends BaseEnvCompletionProvider impleme
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getActionText(DataContext dataContext) {
|
||||
public String getActionText(@NotNull DataContext dataContext) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package ru.adelf.idea.dotenv.ruby;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.patterns.PlatformPatterns;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.ruby.ruby.lang.psi.basicTypes.stringLiterals.RStringLiteral;
|
||||
import org.jetbrains.plugins.ruby.ruby.lang.psi.expressions.RArrayIndexing;
|
||||
import org.jetbrains.plugins.ruby.ruby.lang.psi.variables.RConstant;
|
||||
import ru.adelf.idea.dotenv.extension.DotEnvReference;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class RubyEnvReferenceContributor extends PsiReferenceContributor {
|
||||
@Override
|
||||
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
|
||||
registrar.registerReferenceProvider(PlatformPatterns.psiElement(RStringLiteral.class),
|
||||
new PsiReferenceProvider() {
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
|
||||
@NotNull ProcessingContext context) {
|
||||
RStringLiteral literal = (RStringLiteral) element;
|
||||
|
||||
if (literal.getParent() == null) {
|
||||
return PsiReference.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
PsiElement array = literal.getParent().getParent();
|
||||
|
||||
if (!(array instanceof RArrayIndexing)) {
|
||||
return PsiReference.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
PsiElement receiver = ((RArrayIndexing) array).getReceiver();
|
||||
|
||||
if (!(receiver instanceof RConstant)) {
|
||||
return PsiReference.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
if (receiver.getFirstChild() == null) {
|
||||
return PsiReference.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
if (!Objects.equals(receiver.getFirstChild().getText(), "ENV")) {
|
||||
return PsiReference.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
return new PsiReference[]{new DotEnvReference(literal, new TextRange(1, literal.getTextLength() + 1))};
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package ru.adelf.idea.dotenv.util;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesProvider;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesUsagesProvider;
|
||||
@@ -17,7 +16,7 @@ public class EnvironmentVariablesProviderUtil {
|
||||
private static Set<EnvironmentVariablesProvider> getEnvVariablesProviders() {
|
||||
Set<EnvironmentVariablesProvider> providers = new HashSet<>();
|
||||
|
||||
Collections.addAll(providers, Extensions.getExtensions(ExtensionPointName.create("ru.adelf.idea.dotenv.environmentVariablesProvider")));
|
||||
Collections.addAll(providers, Extensions.getExtensions("ru.adelf.idea.dotenv.environmentVariablesProvider", null) );
|
||||
|
||||
return providers;
|
||||
}
|
||||
@@ -25,7 +24,7 @@ public class EnvironmentVariablesProviderUtil {
|
||||
private static Set<EnvironmentVariablesUsagesProvider> getEnvVariablesUsagesProviders() {
|
||||
Set<EnvironmentVariablesUsagesProvider> providers = new HashSet<>();
|
||||
|
||||
Collections.addAll(providers, Extensions.getExtensions(ExtensionPointName.create("ru.adelf.idea.dotenv.environmentVariablesUsagesProvider")));
|
||||
Collections.addAll(providers, Extensions.getExtensions("ru.adelf.idea.dotenv.environmentVariablesUsagesProvider", null));
|
||||
|
||||
return providers;
|
||||
}
|
||||
|
||||
@@ -33,17 +33,6 @@ public class EnvironmentVariablesUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getValueFromString(@NotNull String s) {
|
||||
int pos = s.indexOf("=");
|
||||
|
||||
if(pos == -1) {
|
||||
return "";
|
||||
} else {
|
||||
return s.substring(pos + 1).trim();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<PsiElement> getElementsByKey(String key, Collection<KeyValuePsiElement> items) {
|
||||
return items.stream().filter(item -> item.getKey().equals(key)).map(KeyValuePsiElement::getElement).collect(Collectors.toSet());
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<gotoDeclarationHandler implementation="ru.adelf.idea.dotenv.extension.DockerfileKeyGotoHandler"/>
|
||||
<gotoDeclarationHandler implementation="ru.adelf.idea.dotenv.docker.DockerfileKeyGotoHandler"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
@@ -3,8 +3,4 @@
|
||||
<completion.contributor language="go" implementationClass="ru.adelf.idea.dotenv.go.GoEnvCompletionProvider"/>
|
||||
<gotoDeclarationHandler implementation="ru.adelf.idea.dotenv.go.GoEnvCompletionProvider"/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="ru.adelf.idea.dotenv">
|
||||
<environmentVariablesUsagesProvider implementation="ru.adelf.idea.dotenv.go.GoEnvironmentVariablesUsagesProvider"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
@@ -2,6 +2,7 @@
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<completion.contributor language="JavaScript" implementationClass="ru.adelf.idea.dotenv.js.JsEnvCompletionProvider"/>
|
||||
<gotoDeclarationHandler implementation="ru.adelf.idea.dotenv.js.JsEnvCompletionProvider"/>
|
||||
<psi.referenceContributor implementation="ru.adelf.idea.dotenv.js.JsEnvReferenceContributor"/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="ru.adelf.idea.dotenv">
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<idea-plugin>
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<completion.contributor language="PHP" implementationClass="ru.adelf.idea.dotenv.extension.DotEnvCompletionContributor"/>
|
||||
<gotoDeclarationHandler implementation="ru.adelf.idea.dotenv.extension.DotEnvCompletionContributor"/>
|
||||
</extensions>
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<completion.contributor language="PHP" implementationClass="ru.adelf.idea.dotenv.php.PhpEnvCompletionContributor"/>
|
||||
<gotoDeclarationHandler implementation="ru.adelf.idea.dotenv.php.PhpEnvCompletionContributor"/>
|
||||
<psi.referenceContributor implementation="ru.adelf.idea.dotenv.php.PhpEnvReferenceContributor"/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="ru.adelf.idea.dotenv">
|
||||
<environmentVariablesUsagesProvider implementation="ru.adelf.idea.dotenv.php.PhpEnvironmentVariablesUsagesProvider"/>
|
||||
</extensions>
|
||||
<extensions defaultExtensionNs="ru.adelf.idea.dotenv">
|
||||
<environmentVariablesUsagesProvider
|
||||
implementation="ru.adelf.idea.dotenv.php.PhpEnvironmentVariablesUsagesProvider"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
@@ -1,8 +1,8 @@
|
||||
<idea-plugin>
|
||||
<id>ru.adelf.idea.dotenv</id>
|
||||
<name>.env files support</name>
|
||||
<version>0.7</version>
|
||||
<vendor email="adel.faiz@gmail.com" url="http://adelf.ru">Adel Fayzrakhmanov</vendor>
|
||||
<version>0.8</version>
|
||||
<vendor email="adel.faiz@gmail.com" url="https://adelf.tech">Adel Fayzrakhmanov</vendor>
|
||||
|
||||
<description><![CDATA[
|
||||
<a href="https://plugins.jetbrains.com/plugin/9525--env-files-support">Homepage</a> | <a href="https://github.com/adelf/idea-php-dotenv-plugin/">Github</a> | <a href="https://github.com/adelf/idea-php-dotenv-plugin/issues">Issues</a>.<br />
|
||||
@@ -26,7 +26,7 @@
|
||||
</ul>
|
||||
]]></change-notes>
|
||||
|
||||
<idea-version since-build="172.0"/>
|
||||
<idea-version since-build="191"/>
|
||||
|
||||
<extensionPoints>
|
||||
<extensionPoint qualifiedName="ru.adelf.idea.dotenv.environmentVariablesProvider" interface="ru.adelf.idea.dotenv.api.EnvironmentVariablesProvider"/>
|
||||
@@ -54,9 +54,16 @@
|
||||
<fileTypeFactory implementation="ru.adelf.idea.dotenv.DotEnvFileTypeFactory"/>
|
||||
<lang.parserDefinition language="DotEnv" implementationClass="ru.adelf.idea.dotenv.DotEnvParserDefinition"/>
|
||||
<lang.commenter language="DotEnv" implementationClass="ru.adelf.idea.dotenv.extension.DotEnvCommenter"/>
|
||||
<!--<lang.refactoringSupport language="DotEnv" implementationClass="ru.adelf.idea.dotenv.extension.DotEnvRefactoringSupportProvider"/>
|
||||
<lang.findUsagesProvider language="DotEnv" implementationClass="ru.adelf.idea.dotenv.extension.DotEnvFindUsagesProvider"/>
|
||||
<referencesSearch implementation="ru.adelf.idea.dotenv.extension.DotEnvReferencesSearcher"/>-->
|
||||
|
||||
<localInspection language="DotEnv" groupName="DotEnv"
|
||||
shortName="DotEnvDuplicateKeyInspection" displayName="Duplicate keys" enabledByDefault="true" level="WARNING"
|
||||
<localInspection language="DotEnv"
|
||||
groupName="DotEnv"
|
||||
shortName="DotEnvDuplicateKeyInspection"
|
||||
displayName="Duplicate keys"
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
implementationClass="ru.adelf.idea.dotenv.inspections.DuplicateKeyInspection"/>
|
||||
|
||||
<lang.syntaxHighlighterFactory language="DotEnv" implementationClass="ru.adelf.idea.dotenv.DotEnvSyntaxHighlighterFactory"/>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<completion.contributor language="ruby" implementationClass="ru.adelf.idea.dotenv.ruby.RubyEnvCompletionProvider"/>
|
||||
<gotoDeclarationHandler implementation="ru.adelf.idea.dotenv.ruby.RubyEnvCompletionProvider"/>
|
||||
<psi.referenceContributor implementation="ru.adelf.idea.dotenv.ruby.RubyEnvReferenceContributor"/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="ru.adelf.idea.dotenv">
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<gotoDeclarationHandler implementation="ru.adelf.idea.dotenv.extension.DockerComposeKeyGotoHandler"/>
|
||||
<gotoDeclarationHandler implementation="ru.adelf.idea.dotenv.docker.DockerComposeKeyGotoHandler"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
@@ -1,345 +1,39 @@
|
||||
package ru.adelf.idea.dotenv.tests;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LineMarkerInfo;
|
||||
import com.intellij.codeInsight.daemon.LineMarkerProvider;
|
||||
import com.intellij.codeInsight.daemon.LineMarkerProviders;
|
||||
import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.intention.IntentionManager;
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation;
|
||||
import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.navigation.GotoRelatedItem;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.fileTypes.LanguageFileType;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
import com.intellij.patterns.PlatformPatterns;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiRecursiveElementVisitor;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.indexing.FileBasedIndexImpl;
|
||||
import com.intellij.util.indexing.ID;
|
||||
import com.jetbrains.php.lang.psi.elements.Function;
|
||||
import com.jetbrains.php.lang.psi.elements.Method;
|
||||
import com.jetbrains.php.lang.psi.elements.PhpReference;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* @author Adel Fayzrakhmanov <adel.faiz@gmail.com>
|
||||
*
|
||||
* Copy of LaravelLightCodeInsightFixtureTestCase from laravel plugin
|
||||
*/
|
||||
public abstract class DotEnvLightCodeInsightFixtureTestCase extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
public void assertCompletionContains(LanguageFileType languageFileType, String configureByText, String... lookupStrings) {
|
||||
protected String basePath = "src/test/java/ru/adelf/idea/dotenv/tests/";
|
||||
|
||||
myFixture.configureByText(languageFileType, configureByText);
|
||||
myFixture.completeBasic();
|
||||
|
||||
checkContainsCompletion(lookupStrings);
|
||||
}
|
||||
|
||||
public void assertAtTextCompletionContains(String findByText, String... lookupStrings) {
|
||||
|
||||
final PsiElement element = myFixture.findElementByText(findByText, PsiElement.class);
|
||||
assert element != null : "No element found by text: " + findByText;
|
||||
myFixture.getEditor().getCaretModel().moveToOffset(element.getTextOffset() + 1);
|
||||
myFixture.completeBasic();
|
||||
|
||||
checkContainsCompletion(lookupStrings);
|
||||
}
|
||||
|
||||
public void assertCompletionNotContains(String text, String configureByText, String... lookupStrings) {
|
||||
|
||||
myFixture.configureByText(text, configureByText);
|
||||
myFixture.completeBasic();
|
||||
|
||||
assertFalse(myFixture.getLookupElementStrings().containsAll(Arrays.asList(lookupStrings)));
|
||||
}
|
||||
|
||||
public void assertCompletionNotContains(LanguageFileType languageFileType, String configureByText, String... lookupStrings) {
|
||||
|
||||
myFixture.configureByText(languageFileType, configureByText);
|
||||
myFixture.completeBasic();
|
||||
|
||||
assertFalse(myFixture.getLookupElementStrings().containsAll(Arrays.asList(lookupStrings)));
|
||||
}
|
||||
|
||||
public void assertCompletionContains(String filename, String configureByText, String... lookupStrings) {
|
||||
|
||||
myFixture.configureByText(filename, configureByText);
|
||||
myFixture.completeBasic();
|
||||
|
||||
completionContainsAssert(lookupStrings);
|
||||
}
|
||||
|
||||
private void completionContainsAssert(String[] lookupStrings) {
|
||||
List<String> lookupElements = myFixture.getLookupElementStrings();
|
||||
if(lookupElements == null) {
|
||||
fail(String.format("failed that empty completion contains %s", Arrays.toString(lookupStrings)));
|
||||
}
|
||||
|
||||
for (String s : Arrays.asList(lookupStrings)) {
|
||||
if(!lookupElements.contains(s)) {
|
||||
fail(String.format("failed that completion contains %s in %s", s, lookupElements.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void assertNavigationContains(LanguageFileType languageFileType, String configureByText, String targetShortcut) {
|
||||
myFixture.configureByText(languageFileType, configureByText);
|
||||
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
|
||||
assertNavigationContains(psiElement, targetShortcut);
|
||||
}
|
||||
|
||||
public void assertNavigationContains(PsiElement psiElement, String targetShortcut) {
|
||||
|
||||
if(!targetShortcut.startsWith("\\")) {
|
||||
targetShortcut = "\\" + targetShortcut;
|
||||
}
|
||||
|
||||
Set<String> classTargets = new HashSet<String>();
|
||||
|
||||
for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
|
||||
PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor());
|
||||
if(gotoDeclarationTargets != null && gotoDeclarationTargets.length > 0) {
|
||||
|
||||
for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) {
|
||||
if(gotoDeclarationTarget instanceof Method) {
|
||||
|
||||
String meName = ((Method) gotoDeclarationTarget).getName();
|
||||
|
||||
String clName = ((Method) gotoDeclarationTarget).getContainingClass().getPresentableFQN();
|
||||
if(!clName.startsWith("\\")) {
|
||||
clName = "\\" + clName;
|
||||
}
|
||||
|
||||
classTargets.add(clName + "::" + meName);
|
||||
} else if(gotoDeclarationTarget instanceof Function) {
|
||||
classTargets.add("\\" + ((Function) gotoDeclarationTarget).getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(!classTargets.contains(targetShortcut)) {
|
||||
fail(String.format("failed that PsiElement (%s) navigate to %s on %s", psiElement.toString(), targetShortcut, classTargets.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void assertNavigationMatchWithParent(LanguageFileType languageFileType, String configureByText, IElementType iElementType) {
|
||||
assertNavigationMatch(languageFileType, configureByText, PlatformPatterns.psiElement().withParent(PlatformPatterns.psiElement(iElementType)));
|
||||
}
|
||||
|
||||
public void assertNavigationMatch(String filename, String configureByText, ElementPattern<?> pattern) {
|
||||
myFixture.configureByText(filename, configureByText);
|
||||
assertNavigationMatch(pattern);
|
||||
}
|
||||
|
||||
public void assertNavigationMatch(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) {
|
||||
myFixture.configureByText(languageFileType, configureByText);
|
||||
assertNavigationMatch(pattern);
|
||||
}
|
||||
|
||||
public void assertNavigationMatch(LanguageFileType languageFileType, String configureByText) {
|
||||
myFixture.configureByText(languageFileType, configureByText);
|
||||
assertNavigationMatch(PlatformPatterns.psiElement());
|
||||
}
|
||||
|
||||
public void assertNavigationMatch(String filename, String configureByText) {
|
||||
myFixture.configureByText(filename, configureByText);
|
||||
assertNavigationMatch(PlatformPatterns.psiElement());
|
||||
}
|
||||
|
||||
public void assertNavigationIsEmpty(LanguageFileType languageFileType, String configureByText) {
|
||||
myFixture.configureByText(languageFileType, configureByText);
|
||||
assertNavigationIsEmpty();
|
||||
}
|
||||
|
||||
public void assertNavigationIsEmpty(String content, String configureByText) {
|
||||
myFixture.configureByText(content, configureByText);
|
||||
assertNavigationIsEmpty();
|
||||
}
|
||||
|
||||
private void assertNavigationIsEmpty() {
|
||||
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
|
||||
for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
|
||||
PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor());
|
||||
if(gotoDeclarationTargets != null && gotoDeclarationTargets.length > 0) {
|
||||
fail(String.format("failed that PsiElement (%s) navigate is empty; found target in '%s'", psiElement.toString(), gotoDeclarationHandler.getClass()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void assertNavigationMatch(ElementPattern<?> pattern) {
|
||||
|
||||
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
|
||||
|
||||
Set<String> targetStrings = new HashSet<String>();
|
||||
|
||||
for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
|
||||
|
||||
PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor());
|
||||
if(gotoDeclarationTargets == null || gotoDeclarationTargets.length == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) {
|
||||
targetStrings.add(gotoDeclarationTarget.toString());
|
||||
if(pattern.accepts(gotoDeclarationTarget)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fail(String.format("failed that PsiElement (%s) navigate matches one of %s", psiElement.toString(), targetStrings.toString()));
|
||||
}
|
||||
|
||||
public void assertNavigationContainsFile(LanguageFileType languageFileType, String configureByText, String targetShortcut) {
|
||||
myFixture.configureByText(languageFileType, configureByText);
|
||||
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
|
||||
|
||||
Set<String> targets = new HashSet<String>();
|
||||
|
||||
for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
|
||||
PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor());
|
||||
if (gotoDeclarationTargets != null && gotoDeclarationTargets.length > 0) {
|
||||
for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) {
|
||||
if(gotoDeclarationTarget instanceof PsiFile) {
|
||||
targets.add(((PsiFile) gotoDeclarationTarget).getVirtualFile().getUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// its possible to have memory fields,
|
||||
// so simple check for ending conditions
|
||||
// temp:///src/interchange.en.xlf
|
||||
for (String target : targets) {
|
||||
if(target.endsWith(targetShortcut)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fail(String.format("failed that PsiElement (%s) navigate to file %s", psiElement.toString(), targetShortcut));
|
||||
}
|
||||
|
||||
public void assertCompletionLookupTailEquals(LanguageFileType languageFileType, String configureByText, String lookupString, String tailText) {
|
||||
assertCompletionLookup(languageFileType, configureByText, lookupString, new LookupElement.TailTextEqualsAssert(tailText));
|
||||
}
|
||||
|
||||
public void assertCompletionLookup(LanguageFileType languageFileType, String configureByText, String lookupString, LookupElement.Assert assertMatch) {
|
||||
|
||||
myFixture.configureByText(languageFileType, configureByText);
|
||||
myFixture.completeBasic();
|
||||
|
||||
for (com.intellij.codeInsight.lookup.LookupElement lookupElement : myFixture.getLookupElements()) {
|
||||
|
||||
if(!lookupElement.getLookupString().equals(lookupString)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
LookupElementPresentation presentation = new LookupElementPresentation();
|
||||
lookupElement.renderElement(presentation);
|
||||
|
||||
if(assertMatch.match(presentation)) {
|
||||
return;
|
||||
}
|
||||
|
||||
fail(String.format("fail that on element '%s' with '%s' matches '%s'", lookupString, assertMatch.getClass(), presentation.toString()));
|
||||
}
|
||||
|
||||
fail(String.format("failed to check '%s' because it's unknown", lookupString));
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void assertPhpReferenceResolveTo(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) {
|
||||
myFixture.configureByText(languageFileType, configureByText);
|
||||
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
|
||||
|
||||
psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class);
|
||||
if (psiElement == null) {
|
||||
fail("Element is not PhpReference.");
|
||||
}
|
||||
|
||||
assertTrue(pattern.accepts(((PhpReference) psiElement).resolve()));
|
||||
}
|
||||
|
||||
public void assertPhpReferenceNotResolveTo(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) {
|
||||
myFixture.configureByText(languageFileType, configureByText);
|
||||
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
|
||||
|
||||
psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class);
|
||||
if (psiElement == null) {
|
||||
fail("Element is not PhpReference.");
|
||||
}
|
||||
|
||||
assertFalse(pattern.accepts(((PhpReference) psiElement).resolve()));
|
||||
}
|
||||
|
||||
public void assertPhpReferenceSignatureEquals(LanguageFileType languageFileType, String configureByText, String typeSignature) {
|
||||
myFixture.configureByText(languageFileType, configureByText);
|
||||
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
|
||||
|
||||
psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class);
|
||||
if (!(psiElement instanceof PhpReference)) {
|
||||
fail("Element is not PhpReference.");
|
||||
}
|
||||
|
||||
assertEquals(typeSignature, ((PhpReference) psiElement).getSignature());
|
||||
}
|
||||
|
||||
public void assertCompletionResultEquals(String filename, String complete, String result) {
|
||||
myFixture.configureByText(filename, complete);
|
||||
myFixture.completeBasic();
|
||||
myFixture.checkResult(result);
|
||||
}
|
||||
|
||||
public void assertCompletionResultEquals(LanguageFileType languageFileType, String complete, String result) {
|
||||
myFixture.configureByText(languageFileType, complete);
|
||||
myFixture.completeBasic();
|
||||
myFixture.checkResult(result);
|
||||
}
|
||||
|
||||
public void assertCheckHighlighting(String filename, String result) {
|
||||
myFixture.configureByText(filename, result);
|
||||
myFixture.checkHighlighting();
|
||||
}
|
||||
|
||||
public void assertIndexContains(@NotNull ID<String, ?> id, @NotNull String... keys) {
|
||||
protected void assertIndexContains(@NotNull ID<String, ?> id, @NotNull String... keys) {
|
||||
assertIndex(id, false, keys);
|
||||
}
|
||||
|
||||
public void assertIndexNotContains(@NotNull ID<String, ?> id, @NotNull String... keys) {
|
||||
protected void assertIndexNotContains(@NotNull ID<String, ?> id, @NotNull String... keys) {
|
||||
assertIndex(id, true, keys);
|
||||
}
|
||||
|
||||
public void assertIndex(@NotNull ID<String, ?> id, boolean notCondition, @NotNull String... keys) {
|
||||
private void assertIndex(@NotNull ID<String, ?> id, boolean notCondition, @NotNull String... keys) {
|
||||
for (String key : keys) {
|
||||
final Collection<VirtualFile> virtualFiles = new ArrayList<>();
|
||||
|
||||
final Collection<VirtualFile> virtualFiles = new ArrayList<VirtualFile>();
|
||||
|
||||
FileBasedIndexImpl.getInstance().getFilesWithKey(id, new HashSet<String>(Arrays.asList(key)), new Processor<VirtualFile>() {
|
||||
@Override
|
||||
public boolean process(VirtualFile virtualFile) {
|
||||
virtualFiles.add(virtualFile);
|
||||
return true;
|
||||
}
|
||||
FileBasedIndexImpl.getInstance().getFilesWithKey(id, new HashSet<>(Collections.singletonList(key)), virtualFile -> {
|
||||
virtualFiles.add(virtualFile);
|
||||
return true;
|
||||
}, GlobalSearchScope.allScope(getProject()));
|
||||
|
||||
if(notCondition && virtualFiles.size() > 0) {
|
||||
@@ -349,258 +43,4 @@ public abstract class DotEnvLightCodeInsightFixtureTestCase extends LightCodeIns
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void assertIndexContainsKeyWithValue(@NotNull ID<String, String> id, @NotNull String key, @NotNull String value) {
|
||||
assertContainsElements(FileBasedIndexImpl.getInstance().getValues(id, key, GlobalSearchScope.allScope(getProject())), value);
|
||||
}
|
||||
|
||||
public <T> void assertIndexContainsKeyWithValue(@NotNull ID<String, T> id, @NotNull String key, @NotNull IndexValue.Assert<T> tAssert) {
|
||||
List<T> values = FileBasedIndexImpl.getInstance().getValues(id, key, GlobalSearchScope.allScope(getProject()));
|
||||
for (T t : values) {
|
||||
if(tAssert.match(t)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fail(String.format("Fail that Key '%s' matches on of '%s' values", key, values.size()));
|
||||
}
|
||||
|
||||
public void assertLocalInspectionContains(String filename, String content, String contains) {
|
||||
Set<String> matches = new HashSet<String>();
|
||||
|
||||
Pair<List<ProblemDescriptor>, Integer> localInspectionsAtCaret = getLocalInspectionsAtCaret(filename, content);
|
||||
for (ProblemDescriptor result : localInspectionsAtCaret.getFirst()) {
|
||||
TextRange textRange = result.getPsiElement().getTextRange();
|
||||
if (textRange.contains(localInspectionsAtCaret.getSecond()) && result.toString().equals(contains)) {
|
||||
return;
|
||||
}
|
||||
|
||||
matches.add(result.toString());
|
||||
}
|
||||
|
||||
fail(String.format("Fail matches '%s' with one of %s", contains, matches));
|
||||
}
|
||||
|
||||
public void assertIntentionIsAvailable(LanguageFileType languageFileType, String configureByText, String intentionText) {
|
||||
myFixture.configureByText(languageFileType, configureByText);
|
||||
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
|
||||
|
||||
for (IntentionAction intentionAction : IntentionManager.getInstance().getIntentionActions()) {
|
||||
if(intentionAction.isAvailable(getProject(), getEditor(), psiElement.getContainingFile()) && intentionAction.getText().equals(intentionText)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fail(String.format("Fail intention action '%s' is available in element '%s'", intentionText, psiElement.getText()));
|
||||
}
|
||||
|
||||
public void assertLocalInspectionContainsNotContains(String filename, String content, String contains) {
|
||||
Pair<List<ProblemDescriptor>, Integer> localInspectionsAtCaret = getLocalInspectionsAtCaret(filename, content);
|
||||
|
||||
for (ProblemDescriptor result : localInspectionsAtCaret.getFirst()) {
|
||||
TextRange textRange = result.getPsiElement().getTextRange();
|
||||
if (textRange.contains(localInspectionsAtCaret.getSecond())) {
|
||||
fail(String.format("Fail inspection not contains '%s'", contains));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Pair<List<ProblemDescriptor>, Integer> getLocalInspectionsAtCaret(String filename, String content) {
|
||||
|
||||
PsiElement psiFile = myFixture.configureByText(filename, content);
|
||||
|
||||
int caretOffset = myFixture.getCaretOffset();
|
||||
if(caretOffset <= 0) {
|
||||
fail("Please provide <caret> tag");
|
||||
}
|
||||
|
||||
ProblemsHolder problemsHolder = new ProblemsHolder(InspectionManager.getInstance(getProject()), psiFile.getContainingFile(), false);
|
||||
|
||||
for (LocalInspectionEP localInspectionEP : LocalInspectionEP.LOCAL_INSPECTION.getExtensions()) {
|
||||
Object object = localInspectionEP.getInstance();
|
||||
if(!(object instanceof LocalInspectionTool)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
((LocalInspectionTool) object).buildVisitor(problemsHolder, false);
|
||||
}
|
||||
|
||||
return new Pair<List<ProblemDescriptor>, Integer>(problemsHolder.getResults(), caretOffset);
|
||||
}
|
||||
|
||||
protected void assertLocalInspectionIsEmpty(String filename, String content) {
|
||||
Pair<List<ProblemDescriptor>, Integer> localInspectionsAtCaret = getLocalInspectionsAtCaret(filename, content);
|
||||
|
||||
for (ProblemDescriptor result : localInspectionsAtCaret.getFirst()) {
|
||||
TextRange textRange = result.getPsiElement().getTextRange();
|
||||
if (textRange.contains(localInspectionsAtCaret.getSecond())) {
|
||||
fail("Fail that matches is empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void createDummyFiles(String... files) throws Exception {
|
||||
for (String file : files) {
|
||||
String path = myFixture.getProject().getBaseDir().getPath() + "/" + file;
|
||||
File f = new File(path);
|
||||
f.getParentFile().mkdirs();
|
||||
f.createNewFile();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkContainsCompletion(String[] lookupStrings) {
|
||||
completionContainsAssert(lookupStrings);
|
||||
}
|
||||
|
||||
public void assertLineMarker(@NotNull PsiElement psiElement, @NotNull LineMarker.Assert assertMatch) {
|
||||
|
||||
final List<PsiElement> elements = collectPsiElementsRecursive(psiElement);
|
||||
|
||||
for (LineMarkerProvider lineMarkerProvider : LineMarkerProviders.INSTANCE.allForLanguage(psiElement.getLanguage())) {
|
||||
Collection<LineMarkerInfo> lineMarkerInfos = new ArrayList<LineMarkerInfo>();
|
||||
lineMarkerProvider.collectSlowLineMarkers(elements, lineMarkerInfos);
|
||||
|
||||
if(lineMarkerInfos.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (LineMarkerInfo lineMarkerInfo : lineMarkerInfos) {
|
||||
if(assertMatch.match(lineMarkerInfo)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fail(String.format("Fail that '%s' matches on of '%s' PsiElements", assertMatch.getClass(), elements.size()));
|
||||
}
|
||||
|
||||
public void assertLineMarkerIsEmpty(@NotNull PsiElement psiElement) {
|
||||
|
||||
final List<PsiElement> elements = collectPsiElementsRecursive(psiElement);
|
||||
|
||||
for (LineMarkerProvider lineMarkerProvider : LineMarkerProviders.INSTANCE.allForLanguage(psiElement.getLanguage())) {
|
||||
Collection<LineMarkerInfo> lineMarkerInfos = new ArrayList<LineMarkerInfo>();
|
||||
lineMarkerProvider.collectSlowLineMarkers(elements, lineMarkerInfos);
|
||||
|
||||
if(lineMarkerInfos.size() > 0) {
|
||||
fail(String.format("Fail that line marker is empty because it matches '%s'", lineMarkerProvider.getClass()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<PsiElement> collectPsiElementsRecursive(@NotNull PsiElement psiElement) {
|
||||
final List<PsiElement> elements = new ArrayList<PsiElement>();
|
||||
elements.add(psiElement.getContainingFile());
|
||||
|
||||
psiElement.acceptChildren(new PsiRecursiveElementVisitor() {
|
||||
@Override
|
||||
public void visitElement(PsiElement element) {
|
||||
elements.add(element);
|
||||
super.visitElement(element);
|
||||
}
|
||||
});
|
||||
return elements;
|
||||
}
|
||||
|
||||
public static class IndexValue {
|
||||
public interface Assert<T> {
|
||||
boolean match(@NotNull T value);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LineMarker {
|
||||
public interface Assert {
|
||||
boolean match(@NotNull LineMarkerInfo markerInfo);
|
||||
}
|
||||
|
||||
public static class ToolTipEqualsAssert implements Assert {
|
||||
@NotNull
|
||||
private final String toolTip;
|
||||
|
||||
public ToolTipEqualsAssert(@NotNull String toolTip) {
|
||||
this.toolTip = toolTip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(@NotNull LineMarkerInfo markerInfo) {
|
||||
return markerInfo.getLineMarkerTooltip() != null && markerInfo.getLineMarkerTooltip().equals(toolTip);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TargetAcceptsPattern implements Assert {
|
||||
|
||||
@NotNull
|
||||
private final String toolTip;
|
||||
@NotNull
|
||||
private final ElementPattern<? extends PsiElement> pattern;
|
||||
|
||||
public TargetAcceptsPattern(@NotNull String toolTip, @NotNull ElementPattern<? extends PsiElement> pattern) {
|
||||
this.toolTip = toolTip;
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(@NotNull LineMarkerInfo markerInfo) {
|
||||
if(markerInfo.getLineMarkerTooltip() == null || !markerInfo.getLineMarkerTooltip().equals(toolTip)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!(markerInfo instanceof RelatedItemLineMarkerInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Object o : ((RelatedItemLineMarkerInfo) markerInfo).createGotoRelatedItems()) {
|
||||
if(o instanceof GotoRelatedItem && this.pattern.accepts(((GotoRelatedItem) o).getElement())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class LookupElement {
|
||||
public interface Assert {
|
||||
boolean match(@NotNull LookupElementPresentation lookupElement);
|
||||
}
|
||||
|
||||
public static class TailTextEqualsAssert implements Assert {
|
||||
|
||||
@NotNull
|
||||
private final String contents;
|
||||
|
||||
public TailTextEqualsAssert(@NotNull String contents) {
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(@NotNull LookupElementPresentation lookupElement) {
|
||||
return this.contents.equals(lookupElement.getTailText());
|
||||
}
|
||||
}
|
||||
|
||||
public static class TypeTextEqualsAssert implements Assert {
|
||||
|
||||
@NotNull
|
||||
private final String contents;
|
||||
|
||||
public TypeTextEqualsAssert(@NotNull String contents) {
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(@NotNull LookupElementPresentation lookupElement) {
|
||||
return this.contents.equals(lookupElement.getTypeText());
|
||||
}
|
||||
}
|
||||
|
||||
public static class TailTextIsBlankAssert implements Assert {
|
||||
@Override
|
||||
public boolean match(@NotNull LookupElementPresentation lookupElement) {
|
||||
return StringUtils.isBlank(lookupElement.getTailText());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import ru.adelf.idea.dotenv.indexing.DotEnvKeyValuesIndex;
|
||||
import ru.adelf.idea.dotenv.indexing.DotEnvKeysIndex;
|
||||
import ru.adelf.idea.dotenv.tests.DotEnvLightCodeInsightFixtureTestCase;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class DotEnvFileTest extends DotEnvLightCodeInsightFixtureTestCase {
|
||||
|
||||
@Override
|
||||
@@ -15,7 +13,7 @@ public class DotEnvFileTest extends DotEnvLightCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
protected String getTestDataPath() {
|
||||
return new File(this.getClass().getResource("fixtures").getFile()).getAbsolutePath();
|
||||
return basePath + "dotenv/fixtures";
|
||||
}
|
||||
|
||||
public void testEnvKeys() {
|
||||
@@ -37,6 +35,11 @@ public class DotEnvFileTest extends DotEnvLightCodeInsightFixtureTestCase {
|
||||
assertIndexContains(DotEnvKeyValuesIndex.KEY,"COMMENTED_VAR4=\"1\"");
|
||||
}
|
||||
|
||||
public void testEnvEmptyCommentedVars() {
|
||||
assertIndexContains(DotEnvKeyValuesIndex.KEY,"COMMENTED_EMPTY=");
|
||||
assertIndexContains(DotEnvKeyValuesIndex.KEY,"COMMENTED_EMPTY2=");
|
||||
}
|
||||
|
||||
public void testEnvComments() {
|
||||
assertIndexNotContains(DotEnvKeysIndex.KEY,"Comment", "#Comment", "#Another comment");
|
||||
}
|
||||
|
||||
@@ -15,4 +15,7 @@ COMMENTED_VAR=123 #comment
|
||||
COMMENTED_VAR2="123 #comment"
|
||||
COMMENTED_VAR3="123 #com\"ment"
|
||||
|
||||
COMMENTED_VAR4="1"this should be commented
|
||||
COMMENTED_VAR4="1"this should be commented
|
||||
|
||||
COMMENTED_EMPTY=#comment
|
||||
COMMENTED_EMPTY2= #comment
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package ru.adelf.idea.dotenv.tests.usages;
|
||||
|
||||
import ru.adelf.idea.dotenv.indexing.DotEnvUsagesIndex;
|
||||
import ru.adelf.idea.dotenv.tests.DotEnvLightCodeInsightFixtureTestCase;
|
||||
|
||||
public class JsUsagesTest extends DotEnvLightCodeInsightFixtureTestCase {
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("usages.js"));
|
||||
}
|
||||
|
||||
protected String getTestDataPath() {
|
||||
return basePath + "usages/fixtures";
|
||||
}
|
||||
|
||||
public void testUsages() {
|
||||
assertIndexContains(DotEnvUsagesIndex.KEY,"JS_TEST");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package ru.adelf.idea.dotenv.tests.usages;
|
||||
|
||||
import ru.adelf.idea.dotenv.indexing.DotEnvUsagesIndex;
|
||||
import ru.adelf.idea.dotenv.tests.DotEnvLightCodeInsightFixtureTestCase;
|
||||
|
||||
public class PhpUsagesTest extends DotEnvLightCodeInsightFixtureTestCase {
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("usages.php"));
|
||||
}
|
||||
|
||||
protected String getTestDataPath() {
|
||||
return basePath + "usages/fixtures";
|
||||
}
|
||||
|
||||
public void testUsages() {
|
||||
assertIndexContains(DotEnvUsagesIndex.KEY,"PHP_TEST", "PHP_TEST2");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package ru.adelf.idea.dotenv.tests.usages;
|
||||
|
||||
import ru.adelf.idea.dotenv.indexing.DotEnvUsagesIndex;
|
||||
import ru.adelf.idea.dotenv.tests.DotEnvLightCodeInsightFixtureTestCase;
|
||||
|
||||
public class PythonUsagesTest extends DotEnvLightCodeInsightFixtureTestCase {
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("usages.py"));
|
||||
}
|
||||
|
||||
protected String getTestDataPath() {
|
||||
return basePath + "usages/fixtures";
|
||||
}
|
||||
|
||||
public void testUsages() {
|
||||
assertIndexContains(DotEnvUsagesIndex.KEY,"PYTHON_TEST", "PYTHON_TEST2");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package ru.adelf.idea.dotenv.tests.usages;
|
||||
|
||||
import ru.adelf.idea.dotenv.indexing.DotEnvUsagesIndex;
|
||||
import ru.adelf.idea.dotenv.tests.DotEnvLightCodeInsightFixtureTestCase;
|
||||
|
||||
public class RubyUsagesTest extends DotEnvLightCodeInsightFixtureTestCase {
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("usages.rb"));
|
||||
}
|
||||
|
||||
protected String getTestDataPath() {
|
||||
return basePath + "usages/fixtures";
|
||||
}
|
||||
|
||||
public void testUsages() {
|
||||
assertIndexContains(DotEnvUsagesIndex.KEY,"RUBY_TEST");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
alert(process.env.JS_TEST);
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
env('PHP_TEST');
|
||||
getenv('PHP_TEST2');
|
||||
@@ -0,0 +1,5 @@
|
||||
import os
|
||||
|
||||
def main():
|
||||
os.environ.get("PYTHON_TEST")
|
||||
os.getenv("PYTHON_TEST2")
|
||||
@@ -0,0 +1 @@
|
||||
ENV['RUBY_TEST']
|
||||
Reference in New Issue
Block a user