1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
Getting Started
===============
This document explains how to install *pygls* and get started writing language
servers that are based on it.
.. note::
Before going any further, if you are not familiar with *language servers*
and *Language Server Protocol*, we recommend reading following articles:
- `Language Server Protocol Overview <https://microsoft.github.io/language-server-protocol/overview>`_
- `Language Server Protocol Specification <https://microsoft.github.io/language-server-protocol/specification>`_
- `Language Server Protocol SDKs <https://microsoft.github.io/language-server-protocol/implementors/sdks/>`_
Installation
------------
To get the latest release from *PyPI*, simply run:
.. code:: console
pip install pygls
Alternatively, *pygls* source code can be downloaded from our `GitHub`_ page and installed with following command:
.. code:: console
pip install git+https://github.com/openlawlibrary/pygls
Quick Start
-----------
Spin the Server Up
~~~~~~~~~~~~~~~~~~
*pygls* is a language server that can be started without writing any additional
code:
.. code:: python
from pygls.server import LanguageServer
server = LanguageServer('example-server', 'v0.1')
server.start_tcp('127.0.0.1', 8080)
After running the code above, server will start listening for incoming
``Json RPC`` requests on ``http://127.0.0.1:8080``.
Register Features and Commands
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*pygls* comes with an API for registering additional features like
``code completion``, ``find all references``, ``go to definition``, etc.
.. code:: python
@server.feature(TEXT_DOCUMENT_COMPLETION, CompletionOptions(trigger_characters=[',']))
def completions(params: CompletionParams):
"""Returns completion items."""
return CompletionList(
is_incomplete=False,
items=[
CompletionItem(label='Item1'),
CompletionItem(label='Item2'),
CompletionItem(label='Item3'),
]
)
… as well as custom commands:
.. code:: python
@server.command('myVerySpecialCommandName')
def cmd_return_hello_world(ls, *args):
return 'Hello World!'
See the :mod:`lsprotocol.types` module for the complete and canonical list of available features.
Tutorial
--------
We recommend completing the :ref:`tutorial <tutorial>`, especially if you
haven't worked with language servers before.
User Guide
----------
To reveal the full potential of *pygls* (``thread management``, ``coroutines``,
``multi-root workspace``, ``TCP/STDIO communication``, etc.) keep reading.
.. _GitHub: https://github.com/openlawlibrary/pygls
|