Skip to content

Commit e38ce33

Browse files
committed
Add --version CLI argument and return version in InitializeResult
1 parent 34be02a commit e38ce33

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pylsp/__main__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from .python_lsp import (PythonLSPServer, start_io_lang_server,
1616
start_tcp_lang_server)
17+
from ._version import __version__
1718

1819
LOG_FORMAT = "%(asctime)s {0} - %(levelname)s - %(name)s - %(message)s".format(
1920
time.localtime().tm_zone)
@@ -57,13 +58,21 @@ def add_arguments(parser):
5758
help="Increase verbosity of log output, overrides log config file"
5859
)
5960

61+
parser.add_argument(
62+
'-V', '--version', action='store_true',
63+
help="Print version and exit"
64+
)
6065

6166
def main():
6267
parser = argparse.ArgumentParser()
6368
add_arguments(parser)
6469
args = parser.parse_args()
6570
_configure_logger(args.verbose, args.log_config, args.log_file)
6671

72+
if args.version:
73+
print('pylsp v{}'.format(__version__))
74+
return
75+
6776
if args.tcp:
6877
start_tcp_lang_server(args.host, args.port, args.check_parent_process,
6978
PythonLSPServer)

pylsp/python_lsp.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from . import lsp, _utils, uris
1515
from .config import config
1616
from .workspace import Workspace
17+
from ._version import __version__
1718

1819
log = logging.getLogger(__name__)
1920

@@ -225,7 +226,13 @@ def watch_parent_process(pid):
225226
self.watching_thread.daemon = True
226227
self.watching_thread.start()
227228
# Get our capabilities
228-
return {'capabilities': self.capabilities()}
229+
return {
230+
'capabilities': self.capabilities(),
231+
'serverInfo': {
232+
'name': 'pylsp',
233+
'version': __version__,
234+
},
235+
}
229236

230237
def m_initialized(self, **_kwargs):
231238
self._hook('pylsp_initialized')

0 commit comments

Comments
 (0)