Skip to content

Hugly MarkupContent formatting #606

Open
@rcasta74

Description

@rcasta74

Here a comparison between pyright and pylsp using coc.nvim plugin:

  1. pyright
[Trace - 3:54:33 PM] Received response 'textDocument/hover - (11)' in 4ms.
Result: {
    "contents": {
        "kind": "markdown",
        "value": "```python\n(function) def load(\n    fp: SupportsRead[str | bytes],\n    *,\n    cls: type[JSONDecoder] | None = None,\n    object_hook: ((dict[Any, Any]) -> Any) | None = None,\n    parse_float: ((str) -> Any) | None = None,\n    parse_int: ((str) -> Any) | None = None,\n    parse_constant: ((str) -> Any) | None = None,\n    object_pairs_hook: ((list[tuple[Any, Any]]) -> Any) | None = None,\n    **kwds: Any\n) -> Any\n```\n---\nDeserialize `fp` (a `.read()`-supporting file-like object containing\na JSON document) to a Python object.\n\n`object_hook` is an optional function that will be called with the\nresult of any object literal decode (a `dict`). The return value of\n`object_hook` will be used instead of the `dict`. This feature\ncan be used to implement custom decoders (e.g. JSON-RPC class hinting).\n\n`object_pairs_hook` is an optional function that will be called with the\nresult of any object literal decoded with an ordered list of pairs.  The\nreturn value of `object_pairs_hook` will be used instead of the `dict`.\nThis feature can be used to implement custom decoders.  If `object_hook`\nis also defined, the `object_pairs_hook` takes priority.\n\nTo use a custom `JSONDecoder` subclass, specify it with the `cls`\nkwarg; otherwise `JSONDecoder` is used."
    },

2024-12-07_16-54

  1. pylsp
[Trace - 3:54:33 PM] Received response 'textDocument/hover - (10)' in 6ms.
Result: {
    "contents": {
        "kind": "markdown",
        "value": "```python\nload(fp: SupportsRead[Union[str, bytes]], *, cls: Optional[Type[JSONDecoder]]=..., object_hook: Optional[Callable[[Dict[Any, Any]], Any]]=..., parse_float: Optional[Callable[[str], Any]]=..., parse_int: Optional[Callable[[str], Any]]=..., parse_constant: Optional[Callable[[str], Any]]=..., object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]]=..., **kwds: Any) -> Any\n```\n\n\nDeserialize ``fp`` (a ``.read()``-supporting file-like object containing\na JSON document) to a Python object.\n\n``object\\_hook`` is an optional function that will be called with the\nresult of any object literal decode (a ``dict``). The return value of\n``object\\_hook`` will be used instead of the ``dict``. This feature\ncan be used to implement custom decoders (e.g. JSON-RPC class hinting).\n\n``object\\_pairs\\_hook`` is an optional function that will be called with the\nresult of any object literal decoded with an ordered list of pairs.  The\nreturn value of ``object\\_pairs\\_hook`` will be used instead of the ``dict``.\nThis feature can be used to implement custom decoders.  If ``object\\_hook``\nis also defined, the ``object\\_pairs\\_hook`` takes priority.\n\nTo use a custom ``JSONDecoder`` subclass, specify it with the ``cls``\nkwarg; otherwise ``JSONDecoder`` is used."
    }

2024-12-07_14-52

So with pylsp

  • code block is formatted as one-line
  • code spans contain backslash escapes that are treated literally as per GitHub Flavored Markdown Spec (they are not present if plaintext format is requested)

Could this be improved?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions