pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

markdown rendering issues

Open jdtsmith opened this issue 3 years ago • 11 comments

Describe the bug

The auto-markdown conversion for signatureHelp and hover is useful, but appears to have some issues. For example, consider the numpy function np.unique. This is the Parameters block from its docstring:

    Parameters
    ----------
    ar : array_like
        Input array. Unless `axis` is specified, this will be flattened if it
        is not already 1-D.
    return_index : bool, optional
        If True, also return the indices of `ar` (along the specified axis,
        if provided, or in the flattened array) that result in the unique array.
    return_inverse : bool, optional
        If True, also return the indices of the unique array (for the specified
        axis, if provided) that can be used to reconstruct `ar`.
    return_counts : bool, optional
        If True, also return the number of times each unique item appears
        in `ar`.

        .. versionadded:: 1.9.0

    axis : int or None, optional
        The axis to operate on. If None, `ar` will be flattened. If an integer,
        the subarrays indexed by the given axis will be flattened and treated
        as the elements of a 1-D array with the dimension of the given axis,
        see the notes for more details.  Object arrays or structured arrays
        that contain objects are not supported if the `axis` kwarg is used. The
        default is None.

        .. versionadded:: 1.13.0

And here is how pyright renders it into markdown:

Parameters

ar : array\_like\     Input array. Unless axis is specified, this will be flattened if it is not already 1-D.\ return\_index : bool, optional\     If True, also return the indices of ar (along the specified axis, if provided, or in the flattened array) that result in the unique array.\ return\_inverse : bool, optional\     If True, also return the indices of the unique array (for the specified axis, if provided) that can be used to reconstruct ar.\ return\_counts : bool, optional\     If True, also return the number of times each unique item appears in ar.

axis : int or None, optional\     The axis to operate on. If None, ar will be flattened. If an integer, the subarrays indexed by the given axis will be flattened and treated as the elements of a 1-D array with the dimension of the given axis, see the notes for more details. Object arrays or structured arrays that contain objects are not supported if the axis kwarg is used. The default is None.


The main issues are (sometimes, but not always) doubling or tripling backslashes (e.g. \\\n), and losing the reverse indentation layout which delineates individual parameters. The ..versionadded info is also stripped.

jdtsmith avatar Jan 09 '22 00:01 jdtsmith

This isn't a core type checking issue, so I'm going to transfer it to the pylance repo.

erictraut avatar Jan 09 '22 01:01 erictraut

this is what i am seeing

image

I don't see any issue on doc string rendering.

please re-open the issue with more specifics if you think we need to improve doc string rendering.

heejaechang avatar Apr 22 '22 01:04 heejaechang

actually, I think you are talking about line wrapping. just make tooltip window larger if you don't want to see line wrapping.

heejaechang avatar Apr 22 '22 01:04 heejaechang

I re-opened the issue and set it as enhancement. we probably want to improve line wrapping.

heejaechang avatar Apr 22 '22 01:04 heejaechang

Thanks for your thoughts on this. The issue is with parsing the doc info in another tool (Emacs). While it may be rendered well enough in some tools, the markdown has errors, as you can see above by Github's rendering of the exact content delivered by pyright. Here's how it renders for me:

image

It would be great if pyright could stick to simple markdown, renderable anywhere. Even GitHub has trouble rendering the markdown pyright generates (see example above). Is there perhaps a plaintext option which returns the docs without processing?

jdtsmith avatar Apr 22 '22 11:04 jdtsmith

@jdtsmith not all markdown renderer supports all different variations of markdowns. our markdown targets one that vscode LSP client uses. it looks like the markdown renderer you used are not supporting some of markdown vscode renderer supports. (we also have bugs the other way that says vscode LSP markdown renderer not supporting one that other renderers support such as LaTex markdown)

we will take a look but we will probably still target best experience over vscode's markdown renderer.

heejaechang avatar Apr 25 '22 18:04 heejaechang

look into replacing \ with <br> https://www.markdownguide.org/basic-syntax/#line-break-best-practices

bschnurr avatar Apr 25 '22 18:04 bschnurr

@bschnurr it looks like &nbsp; is shown as it is according to the image @jdtsmith shared. so, I am not sure the markdown renderer @jdtsmith is using even supports HTML tags. it might be better to use the "two spaces - trailing whitespace" trick the doc is mentioning?

heejaechang avatar Apr 25 '22 18:04 heejaechang

but the renderer user uses doesn't even support char escaping we put for _. (https://www.markdownguide.org/basic-syntax/#characters-you-can-escape)

so, it might be better to just ask users to use better markdown renderer.

by the way, if you don't want markdown, the LSP client you use such as Emac, you can ask the LSP client to request plaintext rather than markdown for tooltips, then we will return plain text as it is written in python source file without any conversion to markdown.

heejaechang avatar Apr 25 '22 18:04 heejaechang

Plain text sounds workable. What is the config setting enabling that? Thanks.

jdtsmith avatar Apr 25 '22 19:04 jdtsmith

@jdtsmith its up to client (Emacs), they need to request plain text hover, not markdown hover.

heejaechang avatar Jun 10 '22 09:06 heejaechang

Not sure there is work to do here? What would the enhancement be?

rchiodo avatar Oct 14 '22 23:10 rchiodo

Unless the markdown can be simplified so as not to include special HTML entities but only pure markdown, I think just reverting to plain text is the right solution. I've put in a request (no traction yet).

Just came across this particularly bad example today (from python's re module):

image

I'll close this as the client's problem.

jdtsmith avatar Oct 15 '22 00:10 jdtsmith