Skip to content

Commit

Permalink
Load plugins via setuptools (#117)
Browse files Browse the repository at this point in the history
* load plugins via setuptools

* Fix syntax

* Revert vscode changes

* Fix

* Fix linting
  • Loading branch information
gatesn authored Sep 3, 2017
1 parent 81f639c commit 04e0261
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
2 changes: 2 additions & 0 deletions pyls/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def __init__(self, root_uri, init_opts):
self._pm.enable_tracing()
self._pm.add_hookspecs(hookspecs)
self._pm.load_setuptools_entrypoints(PYLS)
for name, plugin in self._pm.list_name_plugin():
log.info("Loaded pyls plugin %s from %s", name, plugin)

@property
def plugin_manager(self):
Expand Down
11 changes: 0 additions & 11 deletions pyls/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
# Copyright 2017 Palantir Technologies, Inc.
from . import (
completion, definition, format,
hover, pyflakes_lint, pycodestyle_lint,
references, signature, symbols
)


CORE_PLUGINS = [
completion, definition, format, hover, pyflakes_lint, pycodestyle_lint,
references, signature, symbols
]
25 changes: 9 additions & 16 deletions pyls/python_ls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2017 Palantir Technologies, Inc.
import logging
from . import config, lsp, plugins, _utils
from . import config, lsp, _utils
from .language_server import LanguageServer
from .workspace import Workspace

Expand All @@ -11,12 +11,18 @@

class PythonLanguageServer(LanguageServer):

_hooks = None
workspace = None
config = None

@property
def _hooks(self):
return self.config.plugin_manager.hook

def _hook(self, hook, doc_uri=None, **kwargs):
doc = self.workspace.get_document(doc_uri) if doc_uri else None
return hook(config=self.config, workspace=self.workspace, document=doc, **kwargs)

def capabilities(self):
# TODO: support incremental sync instead of full
return {
'codeActionProvider': True,
'codeLensProvider': {
Expand Down Expand Up @@ -44,21 +50,8 @@ def capabilities(self):
def initialize(self, root_uri, init_opts, _process_id):
self.workspace = Workspace(root_uri, lang_server=self)
self.config = config.Config(root_uri, init_opts)

# Register the base set of plugins
# TODO(gatesn): Make these configurable in init_opts
for plugin in plugins.CORE_PLUGINS:
self.config.plugin_manager.register(plugin)

# Store a reference to the plugin manager's hook relay to keep things neat
self._hooks = self.config.plugin_manager.hook

self._hook(self._hooks.pyls_initialize)

def _hook(self, hook, doc_uri=None, **kwargs):
doc = self.workspace.get_document(doc_uri) if doc_uri else None
return hook(config=self.config, workspace=self.workspace, document=doc, **kwargs)

def code_actions(self, doc_uri, range, context):
return flatten(self._hook(self._hooks.pyls_code_actions, doc_uri, range=range, context=context))

Expand Down
11 changes: 11 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,16 @@
'console_scripts': [
'pyls = pyls.__main__:main',
],
'pyls': [
'jedi_completion = pyls.plugins.completion',
'jedi_definition = pyls.plugins.definition',
'jedi_hover = pyls.plugins.hover',
'jedi_references = pyls.plugins.references',
'jedi_signature_help = pyls.plugins.signature',
'jedi_symbols = pyls.plugins.symbols',
'yapf = pyls.plugins.format',
'pycodestyle = pyls.plugins.pycodestyle_lint',
'pyflakes = pyls.plugins.pyflakes_lint',
]
},
)

0 comments on commit 04e0261

Please sign in to comment.