Skip to content

Commit

Permalink
chore: align to new server implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Aug 18, 2024
1 parent 2413bd5 commit fd38dd1
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 206 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _pygls_ (pronounced like "pie glass") is a pythonic generic implementation of th

## Quickstart
```python
from pygls.server import LanguageServer
from pygls.lsp.server import LanguageServer
from lsprotocol.types import (
TEXT_DOCUMENT_COMPLETION,
CompletionItem,
Expand Down
8 changes: 4 additions & 4 deletions docs/source/user-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The code snippet below shows how to start the server in *TCP* mode.

.. code:: python
from pygls.server import LanguageServer
from pygls.lsp.server import LanguageServer
server = LanguageServer('example-server', 'v0.1')
Expand All @@ -48,7 +48,7 @@ The code snippet below shows how to start the server in *STDIO* mode.

.. code:: python
from pygls.server import LanguageServer
from pygls.lsp.server import LanguageServer
server = LanguageServer('example-server', 'v0.1')
Expand All @@ -66,7 +66,7 @@ The code snippet below shows how to start the server in *WEBSOCKET* mode.

.. code:: python
from pygls.server import LanguageServer
from pygls.lsp.server import LanguageServer
server = LanguageServer('example-server', 'v0.1')
Expand All @@ -89,7 +89,7 @@ is the minimal setup to setup logging in *pygls*:
import logging
from pygls.server import LanguageServer
from pygls.lsp.server import LanguageServer
logging.basicConfig(filename='pygls.log', filemode='w', level=logging.DEBUG)
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-world/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pygls.server import LanguageServer
from pygls.lsp.server import LanguageServer
from lsprotocol import types

server = LanguageServer("example-server", "v0.1")
Expand Down
3 changes: 2 additions & 1 deletion examples/servers/code_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
This server scans the document for incomplete sums e.g. ``1 + 1 =`` and returns a code
action which, when invoked will fill in the answer.
"""

import re
from pygls.server import LanguageServer
from pygls.lsp.server import LanguageServer
from lsprotocol.types import (
TEXT_DOCUMENT_CODE_ACTION,
CodeAction,
Expand Down
12 changes: 9 additions & 3 deletions examples/servers/code_lens.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
front, this example demonstrates how the ``codeLens/resolve`` can be used to defer this
computation until it is actually necessary.
"""

import logging
import re

from lsprotocol import types

from pygls.server import LanguageServer
from pygls.lsp.server import LanguageServer

ADDITION = re.compile(r"^\s*(\d+)\s*\+\s*(\d+)\s*=(?=\s*$)")
server = LanguageServer("code-lens-server", "v1")
Expand Down Expand Up @@ -115,7 +116,8 @@ def evaluate_sum(ls: LanguageServer, args):
answer = arguments["left"] + arguments["right"]
edit = types.TextDocumentEdit(
text_document=types.OptionalVersionedTextDocumentIdentifier(
uri=arguments["uri"], version=document.version
uri=arguments["uri"],
version=document.version,
),
edits=[
types.TextEdit(
Expand All @@ -129,7 +131,11 @@ def evaluate_sum(ls: LanguageServer, args):
)

# Apply the edit.
ls.apply_edit(types.WorkspaceEdit(document_changes=[edit]))
ls.workspace_apply_edit(
types.ApplyWorkspaceEditParams(
edit=types.WorkspaceEdit(document_changes=[edit]),
),
)


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion examples/servers/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@
This server implements the requests defined above for CSS's hex color code syntax
(``#000`` and ``#000000``).
"""

import logging
import re

from lsprotocol import types

from pygls.server import LanguageServer
from pygls.lsp.server import LanguageServer

COLOR = re.compile(r"""\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})(?!\w)""")
server = LanguageServer("color-server", "v1")
Expand Down
3 changes: 2 additions & 1 deletion examples/servers/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
expect (fixes welcome!), but it should be enough to demonstrate the expected interaction
between client and server.
"""

import logging
from typing import Dict
from typing import List
Expand All @@ -41,7 +42,7 @@
import attrs
from lsprotocol import types

from pygls.server import LanguageServer
from pygls.lsp.server import LanguageServer
from pygls.workspace import TextDocument


Expand Down
3 changes: 2 additions & 1 deletion examples/servers/goto.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@
This means the choices of what the example server below will return results for are
completely arbitrary.
"""

import logging
import re

from lsprotocol import types

from pygls.server import LanguageServer
from pygls.lsp.server import LanguageServer
from pygls.workspace import TextDocument

ARGUMENT = re.compile(r"(?P<name>\w+): (?P<type>\w+)")
Expand Down
3 changes: 2 additions & 1 deletion examples/servers/hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
displaying a table how the selected date would be formatted in each of the supported
formats.
"""

import logging
from datetime import datetime

from lsprotocol import types

from pygls.server import LanguageServer
from pygls.lsp.server import LanguageServer

DATE_FORMATS = [
"%H:%M:%S",
Expand Down
3 changes: 2 additions & 1 deletion examples/servers/inlay_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
uses the ``inlayHint/resolve`` to demonstrate how you can defer expensive computations
to when they are required.
"""

import re
from typing import Optional

from lsprotocol import types
from pygls.server import LanguageServer
from pygls.lsp.server import LanguageServer

NUMBER = re.compile(r"\d+")
server = LanguageServer("inlay-hint-server", "v1")
Expand Down
Loading

0 comments on commit fd38dd1

Please sign in to comment.