From 758d78132a7d52cb2afa9d532a38f4814626ddf9 Mon Sep 17 00:00:00 2001 From: ryjm Date: Sun, 27 Mar 2022 01:32:55 -0400 Subject: [PATCH] Remove python files No longer used. --- hoon-language-server | 200 ------------------------------------------- setup.py | 23 ----- 2 files changed, 223 deletions(-) delete mode 100755 hoon-language-server delete mode 100644 setup.py diff --git a/hoon-language-server b/hoon-language-server deleted file mode 100755 index 539ca16..0000000 --- a/hoon-language-server +++ /dev/null @@ -1,200 +0,0 @@ -#!/usr/bin/env python3 - -# Adapted from: -# https://github.com/palantir/python-jsonrpc-server/blob/409eb0c/examples/langserver.py - -import requests -import json -import logging -import sys -import time - -from getopt import getopt, GetoptError -from pyls_jsonrpc import dispatchers, endpoint -from pyls_jsonrpc.streams import JsonRpcStreamReader, JsonRpcStreamWriter - -logging.basicConfig(level=logging.INFO, filename='/tmp/hoon-language-server.log', filemode='w') -log = logging.getLogger(__name__) - -defaultConfig = { - 'port': 8080, - 'delay': 0 -} - - -def bail(): - "Print usage string and bail" - print('usage: %s [-p port] [-d ms_delay]' % sys.argv[0]) - sys.exit(2) - -def get_config(): - "Parse command line args and return config" - try: - options, args = getopt(sys.argv[1:], 'p:d:', ['--port', '--delay']) - except GetoptError: - bail() - config = defaultConfig.copy() - for option, arg in options: - if option in ('-p', '--port'): - try: - config['port'] = int(arg) - except ValueError: - bail() - elif option in ('-d', '--delay'): - try: - config['delay'] = int(arg) - except ValueError: - bail() - else: - bail() - return config - - -def stdio(): - if sys.version_info >= (3, 0): - # pylint: disable=no-member - stdin, stdout = sys.stdin.buffer, sys.stdout.buffer - else: - stdin, stdout = sys.stdin, sys.stdout - - return stdin, stdout - - -class LanguageServer(dispatchers.MethodDispatcher): - """Implement a JSON RPC method dispatcher for the language server protocol.""" - - def __init__(self, rx, tx, config=defaultConfig): - # Endpoint is lazily set after construction - self._jsonrpc_stream_reader = JsonRpcStreamReader(rx) - self._jsonrpc_stream_writer = JsonRpcStreamWriter(tx) - self._endpoint = endpoint.Endpoint(self, - self._jsonrpc_stream_writer.write, max_workers=1) - self._base_url = 'http://localhost:' + str(config['port']) - data={'password': 'lidlut-tabwed-pillex-ridrup'} # fakezod - self._requests_session = requests.Session() - self._requests_session.post(self._base_url + '/~/login', data=data) - - def _hook(self, uri, data): - r = self._requests_session.post(self._base_url + '/~language-server-protocol', - data=json.dumps({'uri': uri, 'data': data})) - try: - log.info("good hook %s", r.json()) - return r.json() - except json.decoder.JSONDecodeError: - log.info("broked hook %s", r.text) - return None - - def start(self): - self._jsonrpc_stream_reader.listen(self._endpoint.consume) - - def m_initialize(self, rootUri=None, **kwargs): - log.info('Got initialize params: %s', kwargs) - return {'capabilities': { - 'hoverProvider': True, - 'textDocumentSync': { - 'openClose': True, - 'change': 2, # send incremental updates - 'willSave': True, - 'save': True - }, - 'definitionProvider': True, - 'completionProvider': { - 'resolveProvider': False, # We know everything ahead of time - 'triggerCharacters': [ - '-', '+', '^', '!', '@', '$', '%', '.', - '%', '&', '*', '/', ',', '>', '<', '~', - '|', '=', ';', ':', '_', - ] - }, - }} - - def m_initialized(self, **kwargs): - log.info("Got initialized params: %s", kwargs) - pass - - def m_shutdown(self, **kwargs): - log.info("Got shutdown request: %s", kwargs) - sys.exit(2) - - def m_text_document__hover(self, textDocument=None, position=None, **_kwargs): - log.info("Hovering on text document %s at: %s", textDocument['uri'], position) - log.info(position) - res = self._hook(textDocument['uri'], {'hover': position}) - log.info('hover responded: %s', res) - return res - - - def m_text_document__did_open(self, textDocument=None, **_kwargs): - log.info("Opened text document %s", textDocument['uri']) - log.info(self._hook( - textDocument['uri'], - {'sync': [{'text': textDocument['text']}]} - )) - - def m_text_document__will_save(self, textDocument=None, **_kwargs): - log.info("saving %s", textDocument['uri']) - # log.info(self._hook({'sync': textDocument['text']})) - - - def m_text_document__did_save(self, textDocument=None, **_kwargs): - log.info("saved %s", textDocument['uri']) - time.sleep(config['delay'] / 1000) # delay in ms - res = self._hook(textDocument['uri'], {'commit': 1}) - log.info("save res: %s", res) - if res['good']: - self._endpoint.notify('textDocument/publishDiagnostics', { - 'uri': textDocument['uri'], - 'diagnostics': [] - }) - else: - self._endpoint.notify('textDocument/publishDiagnostics', { - 'uri': textDocument['uri'], - 'diagnostics': res['diagnostics'] - }) - - - def m_text_document__did_change(self, textDocument=None, **_kwargs): - log.info("changing %s", textDocument['uri']) - log.info("diff: %s", _kwargs) - self._hook( - textDocument['uri'], - {'sync': _kwargs['contentChanges']} - ) - - def m_text_document__completion(self, textDocument=None, - position=None, **kwargs): - log.info("Got compl params: %s %s %s", textDocument, position, - kwargs) - res = self._hook(textDocument['uri'], {'completion': position}) - if res['good']: - self._endpoint.notify('textDocument/publishDiagnostics', { - 'uri': textDocument['uri'], - 'diagnostics': [] - }) - return res['result'] - else: - self._endpoint.notify('textDocument/publishDiagnostics', { - 'uri': textDocument['uri'], - 'diagnostics': res['diagnostics'] - }) - return None - - def m_text_document__definition(self, textDocument=None, - position=None, **kwargs): - log.info("Got def params: %s %s %s", textDocument, position, - kwargs) - return { - 'uri': textDocument['uri'], - 'range': { - 'start': { 'line': 1, 'character': '3' }, - 'end': { 'line': 1, 'character': '5' } - } - } - - -if __name__ == "__main__": - stdin, stdout = stdio() - config = get_config() - print(config) - server = LanguageServer(stdin,stdout, config) - server.start() diff --git a/setup.py b/setup.py deleted file mode 100644 index c0a8971..0000000 --- a/setup.py +++ /dev/null @@ -1,23 +0,0 @@ -import setuptools -with open("README.md", "r") as fh: - long_description = fh.read() -setuptools.setup( - name='hoon-language-server', - version='0.1.1', - scripts=['hoon-language-server'] , - author="Tlon", - author_email="philip@tlon.io", - description="Language Server for Hoon", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/urbit/hoon-language-server", - packages=setuptools.find_packages(), - install_requires=[ - 'requests', - 'python-jsonrpc-server', - ], - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - ], - )