mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-1413 Show first line of docstring in Ctrl-hover popup
This commit is contained in:
@@ -69,11 +69,32 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i
|
||||
cat.append("class ").append(cls_name).append("\n");
|
||||
// It would be nice to have class import info here, but we don't know the ctrl+hovered reference and context
|
||||
}
|
||||
return $(cat.toString()).add(describeDecorators(func, LSame2, ", ", LSame1)).add(describeFunction(func, LSame2, LSame1)).toString();
|
||||
String summary = "";
|
||||
final PyStringLiteralExpression docStringExpression = func.getDocStringExpression();
|
||||
if (docStringExpression != null) {
|
||||
final StructuredDocString docString = StructuredDocString.parse(docStringExpression.getStringValue());
|
||||
if (docString != null)
|
||||
summary = docString.getSummary();
|
||||
}
|
||||
return $(cat.toString()).add(describeDecorators(func, LSame2, ", ", LSame1)).add(describeFunction(func, LSame2, LSame1))
|
||||
.toString() + summary;
|
||||
}
|
||||
else if (element instanceof PyClass) {
|
||||
PyClass cls = (PyClass)element;
|
||||
return describeDecorators(cls, LSame2, ", ", LSame1).add(describeClass(cls, LSame2, false, false)).toString();
|
||||
String summary = "";
|
||||
PyStringLiteralExpression docStringExpression = cls.getDocStringExpression();
|
||||
if (docStringExpression == null) {
|
||||
final PyFunction initOrNew = cls.findInitOrNew(false);
|
||||
if (initOrNew != null)
|
||||
docStringExpression = initOrNew.getDocStringExpression();
|
||||
}
|
||||
if (docStringExpression != null) {
|
||||
final StructuredDocString docString = StructuredDocString.parse(docStringExpression.getStringValue());
|
||||
if (docString != null)
|
||||
summary = docString.getSummary();
|
||||
}
|
||||
|
||||
return describeDecorators(cls, LSame2, ", ", LSame1).add(describeClass(cls, LSame2, false, false)).toString() + summary;
|
||||
}
|
||||
else if (element instanceof PyTargetExpression || element instanceof PyNamedParameter) {
|
||||
return describeExpression((PyExpression)element, originalElement);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.jetbrains.python.documentation;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -66,6 +67,15 @@ public abstract class StructuredDocString {
|
||||
return myDescription;
|
||||
}
|
||||
|
||||
public String getSummary() {
|
||||
final List<String> strings = StringUtil.split(StringUtil.trimLeading(myDescription), "\n", true, false);
|
||||
if (strings.size() > 1) {
|
||||
if (strings.get(1).isEmpty())
|
||||
return strings.get(0);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Map<Substring, Substring> getTagValuesMap(String key) {
|
||||
Map<Substring, Substring> map = myArgTagValues.get(key);
|
||||
|
||||
Reference in New Issue
Block a user