Skip to content

Commit 1db1eed

Browse files
committed
Fix wrong template suggestion in auto-popup completion list
#KT-14098 Fixed
1 parent 013649e commit 1db1eed

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

kotlin-eclipse-ui/src/org/jetbrains/kotlin/ui/editors/codeassist/KotlinCompletionProcessor.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.jetbrains.kotlin.ui.editors.codeassist
1818

1919
import com.intellij.psi.PsiElement
20+
import com.intellij.psi.PsiFile
2021
import com.intellij.psi.util.PsiTreeUtil
2122
import org.eclipse.jdt.core.IJavaProject
2223
import org.eclipse.jdt.internal.ui.JavaPlugin
@@ -35,10 +36,8 @@ import org.eclipse.jface.text.contentassist.IContextInformation
3536
import org.eclipse.jface.text.contentassist.IContextInformationValidator
3637
import org.eclipse.jface.text.templates.TemplateContext
3738
import org.eclipse.jface.text.templates.TemplateProposal
38-
import org.jetbrains.kotlin.core.log.KotlinLogger
3939
import org.jetbrains.kotlin.descriptors.ClassDescriptor
4040
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
41-
import org.jetbrains.kotlin.eclipse.ui.utils.EditorUtil
4241
import org.jetbrains.kotlin.eclipse.ui.utils.KotlinImageProvider
4342
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
4443
import org.jetbrains.kotlin.name.Name
@@ -107,8 +106,8 @@ class KotlinCompletionProcessor(
107106
}
108107
if (psiElement != null) {
109108
addAll(generateKeywordProposals(identifierPart, psiElement))
109+
addAll(generateTemplateProposals(psiElement.containingFile, viewer, offset, identifierPart))
110110
}
111-
addAll(generateTemplateProposals(viewer, offset, identifierPart))
112111
}
113112
}
114113

@@ -163,14 +162,10 @@ class KotlinCompletionProcessor(
163162
}
164163
}
165164

166-
private fun generateTemplateProposals(viewer: ITextViewer, offset: Int, identifierPart: String): List<ICompletionProposal> {
167-
val file = editor.eclipseFile
168-
if (file == null) {
169-
KotlinLogger.logError("Failed to retrieve IFile from editor $editor", null)
170-
return emptyList()
171-
}
165+
private fun generateTemplateProposals(
166+
psiFile: PsiFile, viewer: ITextViewer, offset: Int, identifierPart: String): List<ICompletionProposal> {
172167

173-
val contextTypeIds = KotlinApplicableTemplateContext.getApplicableContextTypeIds(viewer, file, offset - identifierPart.length)
168+
val contextTypeIds = KotlinApplicableTemplateContext.getApplicableContextTypeIds(viewer, psiFile, offset - identifierPart.length)
174169
val region = Region(offset - identifierPart.length, identifierPart.length)
175170

176171
val templateIcon = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_TEMPLATE)

kotlin-eclipse-ui/src/org/jetbrains/kotlin/ui/editors/templates/KotlinApplicableTemplateContext.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@
2121
import java.util.List;
2222
import java.util.Set;
2323

24-
import org.eclipse.core.resources.IFile;
2524
import org.eclipse.jface.text.ITextViewer;
2625
import org.eclipse.jface.text.templates.Template;
2726
import org.jetbrains.annotations.NotNull;
2827
import org.jetbrains.annotations.Nullable;
29-
import org.jetbrains.kotlin.core.builder.KotlinPsiManager;
3028
import org.jetbrains.kotlin.eclipse.ui.utils.LineEndUtil;
3129
import org.jetbrains.kotlin.psi.KtFile;
3230

@@ -49,9 +47,8 @@ public static List<Template> getTemplatesByContextTypeIds(List<String> contextTy
4947
}
5048

5149
@NotNull
52-
public static List<String> getApplicableContextTypeIds(@NotNull ITextViewer viewer, @NotNull IFile file, int offset) {
50+
public static List<String> getApplicableContextTypeIds(@NotNull ITextViewer viewer, @NotNull PsiFile psiFile, int offset) {
5351
int offsetWithoutCr = LineEndUtil.convertCrToDocumentOffset(viewer.getDocument(), offset);
54-
PsiFile psiFile = KotlinPsiManager.INSTANCE.getParsedFile(file);
5552

5653
List<String> contextTypeIds = new ArrayList<String>();
5754
for (String contextTypeId : getAllContextTypeIds()) {

0 commit comments

Comments
 (0)