mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Update PythonDocumentationProvider.describeFunction
This commit is contained in:
@@ -35,10 +35,7 @@ class DocumentationBuilderKit {
|
||||
static final TagWrapper TagCode = new TagWrapper("code");
|
||||
static final TagWrapper TagSpan = new TagWrapper("span");
|
||||
|
||||
static final Function<String, String> LCombUp = argname -> combUp(argname);
|
||||
final static @NonNls String BR = "<br>";
|
||||
static final Function<String, String> LSame1 = name -> name;
|
||||
static final Function<Iterable<String>, Iterable<String>> LSame2 = what -> what;
|
||||
|
||||
@NotNull
|
||||
static final Function<String, String> ESCAPE_ONLY = StringUtil::escapeXml;
|
||||
|
||||
@@ -303,7 +303,7 @@ public class PyDocumentationBuilder {
|
||||
}
|
||||
}
|
||||
myBody.add(PythonDocumentationProvider.describeDecorators(pyFunction, WRAP_IN_ITALIC, ESCAPE_AND_SAVE_NEW_LINES_AND_SPACES, BR, BR));
|
||||
myBody.add(PythonDocumentationProvider.describeFunction(pyFunction, TagBold, LCombUp));
|
||||
myBody.add(PythonDocumentationProvider.describeFunction(pyFunction, WRAP_IN_BOLD, ESCAPE_AND_SAVE_NEW_LINES_AND_SPACES, context));
|
||||
if (docStringExpression == null) {
|
||||
addInheritedDocString(pyFunction, pyClass);
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i
|
||||
}
|
||||
return $(cat.toString())
|
||||
.add(describeDecorators(func, Function.identity(), TO_ONE_LINE_AND_ESCAPE, ", ", "\n"))
|
||||
.add(describeFunction(func, LSame2, LSame1))
|
||||
.add(describeFunction(func, Function.identity(), ESCAPE_ONLY, context))
|
||||
.toString() + "\n" + summary;
|
||||
}
|
||||
else if (element instanceof PyClass) {
|
||||
@@ -133,29 +133,25 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a HTML description of function definition.
|
||||
*
|
||||
* @param fun the function
|
||||
* @param funcNameWrapper puts a tag around the function name
|
||||
* @param escaper sanitizes values that come directly from doc string or code
|
||||
* @return chain of strings for further chaining
|
||||
*/
|
||||
@NotNull
|
||||
static ChainIterable<String> describeFunction(@NotNull PyFunction fun,
|
||||
Function<Iterable<String>, Iterable<String>> funcNameWrapper,
|
||||
@NotNull Function<String, String> escaper
|
||||
) {
|
||||
final ChainIterable<String> cat = new ChainIterable<>();
|
||||
final String name = fun.getName();
|
||||
cat.addItem("def ").addWith(funcNameWrapper, $(name));
|
||||
cat.addItem(escaper.apply(PyUtil.getReadableRepr(fun.getParameterList(), false)));
|
||||
static ChainIterable<String> describeFunction(@NotNull PyFunction function,
|
||||
@NotNull Function<String, String> escapedNameMapper,
|
||||
@NotNull Function<String, String> escaper,
|
||||
@NotNull TypeEvalContext context) {
|
||||
final ChainIterable<String> result = new ChainIterable<>();
|
||||
final String name = function.getName();
|
||||
|
||||
result
|
||||
.addItem(escaper.apply("def "))
|
||||
.addItem(escapedNameMapper.apply(escaper.apply(name)))
|
||||
.addItem(escaper.apply(PyUtil.getReadableRepr(function.getParameterList(), false)));
|
||||
|
||||
if (!PyNames.INIT.equals(name)) {
|
||||
cat.addItem(escaper.apply("\nInferred type: "));
|
||||
describeTypeWithLinks(fun, cat);
|
||||
cat.addItem(BR);
|
||||
result.addItem(escaper.apply("\nInferred type: "));
|
||||
describeTypeWithLinks(context.getType(function), context, function, result);
|
||||
}
|
||||
return cat;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -200,11 +196,6 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i
|
||||
return buildTypeModel(type, context).asString();
|
||||
}
|
||||
|
||||
private static void describeTypeWithLinks(@NotNull PyTypedElement element, @NotNull ChainIterable<String> body) {
|
||||
final TypeEvalContext context = TypeEvalContext.userInitiated(element.getProject(), element.getContainingFile());
|
||||
describeTypeWithLinks(context.getType(element), context, element, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type type which description will be calculated.
|
||||
* Description is the same as {@link PythonDocumentationProvider#getTypeDescription(PyType, TypeEvalContext)} gives but
|
||||
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>def <b>foo</b>()<br>Inferred type: () -> None<br><br>Doc of foo.</code></body></html>
|
||||
<html><body><code>def <b>foo</b>()<br>Inferred type: () -> None<br>Doc of foo.</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>def <b>len</b>(o: Sized)<br>Inferred type: (o: Sized) -> <a href="psi_element://#typename#int">int</a><br><br><br>len(object) -> integer<br><br>Return the number of items of a sequence or collection.<br></code></body></html>
|
||||
<html><body><code>def <b>len</b>(o: Sized)<br>Inferred type: (o: Sized) -> <a href="psi_element://#typename#int">int</a><br><br>len(object) -> integer<br><br>Return the number of items of a sequence or collection.<br></code></body></html>
|
||||
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>def <b>foo</b>()<br>Inferred type: () -> None<br><br>Doc of foo.</code></body></html>
|
||||
<html><body><code>def <b>foo</b>()<br>Inferred type: () -> None<br>Doc of foo.</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code><small>class <a href="psi_element://#class#">Foo</a>(<a href="psi_element://#typename#object">object</a>)</small><br><br>def <b>__init__</b>(self)</code><br><br><i>Documentation is missing.</i> The following is copied from class <code><a href="psi_element://#class#">Foo</a></code>.<br><br><code>Doc of Foo.</code></body></html>
|
||||
<html><body><code><small>class <a href="psi_element://#class#">Foo</a>(<a href="psi_element://#typename#object">object</a>)</small><br><br>def <b>__init__</b>(self)</code><br><br><i>Documentation is missing.</i> The following is copied from class <code><a href="psi_element://#class#">Foo</a></code>.<br><br><code>Doc of Foo.</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code><small>class <a href="psi_element://#class#">Foo</a>(<a href="psi_element://#typename#ClassUndocumentedEmptyConstructor.Moo">Moo</a>)</small><br><br>def <b>__init__</b>(self)</code><br><br><i>Documentation is missing.</i> The following is copied from <code><a href="psi_element://#typename#ClassUndocumentedEmptyConstructor.Moo">Moo</a>.__init__</code>.<br><br><code>Doc of Moo()</code></body></html>
|
||||
<html><body><code><small>class <a href="psi_element://#class#">Foo</a>(<a href="psi_element://#typename#ClassUndocumentedEmptyConstructor.Moo">Moo</a>)</small><br><br>def <b>__init__</b>(self)</code><br><br><i>Documentation is missing.</i> The following is copied from <code><a href="psi_element://#typename#ClassUndocumentedEmptyConstructor.Moo">Moo</a>.__init__</code>.<br><br><code>Doc of Moo()</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>def <b>foo</b>()<br>Inferred type: () -> None<br><br>Doc of foo.</code></body></html>
|
||||
<html><body><code>def <b>foo</b>()<br>Inferred type: () -> None<br>Doc of foo.</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>def <b>foo</b>()<br>Inferred type: () -> None<br><br>Doc of foo.</code></body></html>
|
||||
<html><body><code>def <b>foo</b>()<br>Inferred type: () -> None<br>Doc of foo.</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>def <b>get_tuple</b>()<br>Inferred type: () -> Tuple[<a href="psi_element://#typename#int">int</a>, <a href="psi_element://#typename#int">int</a>, <a href="psi_element://#typename#str">str</a>]<br></code></body></html>
|
||||
<html><body><code>def <b>get_tuple</b>()<br>Inferred type: () -> Tuple[<a href="psi_element://#typename#int">int</a>, <a href="psi_element://#typename#int">int</a>, <a href="psi_element://#typename#str">str</a>]</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>def <b>get_tuple</b>()<br>Inferred type: () -> Tuple[<a href="psi_element://#typename#str">str</a>, ...]<br></code></body></html>
|
||||
<html><body><code>def <b>get_tuple</b>()<br>Inferred type: () -> Tuple[<a href="psi_element://#typename#str">str</a>, ...]</code></body></html>
|
||||
@@ -1,2 +1,2 @@
|
||||
def foo(arg)
|
||||
Inferred type: (arg: Any) -> <a href="psi_element://#typename#int">int</a><br>
|
||||
Inferred type: (arg: Any) -> <a href="psi_element://#typename#int">int</a>
|
||||
@@ -1,3 +1,3 @@
|
||||
@decorator1, @decorator2
|
||||
def foo(param)
|
||||
Inferred type: (param: Any) -> None<br>
|
||||
Inferred type: (param: Any) -> None
|
||||
@@ -1,3 +1,3 @@
|
||||
class A
|
||||
def f(self)
|
||||
Inferred type: (self: <a href="psi_element://#typename#A">A</a>) -> <a href="psi_element://#typename#int">int</a><br>
|
||||
Inferred type: (self: <a href="psi_element://#typename#A">A</a>) -> <a href="psi_element://#typename#int">int</a>
|
||||
@@ -1,3 +1,3 @@
|
||||
@decorator
|
||||
def foo(param)
|
||||
Inferred type: (param: Any) -> None<br>
|
||||
Inferred type: (param: Any) -> None
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>def <b>foo</b>()<br>Inferred type: () -> None<br><br>Doc of foo.<br>It has two lines.</code></body></html>
|
||||
<html><body><code>def <b>foo</b>()<br>Inferred type: () -> None<br>Doc of foo.<br>It has two lines.</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code><small>class <a href="psi_element://#class#">B</a>(<a href="psi_element://#typename#InheritedMethod.A">A</a>)</small><br><br>def <b>foo</b>(self)<br>Inferred type: (self: <a href="psi_element://#typename#B">B</a>) -> None<br></code><br><br><i>Documentation is missing.</i> The following is copied from <code><a href="psi_element://#typename#InheritedMethod.A">A</a>.foo</code>.<br><br><code>Doc from A.foo.</code></body></html>
|
||||
<html><body><code><small>class <a href="psi_element://#class#">B</a>(<a href="psi_element://#typename#InheritedMethod.A">A</a>)</small><br><br>def <b>foo</b>(self)<br>Inferred type: (self: <a href="psi_element://#typename#B">B</a>) -> None</code><br><br><i>Documentation is missing.</i> The following is copied from <code><a href="psi_element://#typename#InheritedMethod.A">A</a>.foo</code>.<br><br><code>Doc from A.foo.</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>@<i>decorator1</i><br>@<i>decorator2</i><br>def <b>foo</b>(param)<br>Inferred type: (param: Any) -> None<br></code></body></html>
|
||||
<html><body><code>@<i>decorator1</i><br>@<i>decorator2</i><br>def <b>foo</b>(param)<br>Inferred type: (param: Any) -> None</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code><small>class <a href="psi_element://#class#">Foo</a></small><br><br>@<i>deco</i><br>def <b>meth</b>(self)<br>Inferred type: (self: <a href="psi_element://#typename#Foo">Foo</a>) -> None<br><br><br>Doc of meth.<br></code></body></html>
|
||||
<html><body><code><small>class <a href="psi_element://#class#">Foo</a></small><br><br>@<i>deco</i><br>def <b>meth</b>(self)<br>Inferred type: (self: <a href="psi_element://#typename#Foo">Foo</a>) -> None<br><br>Doc of meth.<br></code></body></html>
|
||||
@@ -1,4 +1,4 @@
|
||||
def ones(shape, dtype=None, order='C')
|
||||
Inferred type: (shape: Union[<a href="psi_element://#typename#int">int</a>, Iterable[<a href="psi_element://#typename#int">int</a>]], dtype: Optional[<a href="psi_element://#typename#object">object</a>], order: Optional[<a href="psi_element://#typename#str">str</a>]) -> <a href="psi_element://#typename#ndarray">ndarray</a><br>
|
||||
def ones(shape, dtype=None, order='C')
|
||||
Inferred type: (shape: Union[<a href="psi_element://#typename#int">int</a>, Iterable[<a href="psi_element://#typename#int">int</a>]], dtype: Optional[<a href="psi_element://#typename#object">object</a>], order: Optional[<a href="psi_element://#typename#str">str</a>]) -> <a href="psi_element://#typename#ndarray">ndarray</a>
|
||||
**Test docstring**
|
||||
Return a new array of given shape and type, filled with ones.
|
||||
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>@<i>decorator</i><br>def <b>foo</b>(param)<br>Inferred type: (param: Any) -> None<br></code></body></html>
|
||||
<html><body><code>@<i>decorator</i><br>def <b>foo</b>(param)<br>Inferred type: (param: Any) -> None</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>def <b>f</b>(x1: Optional[T], x2: Union[T, Tuple[Any, Any]])<br>Inferred type: (x1: Optional[TypeVar('T', <a href="psi_element://#typename#int">int</a>)], x2: Union[TypeVar('T', <a href="psi_element://#typename#int">int</a>), Tuple[Any, Any]]) -> None<br></code></body></html>
|
||||
<html><body><code>def <b>f</b>(x1: Optional[T], x2: Union[T, Tuple[Any, Any]])<br>Inferred type: (x1: Optional[TypeVar('T', <a href="psi_element://#typename#int">int</a>)], x2: Union[TypeVar('T', <a href="psi_element://#typename#int">int</a>), Tuple[Any, Any]]) -> None</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>def <b>open</b>(encoding: str = None, errors: str = None)<br>Inferred type: (encoding: Optional[<a href="psi_element://#typename#str">str</a>], errors: Optional[<a href="psi_element://#typename#str">str</a>]) -> None<br></code></body></html>
|
||||
<html><body><code>def <b>open</b>(encoding: str = None, errors: str = None)<br>Inferred type: (encoding: Optional[<a href="psi_element://#typename#str">str</a>], errors: Optional[<a href="psi_element://#typename#str">str</a>]) -> None</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><i>Copied from getter:</i><br>Does things to X<code><br><br>@<i>x.deleter</i><br>def <b>x</b>(self, v)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>, v: Any) -> None<br><br>Deletes X</code><small><br><br>Deleter of property</small><br></body></html>
|
||||
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><i>Copied from getter:</i><br>Does things to X<code><br><br>@<i>x.deleter</i><br>def <b>x</b>(self, v)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>, v: Any) -> None<br>Deletes X</code><small><br><br>Deleter of property</small><br></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<code><br><br>@<i>property</i><br>def <b>x</b>(self)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>) -> <a href="psi_element://#typename#int">int</a><br><br>Does things to X</code><small><br><br>Getter of property</small><br></body></html>
|
||||
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<code><br><br>@<i>property</i><br>def <b>x</b>(self)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>) -> <a href="psi_element://#typename#int">int</a><br>Does things to X</code><small><br><br>Getter of property</small><br></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><i>Copied from getter:</i><br>Does things to X<code><br><br>@<i>x.setter</i><br>def <b>x</b>(self, v)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>, v: Any) -> None<br><br>Sets X</code><small><br><br>Setter of property</small><br></body></html>
|
||||
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><i>Copied from getter:</i><br>Does things to X<code><br><br>@<i>x.setter</i><br>def <b>x</b>(self, v)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>, v: Any) -> None<br>Sets X</code><small><br><br>Setter of property</small><br></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<code><br><br>def <b>__getX</b>(self)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>) -> Any<br><br>Doc of getter</code><small><br><br>Deleter of property</small><br></body></html>
|
||||
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<code><br><br>def <b>__getX</b>(self)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>) -> Any<br>Doc of getter</code><small><br><br>Deleter of property</small><br></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<code><br><br>def <b>__getX</b>(self)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>) -> Any<br><br>Doc of getter</code><small><br><br>Getter of property</small><br></body></html>
|
||||
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<code><br><br>def <b>__getX</b>(self)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>) -> Any<br>Doc of getter</code><small><br><br>Getter of property</small><br></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<code><br><br>def <b>__getX</b>(self, x)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>, x: Any) -> None<br><br>Doc of getter</code><small><br><br>Setter of property</small><br></body></html>
|
||||
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<code><br><br>def <b>__getX</b>(self, x)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>, x: Any) -> None<br>Doc of getter</code><small><br><br>Setter of property</small><br></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><small>Assigned to <code>c1</code><br></small><code><small>class <a href="psi_element://#class#">list</a>(<a href="psi_element://#typename#typing.MutableSequence">MutableSequence</a>[_T], Generic[_T])</small><br><br>def <b>count</b>(self, object: _T)<br>Inferred type: (self: <a href="psi_element://#typename#list">list</a>, object: TypeVar('_T')) -> <a href="psi_element://#typename#int">int</a><br><br>L.count(value) -> integer -- return number of occurrences of value </code></body></html>
|
||||
<html><body><small>Assigned to <code>c1</code><br></small><code><small>class <a href="psi_element://#class#">list</a>(<a href="psi_element://#typename#typing.MutableSequence">MutableSequence</a>[_T], Generic[_T])</small><br><br>def <b>count</b>(self, object: _T)<br>Inferred type: (self: <a href="psi_element://#typename#list">list</a>, object: TypeVar('_T')) -> <a href="psi_element://#typename#int">int</a><br>L.count(value) -> integer -- return number of occurrences of value </code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>def <b>f</b>(p1: T1, p2: T2, p3: T3)<br>Inferred type: (p1: TypeVar('T1', <a href="psi_element://#typename#int">int</a>), p2: TypeVar('T2', <a href="psi_element://#typename#int">int</a>, <a href="psi_element://#typename#str">str</a>), p3: TypeVar('T3', <a href="psi_element://#typename#List">List</a>[<a href="psi_element://#typename#bool">bool</a>])) -> None<br></code></body></html>
|
||||
<html><body><code>def <b>f</b>(p1: T1, p2: T2, p3: T3)<br>Inferred type: (p1: TypeVar('T1', <a href="psi_element://#typename#int">int</a>), p2: TypeVar('T2', <a href="psi_element://#typename#int">int</a>, <a href="psi_element://#typename#str">str</a>), p3: TypeVar('T3', <a href="psi_element://#typename#List">List</a>[<a href="psi_element://#typename#bool">bool</a>])) -> None</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>def <b>get_tuple</b>()<br>Inferred type: () -> <a href="psi_element://#typename#tuple">tuple</a><br></code></body></html>
|
||||
<html><body><code>def <b>get_tuple</b>()<br>Inferred type: () -> <a href="psi_element://#typename#tuple">tuple</a></code></body></html>
|
||||
Reference in New Issue
Block a user