mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:10:43 +07:00
settings for completion and storing environment variables values
GitOrigin-RevId: 51a90fda7ad9dcaeba09187744077693915ffd61
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d9498601b2
commit
ec0728b3aa
@@ -0,0 +1,31 @@
|
||||
package ru.adelf.idea.dotenv;
|
||||
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@State(name = "DotEnvSettings", storages = {@Storage("dot-env.xml")})
|
||||
public class DotEnvSettings implements PersistentStateComponent<DotEnvSettings> {
|
||||
public boolean completionEnabled = true;
|
||||
public boolean storeValues = true;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public DotEnvSettings getState() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(@NotNull DotEnvSettings state) {
|
||||
XmlSerializerUtil.copyBean(state, this);
|
||||
}
|
||||
|
||||
public static DotEnvSettings getInstance(Project project) {
|
||||
return ServiceManager.getService(project, DotEnvSettings.class);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.adelf.idea.dotenv.DotEnvSettings;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi;
|
||||
import ru.adelf.idea.dotenv.common.BaseEnvCompletionProvider;
|
||||
|
||||
@@ -24,7 +25,12 @@ public class GoEnvCompletionProvider extends BaseEnvCompletionProvider implement
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
|
||||
PsiElement psiElement = completionParameters.getOriginalPosition();
|
||||
if(psiElement == null || getStringLiteral(psiElement) == null) {
|
||||
|
||||
if (psiElement == null || !DotEnvSettings.getInstance(psiElement.getProject()).completionEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getStringLiteral(psiElement) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,13 +42,13 @@ public class GoEnvCompletionProvider extends BaseEnvCompletionProvider implement
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
|
||||
if(psiElement == null) {
|
||||
if (psiElement == null) {
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
GoStringLiteral stringLiteral = getStringLiteral(psiElement);
|
||||
|
||||
if(stringLiteral == null) {
|
||||
if (stringLiteral == null) {
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@@ -53,17 +59,17 @@ public class GoEnvCompletionProvider extends BaseEnvCompletionProvider implement
|
||||
private GoStringLiteral getStringLiteral(@NotNull PsiElement psiElement) {
|
||||
PsiElement parent = psiElement.getParent();
|
||||
|
||||
if(!(parent instanceof GoStringLiteral)) {
|
||||
if (!(parent instanceof GoStringLiteral)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(parent.getParent() == null) {
|
||||
if (parent.getParent() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PsiElement candidate = parent.getParent().getParent();
|
||||
|
||||
if(candidate instanceof GoCallExpr) {
|
||||
if (candidate instanceof GoCallExpr) {
|
||||
return GoPsiHelper.getEnvironmentGoLiteral((GoCallExpr) candidate);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.util.io.DataExternalizer;
|
||||
import com.intellij.util.io.EnumeratorStringDescriptor;
|
||||
import com.intellij.util.io.KeyDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import ru.adelf.idea.dotenv.DotEnvSettings;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesProvider;
|
||||
import ru.adelf.idea.dotenv.models.KeyValuePsiElement;
|
||||
import ru.adelf.idea.dotenv.util.EnvironmentVariablesProviderUtil;
|
||||
@@ -28,9 +29,15 @@ public class DotEnvKeyValuesIndex extends FileBasedIndexExtension<String, String
|
||||
return fileContent -> {
|
||||
final Map<String, String> map = new HashMap<>();
|
||||
|
||||
boolean storeValues = DotEnvSettings.getInstance(fileContent.getProject()).storeValues;
|
||||
|
||||
for (EnvironmentVariablesProvider provider : EnvironmentVariablesProviderUtil.PROVIDERS) {
|
||||
for (KeyValuePsiElement keyValueElement : provider.getElements(fileContent.getPsiFile())) {
|
||||
map.put(keyValueElement.getKey(), keyValueElement.getShortValue());
|
||||
if (storeValues) {
|
||||
map.put(keyValueElement.getKey(), keyValueElement.getShortValue());
|
||||
} else {
|
||||
map.put(keyValueElement.getKey(), "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +76,6 @@ public class DotEnvKeyValuesIndex extends FileBasedIndexExtension<String, String
|
||||
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return 5;
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.intellij.psi.PsiLiteralExpression;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.adelf.idea.dotenv.DotEnvSettings;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi;
|
||||
import ru.adelf.idea.dotenv.common.BaseEnvCompletionProvider;
|
||||
|
||||
@@ -22,7 +23,12 @@ public class JavaEnvCompletionContributor extends BaseEnvCompletionProvider impl
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
PsiElement psiElement = completionParameters.getOriginalPosition();
|
||||
if(psiElement == null || getStringLiteral(psiElement) == null) {
|
||||
|
||||
if (psiElement == null || !DotEnvSettings.getInstance(psiElement.getProject()).completionEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getStringLiteral(psiElement) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34,13 +40,13 @@ public class JavaEnvCompletionContributor extends BaseEnvCompletionProvider impl
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
|
||||
if(psiElement == null) {
|
||||
if (psiElement == null) {
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
PsiLiteralExpression stringLiteral = getStringLiteral(psiElement);
|
||||
|
||||
if(stringLiteral == null) {
|
||||
if (stringLiteral == null) {
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@@ -50,18 +56,18 @@ public class JavaEnvCompletionContributor extends BaseEnvCompletionProvider impl
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), (String)value);
|
||||
return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), (String) value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiLiteralExpression getStringLiteral(@NotNull PsiElement psiElement) {
|
||||
PsiElement parent = psiElement.getParent();
|
||||
|
||||
if(!(parent instanceof PsiLiteralExpression)) {
|
||||
if (!(parent instanceof PsiLiteralExpression)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!JavaPsiHelper.isEnvStringLiteral((PsiLiteralExpression) parent)) {
|
||||
if (!JavaPsiHelper.isEnvStringLiteral((PsiLiteralExpression) parent)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.adelf.idea.dotenv.DotEnvSettings;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi;
|
||||
import ru.adelf.idea.dotenv.common.BaseEnvCompletionProvider;
|
||||
|
||||
@@ -22,7 +23,12 @@ public class JsEnvCompletionProvider extends BaseEnvCompletionProvider implement
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
|
||||
PsiElement psiElement = completionParameters.getOriginalPosition();
|
||||
if(psiElement == null || !JsPsiHelper.checkPsiElement(psiElement)) {
|
||||
|
||||
if (psiElement == null || !DotEnvSettings.getInstance(psiElement.getProject()).completionEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!JsPsiHelper.checkPsiElement(psiElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -35,11 +41,11 @@ public class JsEnvCompletionProvider extends BaseEnvCompletionProvider implement
|
||||
@Override
|
||||
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
|
||||
|
||||
if(psiElement == null) {
|
||||
if (psiElement == null) {
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
if(!JsPsiHelper.checkPsiElement(psiElement)) {
|
||||
if (!JsPsiHelper.checkPsiElement(psiElement)) {
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.psi.KtLiteralStringTemplateEntry;
|
||||
import ru.adelf.idea.dotenv.DotEnvSettings;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi;
|
||||
import ru.adelf.idea.dotenv.common.BaseEnvCompletionProvider;
|
||||
|
||||
@@ -22,7 +23,12 @@ public class KotlinEnvCompletionContributor extends BaseEnvCompletionProvider im
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
PsiElement psiElement = completionParameters.getOriginalPosition();
|
||||
if (psiElement == null || getStringLiteral(psiElement) == null) {
|
||||
|
||||
if (psiElement == null || !DotEnvSettings.getInstance(psiElement.getProject()).completionEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getStringLiteral(psiElement) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.adelf.idea.dotenv.DotEnvSettings;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi;
|
||||
import ru.adelf.idea.dotenv.common.BaseEnvCompletionProvider;
|
||||
|
||||
@@ -23,7 +24,12 @@ public class PhpEnvCompletionContributor extends BaseEnvCompletionProvider imple
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
|
||||
PsiElement psiElement = completionParameters.getOriginalPosition();
|
||||
if(psiElement == null || getStringLiteral(psiElement) == null) {
|
||||
|
||||
if (psiElement == null || !DotEnvSettings.getInstance(psiElement.getProject()).completionEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getStringLiteral(psiElement) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,13 +42,13 @@ public class PhpEnvCompletionContributor extends BaseEnvCompletionProvider imple
|
||||
@Override
|
||||
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
|
||||
|
||||
if(psiElement == null) {
|
||||
if (psiElement == null) {
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
StringLiteralExpression stringLiteral = getStringLiteral(psiElement);
|
||||
|
||||
if(stringLiteral == null) {
|
||||
if (stringLiteral == null) {
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@@ -53,11 +59,11 @@ public class PhpEnvCompletionContributor extends BaseEnvCompletionProvider imple
|
||||
private StringLiteralExpression getStringLiteral(@NotNull PsiElement psiElement) {
|
||||
PsiElement parent = psiElement.getParent();
|
||||
|
||||
if(!(parent instanceof StringLiteralExpression)) {
|
||||
if (!(parent instanceof StringLiteralExpression)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!PhpPsiHelper.isEnvStringLiteral((StringLiteralExpression) parent)) {
|
||||
if (!PhpPsiHelper.isEnvStringLiteral((StringLiteralExpression) parent)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.intellij.psi.xml.XmlToken;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.adelf.idea.dotenv.DotEnvSettings;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi;
|
||||
import ru.adelf.idea.dotenv.common.BaseEnvCompletionProvider;
|
||||
|
||||
@@ -29,8 +30,14 @@ public class PhpunitEnvCompletionContributor extends BaseEnvCompletionProvider i
|
||||
extend(CompletionType.BASIC, PlatformPatterns.psiElement(XmlToken.class).withParent(XmlAttributeValue.class), new CompletionProvider<CompletionParameters>() {
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
|
||||
PsiElement psiElement = completionParameters.getOriginalPosition();
|
||||
if (psiElement == null || getXmlAttributeValue(psiElement) == null) {
|
||||
|
||||
if (psiElement == null || !DotEnvSettings.getInstance(psiElement.getProject()).completionEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getXmlAttributeValue(psiElement) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,7 +73,7 @@ public class PhpunitEnvCompletionContributor extends BaseEnvCompletionProvider i
|
||||
|
||||
if (!(attribute instanceof XmlAttribute)) return null;
|
||||
|
||||
if (!((XmlAttribute)attribute).getName().equals("name")) return null;
|
||||
if (!((XmlAttribute) attribute).getName().equals("name")) return null;
|
||||
|
||||
if (!(attribute.getParent() instanceof XmlTag)) return null;
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package ru.adelf.idea.dotenv.python;
|
||||
|
||||
import com.intellij.codeInsight.completion.*;
|
||||
import com.intellij.codeInsight.completion.CompletionParameters;
|
||||
import com.intellij.codeInsight.completion.CompletionProvider;
|
||||
import com.intellij.codeInsight.completion.CompletionResultSet;
|
||||
import com.intellij.codeInsight.completion.CompletionType;
|
||||
import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -10,6 +13,7 @@ import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.adelf.idea.dotenv.DotEnvSettings;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi;
|
||||
import ru.adelf.idea.dotenv.common.BaseEnvCompletionProvider;
|
||||
|
||||
@@ -20,7 +24,12 @@ public class PythonEnvCompletionProvider extends BaseEnvCompletionProvider imple
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
|
||||
PsiElement psiElement = completionParameters.getOriginalPosition();
|
||||
if(psiElement == null || getStringLiteral(psiElement) == null) {
|
||||
|
||||
if (psiElement == null || !DotEnvSettings.getInstance(psiElement.getProject()).completionEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getStringLiteral(psiElement) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,13 +42,13 @@ public class PythonEnvCompletionProvider extends BaseEnvCompletionProvider imple
|
||||
@Override
|
||||
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
|
||||
|
||||
if(psiElement == null) {
|
||||
if (psiElement == null) {
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
PyStringLiteralExpression stringLiteral = getStringLiteral(psiElement);
|
||||
|
||||
if(stringLiteral == null) {
|
||||
if (stringLiteral == null) {
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@@ -50,22 +59,22 @@ public class PythonEnvCompletionProvider extends BaseEnvCompletionProvider imple
|
||||
private PyStringLiteralExpression getStringLiteral(@NotNull PsiElement psiElement) {
|
||||
PsiElement parent = psiElement.getParent();
|
||||
|
||||
if(!(parent instanceof PyStringLiteralExpression)) {
|
||||
if (!(parent instanceof PyStringLiteralExpression)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(parent.getParent() == null) {
|
||||
if (parent.getParent() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PsiElement candidate = parent.getParent().getParent();
|
||||
|
||||
if(candidate instanceof PyCallExpression) {
|
||||
if (candidate instanceof PyCallExpression) {
|
||||
PyCallExpression callExpression = (PyCallExpression) candidate;
|
||||
if(PythonPsiHelper.checkGetMethodCall(callExpression)
|
||||
&& callExpression.getArgumentList() != null
|
||||
&& callExpression.getArgumentList().getArguments().length > 0
|
||||
&& callExpression.getArgumentList().getArguments()[0].isEquivalentTo(parent)) {
|
||||
if (PythonPsiHelper.checkGetMethodCall(callExpression)
|
||||
&& callExpression.getArgumentList() != null
|
||||
&& callExpression.getArgumentList().getArguments().length > 0
|
||||
&& callExpression.getArgumentList().getArguments()[0].isEquivalentTo(parent)) {
|
||||
|
||||
return (PyStringLiteralExpression) parent;
|
||||
}
|
||||
@@ -73,10 +82,10 @@ public class PythonEnvCompletionProvider extends BaseEnvCompletionProvider imple
|
||||
return null;
|
||||
}
|
||||
|
||||
if(candidate instanceof PyAssignmentStatement) {
|
||||
if (candidate instanceof PyAssignmentStatement) {
|
||||
PyExpression assignedValue = ((PyAssignmentStatement) candidate).getAssignedValue();
|
||||
if(assignedValue instanceof PySubscriptionExpression) {
|
||||
if(PythonPsiHelper.checkIndexCall((PySubscriptionExpression) assignedValue)) {
|
||||
if (assignedValue instanceof PySubscriptionExpression) {
|
||||
if (PythonPsiHelper.checkIndexCall((PySubscriptionExpression) assignedValue)) {
|
||||
return (PyStringLiteralExpression) parent;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package ru.adelf.idea.dotenv.ruby;
|
||||
|
||||
import com.intellij.codeInsight.completion.*;
|
||||
import com.intellij.codeInsight.completion.CompletionParameters;
|
||||
import com.intellij.codeInsight.completion.CompletionProvider;
|
||||
import com.intellij.codeInsight.completion.CompletionResultSet;
|
||||
import com.intellij.codeInsight.completion.CompletionType;
|
||||
import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -12,6 +15,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
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.DotEnvSettings;
|
||||
import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi;
|
||||
import ru.adelf.idea.dotenv.common.BaseEnvCompletionProvider;
|
||||
|
||||
@@ -24,7 +28,12 @@ public class RubyEnvCompletionProvider extends BaseEnvCompletionProvider impleme
|
||||
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
|
||||
|
||||
PsiElement psiElement = completionParameters.getOriginalPosition();
|
||||
if(psiElement == null || getStringLiteral(psiElement) == null) {
|
||||
|
||||
if (psiElement == null || !DotEnvSettings.getInstance(psiElement.getProject()).completionEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getStringLiteral(psiElement) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,13 +46,13 @@ public class RubyEnvCompletionProvider extends BaseEnvCompletionProvider impleme
|
||||
@Override
|
||||
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
|
||||
|
||||
if(psiElement == null) {
|
||||
if (psiElement == null) {
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
RStringLiteral stringLiteral = getStringLiteral(psiElement);
|
||||
|
||||
if(stringLiteral == null) {
|
||||
if (stringLiteral == null) {
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@@ -54,31 +63,31 @@ public class RubyEnvCompletionProvider extends BaseEnvCompletionProvider impleme
|
||||
private RStringLiteral getStringLiteral(@NotNull PsiElement psiElement) {
|
||||
PsiElement parent = psiElement.getParent();
|
||||
|
||||
if(!(parent instanceof RStringLiteral)) {
|
||||
if (!(parent instanceof RStringLiteral)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(parent.getParent() == null) {
|
||||
if (parent.getParent() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PsiElement array = parent.getParent().getParent();
|
||||
|
||||
if(!(array instanceof RArrayIndexing)) {
|
||||
if (!(array instanceof RArrayIndexing)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PsiElement receiver = ((RArrayIndexing) array).getReceiver();
|
||||
|
||||
if(!(receiver instanceof RConstant)) {
|
||||
if (!(receiver instanceof RConstant)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(receiver.getFirstChild() == null) {
|
||||
if (receiver.getFirstChild() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!Objects.equals(receiver.getFirstChild().getText(), "ENV")) {
|
||||
if (!Objects.equals(receiver.getFirstChild().getText(), "ENV")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package ru.adelf.idea.dotenv.ui;
|
||||
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.adelf.idea.dotenv.DotEnvSettings;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
public class DotEnvSettingsConfigurable implements Configurable {
|
||||
|
||||
private final Project project;
|
||||
|
||||
public DotEnvSettingsConfigurable(@NotNull final Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
private JCheckBox completionEnabledCheckbox;
|
||||
private JCheckBox storeValuesCheckbox;
|
||||
|
||||
@Nls
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "DotEnv";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
DotEnvSettings settings = getSettings();
|
||||
Border standardBorder = BorderFactory.createEmptyBorder(5, 5, 5, 5);
|
||||
|
||||
completionEnabledCheckbox = new JCheckBox("Enable environment variables completions", settings.completionEnabled);
|
||||
completionEnabledCheckbox.setBorder(standardBorder);
|
||||
|
||||
storeValuesCheckbox = new JCheckBox("Store and complete values", settings.storeValues);
|
||||
storeValuesCheckbox.setBorder(standardBorder);
|
||||
storeValuesCheckbox.setToolTipText("Storing values in the indices can be turned off due to security reasons");
|
||||
|
||||
JLabel storeValuesInvalidateCachesLabel = new JLabel("Run File > Invalidate Caches... to update indices");
|
||||
storeValuesInvalidateCachesLabel.setBorder(standardBorder);
|
||||
storeValuesInvalidateCachesLabel.setVisible(false);
|
||||
|
||||
storeValuesCheckbox.addChangeListener(e -> storeValuesInvalidateCachesLabel.setVisible(storeValuesCheckbox.isSelected() != getSettings().storeValues));
|
||||
|
||||
JPanel rootPanel = new JPanel();
|
||||
rootPanel.setLayout(new BoxLayout(rootPanel, BoxLayout.PAGE_AXIS));
|
||||
rootPanel.add(completionEnabledCheckbox);
|
||||
rootPanel.add(storeValuesCheckbox);
|
||||
rootPanel.add(storeValuesInvalidateCachesLabel);
|
||||
|
||||
return rootPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return !completionEnabledCheckbox.isSelected() == getSettings().completionEnabled
|
||||
|| !storeValuesCheckbox.isSelected() == getSettings().storeValues
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
getSettings().completionEnabled = completionEnabledCheckbox.isSelected();
|
||||
getSettings().storeValues = storeValuesCheckbox.isSelected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
completionEnabledCheckbox.setSelected(getSettings().completionEnabled);
|
||||
storeValuesCheckbox.setSelected(getSettings().storeValues);
|
||||
}
|
||||
|
||||
private DotEnvSettings getSettings() {
|
||||
return DotEnvSettings.getInstance(this.project);
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,7 @@
|
||||
<depends optional="true" config-file="yaml.xml">org.jetbrains.plugins.yaml</depends>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<projectService serviceImplementation="ru.adelf.idea.dotenv.DotEnvSettings"/>
|
||||
<gotoDeclarationHandler implementation="ru.adelf.idea.dotenv.extension.DotEnvKeyGotoHandler"/>
|
||||
|
||||
<fileBasedIndex implementation="ru.adelf.idea.dotenv.indexing.DotEnvKeyValuesIndex"/>
|
||||
@@ -104,6 +105,13 @@
|
||||
|
||||
<lang.syntaxHighlighterFactory language="DotEnv"
|
||||
implementationClass="ru.adelf.idea.dotenv.DotEnvSyntaxHighlighterFactory"/>
|
||||
|
||||
<projectConfigurable instance="ru.adelf.idea.dotenv.ui.DotEnvSettingsConfigurable"
|
||||
id="DotEnv.SettingsForm"
|
||||
displayName="DotEnv"
|
||||
groupId="language"
|
||||
nonDefaultProject="true"
|
||||
/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="ru.adelf.idea.dotenv">
|
||||
|
||||
Reference in New Issue
Block a user