Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Hover Doc String Formatting Lacks Linebreaks #42

Closed
maegul opened this issue Dec 11, 2020 · 19 comments
Closed

On Hover Doc String Formatting Lacks Linebreaks #42

maegul opened this issue Dec 11, 2020 · 19 comments
Labels
upstream Upstream issue

Comments

@maegul
Copy link

maegul commented Dec 11, 2020

Not sure if this is a pyright or lsp issue (I'm new to this ecosystem).

Line breaks between parameters are not being printed in the hover over signature and docstring.

See screenshot below:

image

Line breaks between parameters are not printed. Compare with the ipython output:

image

@jfcherng
Copy link
Collaborator

jfcherng commented Dec 11, 2020

I think that's because we render it in Markdown format. However, a single \n is treated like a whitespace while \n\n is rederered as a new line.

    def get_sheet_index(self, sheet: "Sheet") -> Tuple[int, int]:
        """
        Returns the group, and index within the group of the `sheet`
        Returns (-1, -1) if not found
        """
        ...

image

{
    "range": {"start": {"character": 8, "line": 676}, "end": {"character": 23, "line": 676}},
    "contents": {
        "value": "```python\n(method) get_sheet_index: (self: Window, sheet: Sheet) -> Tuple[int, int]\n```\nReturns the group, and index within the group of the `sheet`\nReturns (-1, -1) if not found",
        "kind": "markdown",
    },
}

Wondering could we intercept messages in LSP-* before it gets rendered with mdpopup lib... I, privately, actually would like to change the output format of signature help for better syntax highlighting for it.

But even if we can intercept the message here, replacing all \n with \n\n sounds like an improper way to fix it.

@rwols
Copy link
Member

rwols commented Dec 12, 2020

The pyright language server tells LSP that the content is markdown, so LSP renders it as markdown.

The fact that the content is not actually markdown, but numpy-flavored restructured text, is really a problem of pyright.

@rchl
Copy link
Member

rchl commented Dec 12, 2020

There is another aspect to it - the markdown implementation that is used.

Using github flavored implementation would preserve the single linebreaks too.

@rwols
Copy link
Member

rwols commented Dec 12, 2020

Fair point. I'll link this to facelessuser/sublime-markdown-popups#103 and ping @facelessuser so we have another example where it would be beneficial to switch mdpopups to (GitHub-flavored) commonmark.

But I still think pyright should put in more effort to move from numpy-flavored restructured text-space to commonmark-space. It might accidentally render alright in VSCode, but the spaces are wrong.

For one thing pyright puts in no effort at all to fill in the parameter documentation. This is readily parseable information.

@facelessuser
Copy link

Have you compared the output in commonmark? I'm not sure it would render as expected there either.

@facelessuser
Copy link

That's what I figured. It doesn't look like it's formatted for Markdown at all.

@maegul
Copy link
Author

maegul commented Dec 13, 2020

Sorry for being new to the ecosystem.

But yes, @rwols , from a quick search on the pyright/pylance repos, it does seem to be a problem on that side for which there are a few pre-existing issues, linked below for the curious ...

microsoft/pyright#721
microsfot/pylance-release#41
microsoft/pylance-release#48
microsfot/pylance-release#476

@rwols
Copy link
Member

rwols commented Dec 18, 2020

I'll close this because we're doing everything correctly here. pyright should have a transformation from whatever its documentation space is to markdown space. I understand that is not trivial because there are many different documentation-styles in Python, but that is a problem of pyright.

@rwols rwols closed this as completed Dec 18, 2020
@maegul
Copy link
Author

maegul commented Feb 8, 2021

Seems that pyright might have fixed this on their end now (See microsoft/pyright#1449)?

I noticed a change in the docstring formatting in sublime lsp-pyright after the latest pyright version was pulled into lsp-pyright (today or yesterday?). But it still isn't right ... line breaks are not respected.

Not sure if everything is fixed on the pyright side ... but a quick comparison with pylance on VSCode shows that line breaks are rendered there now with nice docstring pop ups. Don't know how much of this is pylance or pyright though.

@rchl
Copy link
Member

rchl commented Feb 8, 2021

Example response (identical in both ST and VSCode) where the line breaks are formatted correctly in VSCode but not in ST:

{
  "contents": {
    "kind": "markdown",
    "value": "```python\n(function) open: (url: Text, new: int = ..., autoraise: bool = ...) -> bool\n```\nDisplay url using the default browser.\n\nIf possible, open url in a location determined by new.\n- 0: the same browser window (the default).\n- 1: a new browser window.\n- 2: a new browser page (\"tab\").\nIf possible, autoraise raises the window (the default) or not."
  },
  "range": {
    "end": {
      "character": 23,
      "line": 56
    },
    "start": {
      "character": 19,
      "line": 56
    }
  }
}

I believe it's again about differences with the markdown parser used.

ST:

Screenshot 2021-02-08 at 11 27 07

VSCode:

Screenshot 2021-02-08 at 11 28 18

@rwols
Copy link
Member

rwols commented Feb 8, 2021

Yes, python-markdown wants two newlines before starting an unordered list. In the sample payload, only one newline is used before starting an unordered list. So we're back at facelessuser/sublime-markdown-popups#103.

@rchl
Copy link
Member

rchl commented Feb 8, 2021

Also, I'm not sure if that issue is exactly what @maegul seen.

@maegul
Copy link
Author

maegul commented Feb 8, 2021

Also, I'm not sure if that issue is exactly what @maegul seen.

Not exactly but it seems to be the same issue.
I'm talking about numpy style docstrings (where the main issue is line breaks between individual parameters).

VS Code:

image

ST:

image

@rchl
Copy link
Member

rchl commented Feb 8, 2021

So it's still pretty much the same as in the initial comment then.

@rwols
Copy link
Member

rwols commented Feb 8, 2021

Not really, initially it was just restructured text, but now it's commonmark.

@maegul
Copy link
Author

maegul commented Feb 8, 2021

So it's still pretty much the same as in the initial comment then.

Regarding line breaks ... yes

There is a slight difference in the output though ... indentation white space is preserved now but wasn't before (which is what prompted me to check for updates in pyright). Don't know why though 🤷 (I'm not on top of the code base here ... just a nagging user 😏 )

@rwols
Copy link
Member

rwols commented Feb 23, 2021

sublimelsp/LSP@111fac6 should be an improvement :)

@maegul
Copy link
Author

maegul commented Mar 4, 2021

Nice! Makes a world of difference!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream Upstream issue
Projects
None yet
Development

No branches or pull requests

5 participants