diff options
author | 2024-02-11 22:28:36 +0100 | |
---|---|---|
committer | 2024-02-11 22:28:36 +0100 | |
commit | 0b7b1b2b5a136e157b733e9d9c7e1d250efae15d (patch) | |
tree | 23bd350b9dd5966a69a8e4b1cc8066ed2e7090ff /subprojects/language-ide/src | |
parent | refactor(language): scope shadowing (diff) | |
download | refinery-0b7b1b2b5a136e157b733e9d9c7e1d250efae15d.tar.gz refinery-0b7b1b2b5a136e157b733e9d9c7e1d250efae15d.tar.zst refinery-0b7b1b2b5a136e157b733e9d9c7e1d250efae15d.zip |
feat(language): filter content assist for imports
Diffstat (limited to 'subprojects/language-ide/src')
-rw-r--r-- | subprojects/language-ide/src/main/java/tools/refinery/language/ide/contentassist/ProblemCrossrefProposalProvider.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/subprojects/language-ide/src/main/java/tools/refinery/language/ide/contentassist/ProblemCrossrefProposalProvider.java b/subprojects/language-ide/src/main/java/tools/refinery/language/ide/contentassist/ProblemCrossrefProposalProvider.java index fa04a012..a09a475b 100644 --- a/subprojects/language-ide/src/main/java/tools/refinery/language/ide/contentassist/ProblemCrossrefProposalProvider.java +++ b/subprojects/language-ide/src/main/java/tools/refinery/language/ide/contentassist/ProblemCrossrefProposalProvider.java | |||
@@ -24,6 +24,7 @@ import tools.refinery.language.model.problem.*; | |||
24 | import tools.refinery.language.naming.NamingUtil; | 24 | import tools.refinery.language.naming.NamingUtil; |
25 | import tools.refinery.language.naming.ProblemQualifiedNameConverter; | 25 | import tools.refinery.language.naming.ProblemQualifiedNameConverter; |
26 | import tools.refinery.language.resource.ProblemResourceDescriptionStrategy; | 26 | import tools.refinery.language.resource.ProblemResourceDescriptionStrategy; |
27 | import tools.refinery.language.scoping.imports.ImportCollector; | ||
27 | import tools.refinery.language.utils.BuiltinSymbols; | 28 | import tools.refinery.language.utils.BuiltinSymbols; |
28 | import tools.refinery.language.utils.ProblemDesugarer; | 29 | import tools.refinery.language.utils.ProblemDesugarer; |
29 | import tools.refinery.language.utils.ProblemUtil; | 30 | import tools.refinery.language.utils.ProblemUtil; |
@@ -44,6 +45,9 @@ public class ProblemCrossrefProposalProvider extends IdeCrossrefProposalProvider | |||
44 | @Inject | 45 | @Inject |
45 | private ProblemDesugarer desugarer; | 46 | private ProblemDesugarer desugarer; |
46 | 47 | ||
48 | @Inject | ||
49 | private ImportCollector importCollector; | ||
50 | |||
47 | @Override | 51 | @Override |
48 | protected Iterable<IEObjectDescription> queryScope(IScope scope, CrossReference crossReference, | 52 | protected Iterable<IEObjectDescription> queryScope(IScope scope, CrossReference crossReference, |
49 | ContentAssistContext context) { | 53 | ContentAssistContext context) { |
@@ -110,6 +114,10 @@ public class ProblemCrossrefProposalProvider extends IdeCrossrefProposalProvider | |||
110 | return true; | 114 | return true; |
111 | } | 115 | } |
112 | 116 | ||
117 | if (eReference == ProblemPackage.Literals.IMPORT_STATEMENT__IMPORTED_MODULE) { | ||
118 | return importedModuleShouldBeVisible(candidate, context); | ||
119 | } | ||
120 | |||
113 | var candidateEObjectOrProxy = candidate.getEObjectOrProxy(); | 121 | var candidateEObjectOrProxy = candidate.getEObjectOrProxy(); |
114 | 122 | ||
115 | if (eReference.equals(ProblemPackage.Literals.REFERENCE_DECLARATION__OPPOSITE) && | 123 | if (eReference.equals(ProblemPackage.Literals.REFERENCE_DECLARATION__OPPOSITE) && |
@@ -127,6 +135,20 @@ public class ProblemCrossrefProposalProvider extends IdeCrossrefProposalProvider | |||
127 | candidateEObjectOrProxy); | 135 | candidateEObjectOrProxy); |
128 | } | 136 | } |
129 | 137 | ||
138 | private boolean importedModuleShouldBeVisible(IEObjectDescription candidate, ContentAssistContext context) { | ||
139 | var moduleKind = candidate.getUserData(ProblemResourceDescriptionStrategy.MODULE_KIND); | ||
140 | if (!ModuleKind.MODULE.getName().equals(moduleKind)) { | ||
141 | return false; | ||
142 | } | ||
143 | var resource = context.getResource(); | ||
144 | var candidateResourceUri = candidate.getEObjectURI().trimFragment(); | ||
145 | if (candidateResourceUri.equals(resource.getURI())) { | ||
146 | return false; | ||
147 | } | ||
148 | var imports = importCollector.getDirectImports(resource); | ||
149 | return !imports.toUriSet().contains(candidateResourceUri); | ||
150 | } | ||
151 | |||
130 | private static boolean oppositeShouldBeVisible(ReferenceDeclaration candidateReferenceDeclaration, | 152 | private static boolean oppositeShouldBeVisible(ReferenceDeclaration candidateReferenceDeclaration, |
131 | ContentAssistContext context) { | 153 | ContentAssistContext context) { |
132 | var referenceDeclaration = EcoreUtil2.getContainerOfType(context.getCurrentModel(), | 154 | var referenceDeclaration = EcoreUtil2.getContainerOfType(context.getCurrentModel(), |