type comments are included in method completion

This commit is contained in:
aleksei.kniazev
2019-02-07 13:38:54 +03:00
committed by Aleksei Kniazev
parent dff84e5cf5
commit b81cefd91f
6 changed files with 50 additions and 9 deletions

View File

@@ -65,12 +65,21 @@ public class PySuperMethodCompletionContributor extends CompletionContributor {
for (PyClass ancestor : containingClass.getAncestorClasses(null)) {
for (PyFunction superMethod : ancestor.getMethods()) {
if (!seenNames.contains(superMethod.getName())) {
String text = superMethod.getName() + superMethod.getParameterList().getText();
if (languageLevel.isAtLeast(LanguageLevel.PYTHON35) && superMethod.getAnnotation() != null) {
text += " " + superMethod.getAnnotation().getText();
StringBuilder builder = new StringBuilder();
builder.append(superMethod.getName())
.append(superMethod.getParameterList().getText());
if (superMethod.getAnnotation() != null) {
builder.append(" ")
.append(superMethod.getAnnotation().getText())
.append(":");
} else if (superMethod.getTypeComment() != null) {
builder.append(": ")
.append(superMethod.getTypeComment().getText());
} else {
builder.append(":");
}
LookupElementBuilder element = LookupElementBuilder.create(text);
result.addElement(TailTypeDecorator.withTail(element, TailType.CASE_COLON));
LookupElementBuilder element = LookupElementBuilder.create(builder.toString());
result.addElement(TailTypeDecorator.withTail(element, TailType.NONE));
seenNames.add(superMethod.getName());
}
}

View File

@@ -1,7 +1,9 @@
from typing import Dict
class Parent:
def overridable_method(param: str) -> Dict[str, str]:
def overridable_method(self, param: str) -> Dict[str, str]:
pass
class Child(Parent):
def overridable_method(param: str) -> Dict[str, str]:
def overridable_method(self, param: str) -> Dict[str, str]:

View File

@@ -1,5 +1,7 @@
from typing import Dict
class Parent:
def overridable_method(param: str) -> Dict[str, str]:
def overridable_method(self, param: str) -> Dict[str, str]:
pass

View File

@@ -0,0 +1,13 @@
from typing import Dict
class Parent:
def overridable_method(self,
param # type: str
): # type: (...) -> Dict[str, str]
pass
class Child(Parent):
def overridable_method(self,
param # type: str
): # type: (...) -> Dict[str, str]

View File

@@ -0,0 +1,11 @@
from typing import Dict
class Parent:
def overridable_method(self,
param # type: str
): # type: (...) -> Dict[str, str]
pass
class Child(Parent):
def over<caret>

View File

@@ -315,7 +315,11 @@ public class PythonCompletionTest extends PyTestCase {
}
public void testSuperMethodWithAnnotation() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest);
doTest();
}
public void testSuperMethodWithCommentAnnotation() {
doTest();
}
public void testLocalVarInDictKey() { // PY-2558