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

Handling reStructuredText in docstrings? #760

Open
thomasjm opened this issue Mar 13, 2020 · 3 comments
Open

Handling reStructuredText in docstrings? #760

thomasjm opened this issue Mar 13, 2020 · 3 comments

Comments

@thomasjm
Copy link

Some Python docstrings use reStructuredText, one notable example being pandas. Here's an example from that link:

def add(num1, num2):
  """
  Add up two integer numbers.
  
  This function simply wraps the `+` operator, and does not
  do anything interesting, except for illustrating what is
  the docstring of a very simple function.
  
  Parameters
  ----------
  num1 : int
      First number to add
  num2 : int
      Second number to add
  
  Returns
  -------
  int
      The sum of `num1` and `num2`
  
  See Also
  --------
  subtract : Subtract one integer from another
  
  Examples
  --------
  >>> add(2, 2)
  4
  >>> add(25, 0)
  25
  >>> add(10, -10)
  0
  """
  return num1 + num2

I noticed that python-language-server feeds these docstrings back directly to the client without any transformation into Markdown, so they don't always render well when you do things like hovers. For example, the code block sections beginning with >>> don't look good. This is actually the cause of issue #291 .

The Microsoft language server has special parsing code in it to handle this; see https://github.com/microsoft/python-language-server/blob/master/src/LanguageServer/Impl/Documentation/DocstringConverter.cs.

Is there some way to address this within this language server? Thanks!

@goanpeca
Copy link
Contributor

So, we should probably convert from rst to markdown for known libraries?

microsoft/language-server-protocol#791

Using pandoc or something similar https://gist.github.com/zaiste/77a946bbba73f5c4d33f3106a494e6cd ?

Thoughts @ccordoba12 @andfoy ?

@andfoy
Copy link
Contributor

andfoy commented Mar 13, 2020

So, we should probably convert from rst to markdown for known libraries?

This is is the only alternative available, as LSP maintainers denied an RST proposal sent last year: microsoft/language-server-protocol#781

@thomasjm
Copy link
Author

FWIW, pandoc is a huge and also GPL-ed dependency.

I suspect something homemade like Microsoft did is the cleanest way to do it.

Or maybe an existing Python library like https://github.com/sixty-north/rst_to_md ?

FYI CommonMark is the best Markdown spec out there: https://commonmark.org

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

No branches or pull requests

3 participants