예제 #1
0
    def __init__(self):
        from DHParser.lsp import gen_lsp_table
        self.lsp_data = {
            'processId': 0,
            'rootUri': '',
            'clientCapabilities': {},
            'serverInfo': {
                "name": "EBNF-Server",
                "version": "0.2"
            },
            'serverCapabilities': {
                "textDocumentSync": 2,  # 0 = None, 1 = full, 2 = incremental
                "completionProvider": {
                    "resolveProvider": False,
                    "triggerCharacters": ['@']
                }
            }
        }
        self.connection = None
        self.cpu_bound = EBNFCPUBoundTasks(self.lsp_data)
        self.blocking = EBNFBlockingTasks(self.lsp_data)
        self.lsp_table = gen_lsp_table(self, prefix='lsp_')
        self.lsp_fulltable = self.lsp_table.copy()
        assert self.lsp_fulltable.keys().isdisjoint(
            self.cpu_bound.lsp_table.keys())
        self.lsp_fulltable.update(self.cpu_bound.lsp_table)
        assert self.lsp_fulltable.keys().isdisjoint(
            self.blocking.lsp_table.keys())
        self.lsp_fulltable.update(self.blocking.lsp_table)

        self.pending_changes = dict()  # uri -> text
        self.current_text = dict()  # uri -> TextBuffer
예제 #2
0
 def start_server(self):
     stop_tcp_server('127.0.0.1', TEST_PORT)
     if self.p is not None:
         self.p.join()
     self.lsp = LSP()
     lsp_table = gen_lsp_table(self.lsp, prefix='lsp_')
     self.p = spawn_tcp_server('127.0.0.1', TEST_PORT,
                               (lsp_table, frozenset(), frozenset()))
예제 #3
0
    def __init__(self):
        from DHParser.lsp import gen_lsp_table
        from DHParser.lsp import CompletionItemKind, TextDocumentSyncKind
        self.lsp_data = {
            'processId': 0,
            'rootUri': '',
            'clientCapabilities': {},
            'serverInfo': {
                "name": "EBNF-Server",
                "version": "0.2"
            },
            'serverCapabilities': {
                "textDocumentSync": TextDocumentSyncKind.Incremental,
                "completionProvider": {
                    "resolveProvider": False,
                    "triggerCharacters":
                    ['@', ' ']  # is necessary to avoid VSC kicking in
                }
            }
        }
        self.connection = None
        self.cpu_bound = EBNFCPUBoundTasks(self.lsp_data)
        self.blocking = EBNFBlockingTasks(self.lsp_data)
        self.lsp_table = gen_lsp_table(self, prefix='lsp_')
        self.lsp_fulltable = self.lsp_table.copy()
        assert self.lsp_fulltable.keys().isdisjoint(
            self.cpu_bound.lsp_table.keys())
        self.lsp_fulltable.update(self.cpu_bound.lsp_table)
        assert self.lsp_fulltable.keys().isdisjoint(
            self.blocking.lsp_table.keys())
        self.lsp_fulltable.update(self.blocking.lsp_table)

        self.current_text = dict()  # uri -> TextBuffer
        self.last_compiled_version = dict()  # uri -> int
        self.last_signature = dict()  # uri -> str
        self.server_call_ID = 0  # unique id

        from itertools import chain
        self.completions.sort()
        self.completion_items1 = [{
            k: v
            for k, v in chain(zip(self.completion_fields, item),
                              [['kind', CompletionItemKind.Keyword]])
        } for item in self.completions]
        self.completion_items2 = [
            item.copy() for item in self.completion_items1
        ]
        for item in self.completion_items1:
            item['insertText'] = item['insertText'][1:]
        for item in self.completion_items2:
            item['insertText'] = item['insertText'][2:]
        self.completion_labels = [f[0] for f in self.completions]

        self.can_publishDiagnostics = False
예제 #4
0
 def __init__(self):
     from DHParser.lsp import gen_lsp_table
     self.lsp_data = {
         'processId': 0,
         'rootUri': '',
         'clientCapabilities': {},
         'serverInfo': {
             "name": "atf-Server",
             "version": "0.1"
         },
         'serverCapabilities': {}
     }
     self.connection = None
     self.cpu_bound = atfCPUBoundTasks(self.lsp_data)
     self.blocking = atfBlockingTasks(self.lsp_data)
     self.lsp_table = gen_lsp_table(self, prefix='lsp_')
     self.lsp_fulltable = self.lsp_table.copy()
     assert self.lsp_fulltable.keys().isdisjoint(
         self.cpu_bound.lsp_table.keys())
     self.lsp_fulltable.update(self.cpu_bound.lsp_table)
     assert self.lsp_fulltable.keys().isdisjoint(
         self.blocking.lsp_table.keys())
     self.lsp_fulltable.update(self.blocking.lsp_table)
예제 #5
0
 def __init__(self, lsp_data: dict):
     from DHParser.lsp import gen_lsp_table
     self.lsp_data = lsp_data
     self.lsp_table = gen_lsp_table(self, prefix='lsp_')
예제 #6
0
def run_server(host, port, log_path=None):
    global scriptpath
    grammar_src = os.path.abspath(__file__).replace('Server.py', '.ebnf')
    dhparserdir = os.path.abspath(
        os.path.join(scriptpath, os.path.join('..', '..')))
    if scriptpath not in sys.path:
        sys.path.append(scriptpath)
    if dhparserdir not in sys.path:
        sys.path.append(dhparserdir)
    from DHParser.dsl import recompile_grammar
    if not recompile_grammar(
            grammar_src,
            force=False,
            notify=lambda: print('recompiling ' + grammar_src)):
        print('\nErrors while recompiling "%s":' % grammar_src +
              '\n--------------------------------------\n\n')
        with open('LaTeX_ebnf_ERRORS.txt', encoding='utf-8') as f:
            print(f.read())
        sys.exit(1)
    recompile_grammar(os.path.join(scriptpath, 'LaTeX.ebnf'), force=False)
    from LaTeXCompiler import compile_src
    from DHParser.server import Server
    from DHParser.lsp import gen_lsp_table
    config_filename = get_config_filename()
    try:
        with open(config_filename, 'w') as f:
            f.write(host + ' ' + str(port))
    except PermissionError:
        print('PermissionError: Could not write temporary config file: ' +
              config_filename)

    print('Starting server on %s:%i' % (host, port))
    LaTeX_lsp = LaTeXLanguageServerProtocol()
    lsp_table = gen_lsp_table(LaTeX_lsp, prefix='lsp_')
    lsp_table.update({'default': compile_src})
    non_blocking = frozenset(('initialize', 'initialized', 'shutdown', 'exit'))
    LaTeX_server = Server(rpc_functions=lsp_table,
                          cpu_bound=set(lsp_table.keys() - non_blocking),
                          blocking=frozenset())
    if log_path is not None:
        LaTeX_server.echo_log = True
        print(LaTeX_server.start_logging(log_path))

    try:
        LaTeX_server.run_tcp_server(
            host, port)  # returns only after server has stopped
    except OSError as e:
        print(e)
        print('Could not start server. Shutting down!')
        return 1
    except KeyboardInterrupt:
        print('Keyboard interrupt received.')
        return 1
    finally:
        print('Server at host: {} port: {} has been stopped.'.format(
            host, port))
        cfg_filename = get_config_filename()
        try:
            os.remove(cfg_filename)
            print('Removing temporary config file: "{}".'.format(cfg_filename))
        except FileNotFoundError:
            print('Config file "{}" does not exist any more.'.format(
                cfg_filename))
    return 0