mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
PY-33254 Complete file paths in string literals assigned to variables that has something about file paths in their names
GitOrigin-RevId: 01a4dfc57348608597fbc13ce17fecdaa7c08e38
This commit is contained in:
committed by
intellij-monorepo-bot
parent
19700c4bfc
commit
c355b9b11c
@@ -1465,6 +1465,16 @@ public class PythonCompletionTest extends PyTestCase {
|
||||
doMultiFileTest();
|
||||
}
|
||||
|
||||
// PY-33254
|
||||
public void testAssignmentPatternStringPath() {
|
||||
doMultiFileTest();
|
||||
}
|
||||
|
||||
// PY-33254
|
||||
public void testQualifiedAssignmentPatternStringPath() {
|
||||
doMultiFileTest();
|
||||
}
|
||||
|
||||
// PY-8302
|
||||
public void testUndeclaredFunction() {
|
||||
myFixture.configureByFile("uninitialized/fun.py");
|
||||
|
||||
@@ -28,11 +28,23 @@ class PySoftFileReferenceContributor : PsiReferenceContributor() {
|
||||
val stringLiteral = psiElement(PyStringLiteralExpression::class.java)
|
||||
val pattern = psiElement()
|
||||
.andOr(stringLiteral.with(HardCodedCalleeName),
|
||||
stringLiteral.with(AssignmentMatchingNamePattern),
|
||||
stringLiteral.with(KeywordArgumentMatchingNamePattern),
|
||||
stringLiteral.with(CallArgumentMatchingParameterNamePattern))
|
||||
registrar.registerReferenceProvider(pattern, PySoftFileReferenceProvider)
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches string literals used in assignment statements where the assignment target has a name that has something about files or paths.
|
||||
*/
|
||||
private object AssignmentMatchingNamePattern : PatternCondition<PyStringLiteralExpression>("assignmentMatchingPattern") {
|
||||
override fun accepts(expr: PyStringLiteralExpression, context: ProcessingContext?): Boolean {
|
||||
val assignment = expr.parent as? PyAssignmentStatement ?: return false
|
||||
val targetNames = assignment.targets.filterIsInstance<PyTargetExpression>().mapNotNull { it.name }
|
||||
return targetNames.any(::matchesPathNamePattern)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches string literals used as function arguments where the corresponding function parameter has a name that has something about
|
||||
* files or paths.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
config_path = "foobar.txt"
|
||||
@@ -0,0 +1 @@
|
||||
config_path = "foo<caret>"
|
||||
@@ -0,0 +1,3 @@
|
||||
class C:
|
||||
def __init__(self):
|
||||
self.path = "foobar.txt"
|
||||
@@ -0,0 +1,3 @@
|
||||
class C:
|
||||
def __init__(self):
|
||||
self.path = "foo<caret>"
|
||||
Reference in New Issue
Block a user