From 5414063d5a4ee3f937d4599112538764dc7d1543 Mon Sep 17 00:00:00 2001 From: Nicholas Gates Date: Fri, 15 Feb 2019 13:17:51 +0000 Subject: [PATCH] Support yaml config file --- pyls/__main__.py | 9 +++++++++ pyls/python_ls.py | 4 +++- setup.py | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pyls/__main__.py b/pyls/__main__.py index 59abf9fb..94051466 100644 --- a/pyls/__main__.py +++ b/pyls/__main__.py @@ -4,6 +4,7 @@ import logging import logging.config import sys +import yaml from .python_ls import start_io_lang_server, start_tcp_lang_server, PythonLanguageServer LOG_FORMAT = "%(asctime)s UTC - %(levelname)s - %(name)s - %(message)s" @@ -30,6 +31,10 @@ def add_arguments(parser): "and auto shut down language server process when parent process is not alive." "Note that this may not work on a Windows machine." ) + parser.add_argument( + '-c', '--conf', + help='Pass a YAML file containing PYLS settings' + ) log_group = parser.add_mutually_exclusive_group() log_group.add_argument( @@ -54,6 +59,10 @@ def main(): args = parser.parse_args() _configure_logger(args.verbose, args.log_config, args.log_file) + if args.conf: + with open(args.conf, 'r') as f: + PythonLanguageServer.INITIAL_CONFIG = yaml.load(f) + if args.tcp: start_tcp_lang_server(args.host, args.port, PythonLanguageServer) else: diff --git a/pyls/python_ls.py b/pyls/python_ls.py index c85fe9eb..ad3b43df 100644 --- a/pyls/python_ls.py +++ b/pyls/python_ls.py @@ -65,9 +65,10 @@ class PythonLanguageServer(MethodDispatcher): """ Implementation of the Microsoft VSCode Language Server Protocol https://github.com/Microsoft/language-server-protocol/blob/master/versions/protocol-1-x.md """ - # pylint: disable=too-many-public-methods,redefined-builtin + INITIAL_CONFIG = {} + def __init__(self, rx, tx, check_parent_process=False): self.workspace = None self.config = None @@ -154,6 +155,7 @@ def m_initialize(self, processId=None, rootUri=None, rootPath=None, initializati self.workspace = Workspace(rootUri, self._endpoint) self.config = config.Config(rootUri, initializationOptions or {}, processId) + self.config.update(PythonLanguageServer.INITIAL_CONFIG) self._dispatchers = self._hook('pyls_dispatchers') self._hook('pyls_initialize') diff --git a/setup.py b/setup.py index 441ded14..68a0ea35 100755 --- a/setup.py +++ b/setup.py @@ -37,7 +37,8 @@ 'futures; python_version<"3.2"', 'jedi>=0.13.2', 'python-jsonrpc-server>=0.1.0', - 'pluggy' + 'pluggy', + 'pyyaml' ], # List additional groups of dependencies here (e.g. development