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

Update documentation #427

Merged
merged 15 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"pygls.server.debug": false,
// "pygls.server.debugHost": "localhost",
// "pygls.server.debugPort": 5678,
"pygls.server.launchScript": "formatting.py", // This is relative to `pygls.server.cwd`
"pygls.server.launchScript": "code_actions.py", // This is relative to `pygls.server.cwd`
"pygls.server.cwd": "${workspaceFolder}/examples/servers",
"pygls.trace.server": "off",
"pygls.client.documentSelector": [
Expand Down
373 changes: 227 additions & 146 deletions docs/requirements.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.. include:: ../../CHANGELOG.md
:parser: myst_parser.sphinx_
19 changes: 16 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
import importlib.metadata
import os
import pathlib
import re
import sys

from docutils import nodes

sys.path.insert(0, os.path.abspath("./ext"))


# -- Project information -----------------------------------------------------

Expand All @@ -45,15 +48,25 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
# Built-in extensions
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
# 3rd party extensions
"myst_parser",
"sphinx_design",
# Local extensions
"examples",
]

autodoc_member_order = "groupwise"
autodoc_typehints = "description"
autodoc_typehints_description_target = "all"

example_server_dir = (
pathlib.Path(__file__).parent.parent.parent / "examples" / "servers"
)

intersphinx_mapping = {
"python": ("https://docs.python.org/3/", None),
}
Expand Down
6 changes: 6 additions & 0 deletions docs/source/examples/code-actions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Code Actions
============

.. example-server:: code_actions.py
:start-at: import re

7 changes: 7 additions & 0 deletions docs/source/examples/code-lens.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Code Lens
=========

.. example-server:: code_lens.py
:start-at: import logging


9 changes: 9 additions & 0 deletions docs/source/examples/colors.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Document Color
==============

.. example-server:: colors.py
:start-at: import logging




10 changes: 10 additions & 0 deletions docs/source/examples/formatting.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Document Formatting
===================

.. example-server:: formatting.py
:start-at: import logging





12 changes: 12 additions & 0 deletions docs/source/examples/goto.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Goto "X"
========

.. example-server:: goto.py
:start-at: import logging







12 changes: 12 additions & 0 deletions docs/source/examples/hover.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Hover
=====

.. example-server:: hover.py
:start-at: import logging







13 changes: 13 additions & 0 deletions docs/source/examples/inlay-hints.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Inlay Hints
===========

.. example-server:: inlay_hints.py
:start-at: import re








13 changes: 13 additions & 0 deletions docs/source/examples/json-server.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
JSON Server
===========

.. example-server:: json_server.py
:start-at: import argparse








13 changes: 13 additions & 0 deletions docs/source/examples/publish-diagnostics.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Publish Diagnostics
===================

.. example-server:: publish_diagnostics.py
:start-at: import logging








13 changes: 13 additions & 0 deletions docs/source/examples/pull-diagnostics.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Pull Diagnostics
================

.. example-server:: pull_diagnostics.py
:start-at: import logging








13 changes: 13 additions & 0 deletions docs/source/examples/rename.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Rename
======

.. example-server:: rename.py
:start-at: import logging








85 changes: 85 additions & 0 deletions docs/source/ext/examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""Documentation for the example servers"""

from __future__ import annotations

import importlib.util as imutil
import os
import pathlib
import typing

from docutils.parsers.rst import directives
from sphinx.util.docutils import SphinxDirective
from sphinx.util.logging import getLogger

if typing.TYPE_CHECKING:
from sphinx.application import Sphinx

logger = getLogger(__name__)


class ExampleServerDirective(SphinxDirective):
"""Automate the process of documenting example servers.

Currently, this doesn't do *that* much, it

- Inserts the code using a ``.. literalinclude::`` directive.
- Extracts the server module's docstring and inserts it into the page as nicely
rendered text.

But perhaps we can do something more interesting in the future!
"""

required_arguments = 1
option_spec = {
"start-at": directives.unchanged,
}

def get_docstring(self, filename: pathlib.Path):
"""Given the filepath to a module, return its docstring."""

base = filename.stem
spec = imutil.spec_from_file_location(f"examples.{base}", filename)

try:
module = imutil.module_from_spec(spec)
spec.loader.exec_module(module)
except Exception:
logger.exception("Unable to import example server")
return []

if (docstring := module.__doc__) is not None:
return docstring.splitlines()

return []

def run(self):
server_dir = self.config.example_server_dir
name = self.arguments[0]

if not (filename := pathlib.Path(server_dir, name)).exists():
raise RuntimeError(f"Unable to find example server: {filename}")

# Tell Sphinx to rebuild a document if this file changes
self.env.note_dependency(str(filename))

# An "absolute" path given to `literalinclude` is actually relative to the
# projects srcdir
relpath = os.path.relpath(str(filename), start=str(self.env.app.srcdir))
content = [
f".. literalinclude:: /{relpath}",
" :language: python",
]

if (start_at := self.options.get("start-at")) is not None:
content.append(f" :start-at: {start_at}")

# Confusingly, these are processed in reverse order...
self.state_machine.insert_input(content, "<examples>")
self.state_machine.insert_input(self.get_docstring(filename), str(filename))

return []


def setup(app: Sphinx):
app.add_config_value("example_server_dir", "", rebuild="env")
app.add_directive("example-server", ExampleServerDirective)
113 changes: 113 additions & 0 deletions docs/source/getting-started.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
Getting Started
===============

.. _example-servers:

Example Servers
---------------

.. toctree::
:hidden:
:glob:

examples/*

.. tip::

If you use VSCode, we recommend you try these servers out in the :ref:`pygls-playground <howto-use-pygls-playground>` extension

Each of the following example servers are focused on implementing a particular subset of the Language Server Protocol.

.. grid:: 1 2 2 4
:gutter: 2

.. grid-item-card:: Code Actions
:link: /examples/code-actions
:link-type: doc
:text-align: center

:octicon:`light-bulb`

.. grid-item-card:: Code Lens
:link: /examples/code-lens
:link-type: doc
:text-align: center

:octicon:`eye`

.. grid-item-card:: Colors
:link: /examples/colors
:link-type: doc
:text-align: center

:octicon:`paintbrush`

.. grid-item-card:: Formatting
:link: /examples/formatting
:link-type: doc
:text-align: center

:octicon:`typography`

.. grid-item-card:: Goto "X"
:link: /examples/goto
:link-type: doc
:text-align: center

:octicon:`search`

.. grid-item-card:: Hover
:link: /examples/hover
:link-type: doc
:text-align: center

:octicon:`book`

.. grid-item-card:: Inlay Hints
:link: /examples/inlay-hints
:link-type: doc
:text-align: center

:octicon:`info`

.. grid-item-card:: Publish Diagnostics
:link: /examples/publish-diagnostics
:link-type: doc
:text-align: center

:octicon:`alert`

.. grid-item-card:: Pull Diagnostics
:link: /examples/pull-diagnostics
:link-type: doc
:text-align: center

:octicon:`alert`

.. grid-item-card:: Rename
:link: /examples/rename
:link-type: doc
:text-align: center

:octicon:`pencil`

These servers are dedicated to demonstrating features of *pygls* itself

.. grid:: 1 2 2 4
:gutter: 2

.. grid-item-card:: JSON Server
:link: /examples/json-server
:link-type: doc
:text-align: center

:octicon:`code`


Tutorial
--------

.. note::

Coming soon\ :sup:`TM`

2 changes: 2 additions & 0 deletions docs/source/history.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.. include:: ../../HISTORY.md
:parser: myst_parser.sphinx_
Loading
Loading