mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-16412 Suggest the intention when the caret is at the identifier's end
This commit is contained in:
committed by
Andrey Vlasovskikh
parent
8c904faac4
commit
7c5c6d1a7e
+3
-1
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.TargetElementUtil;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
@@ -60,7 +61,8 @@ public class PyAnnotateVariableTypeIntention extends PyBaseIntentionAction {
|
||||
|
||||
@NotNull
|
||||
private static List<PyTargetExpression> findSuitableTargetsUnderCaret(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
final PyReferenceOwner elementAtCaret = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()),
|
||||
final int offset = TargetElementUtil.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset());
|
||||
final PyReferenceOwner elementAtCaret = PsiTreeUtil.getParentOfType(file.findElementAt(offset),
|
||||
PyReferenceExpression.class, PyTargetExpression.class);
|
||||
if (elementAtCaret == null) {
|
||||
return Collections.emptyList();
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
var<caret> = 42
|
||||
+1
@@ -0,0 +1 @@
|
||||
var: [int] = 42
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
var = 42
|
||||
var<caret>
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
var: [int] = 42
|
||||
var
|
||||
+8
@@ -191,6 +191,14 @@ public class PyAnnotateVariableTypeIntentionTest extends PyIntentionTestCase {
|
||||
doNegativeTest();
|
||||
}
|
||||
|
||||
public void testAnnotationCaretAtReferenceEnd() {
|
||||
doAnnotationTest();
|
||||
}
|
||||
|
||||
public void testAnnotationCaretAtDefinitionNameEnd() {
|
||||
doAnnotationTest();
|
||||
}
|
||||
|
||||
private void doAnnotationTest() {
|
||||
doTest(LanguageLevel.PYTHON36);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user