How to use the pygls.lsp function in pygls

To help you get started, we’ve selected a few pygls examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openlawlibrary / pygls / pygls / lsp_impl.py View on Github external
def _setup_base_features(self):
        # General
        self._base_features[lsp.INITIALIZE] = self.initialize
        self._base_features[lsp.INITIALIZED] = self.initialized
        # self._base_features[lsp.SHUTDOWN] = self.m_shutdown
        # self._base_features[lsp.EXIT] = self.m_exit

        # Workspace
        self._base_features[lsp.EXECUTE_COMMAND] = self.execute_command
        self._base_features[lsp.DID_CHANGE_WORKSPACE_FOLDERS] = self.workspace__did_change_workspace_folders
        self._base_features[lsp.DID_CHANGE_CONFIGURATION] = self.workspace__did_change_configuration

        # Text Synchronization
        self._base_features[lsp.TEXT_DOC_DID_OPEN] = self.text_document__did_open
        self._base_features[lsp.TEXT_DOC_DID_CHANGE] = self.text_document__did_change
        self._base_features[lsp.TEXT_DOC_DID_CLOSE] = self.text_document__did_close
        self._base_features[lsp.TEXT_DOC_DID_SAVE] = self.text_document__did_save
github openlawlibrary / pygls / examples / simple-json-server / server / server.py View on Github external
@ls.feature(lsp.COMPLETION, triggerCharacters=[','])
def completions(textDocument=None, position=None, **_kwargs):
    '''
    Returns completion items (dummy)
    '''
    return {
        'isIncomplete': False,
        'items': [{'label': '"'},
                  {'label': '['},
                  {'label': '{'},
                  {'label': '}'},
                  {'label': ']'}]
    }
github openlawlibrary / pygls / pygls / lsp_impl.py View on Github external
def decorator(f):
            # Register commands separately
            if feature_name is lsp.REGISTER_COMMAND:
                self._commands[options['name']] = f
            else:
                self._features[feature_name] = f

            if options:
                self._feature_options[feature_name] = options

            return f
        return decorator
github openlawlibrary / pygls / pygls / lsp_impl.py View on Github external
def _setup_base_features(self):
        # General
        self._base_features[lsp.INITIALIZE] = self.initialize
        self._base_features[lsp.INITIALIZED] = self.initialized
        # self._base_features[lsp.SHUTDOWN] = self.m_shutdown
        # self._base_features[lsp.EXIT] = self.m_exit

        # Workspace
        self._base_features[lsp.EXECUTE_COMMAND] = self.execute_command
        self._base_features[lsp.DID_CHANGE_WORKSPACE_FOLDERS] = self.workspace__did_change_workspace_folders
        self._base_features[lsp.DID_CHANGE_CONFIGURATION] = self.workspace__did_change_configuration

        # Text Synchronization
        self._base_features[lsp.TEXT_DOC_DID_OPEN] = self.text_document__did_open
        self._base_features[lsp.TEXT_DOC_DID_CHANGE] = self.text_document__did_change
        self._base_features[lsp.TEXT_DOC_DID_CLOSE] = self.text_document__did_close
        self._base_features[lsp.TEXT_DOC_DID_SAVE] = self.text_document__did_save
github openlawlibrary / pygls / pygls / lsp_impl.py View on Github external
},
            'documentFormattingProvider': True,
            'documentHighlightProvider': True,
            'documentRangeFormattingProvider': True,
            'documentSymbolProvider': True,
            'definitionProvider': True,
            'executeCommandProvider': {
                'commands': list(self._commands.keys())
            },
            'hoverProvider': True,
            'referencesProvider': True,
            'renameProvider': True,
            'signatureHelpProvider': {
                'triggerCharacters': ['(', ',']
            },
            'textDocumentSync': lsp.TextDocumentSyncKind.INCREMENTAL,
            'workspace': {
                'workspaceFolders': {
                    'supported': True,
                    'changeNotifications': True
                }
            }
        }
        log.info('Server capabilities: %s', server_capabilities)
        return server_capabilities
github openlawlibrary / pygls / examples / simple-json-server / server / server.py View on Github external
'''
    Validates json file on save and on change
    '''
    doc = ls.workspace.get_document(textDocument['uri'])

    diagnostics = []

    try:
        json.loads(doc.source)
    except JSONDecodeError as err:
        msg = err.msg
        col = err.colno
        line = err.lineno

        d = lsp.Diagnostic(
            lsp.Range(
                lsp.Position(line-1, col-1),
                lsp.Range(line-1, col)
            ),
            msg,
            source=type(ls).__name__
        )

        diagnostics.append(d)

    ls.workspace.publish_diagnostics(textDocument['uri'], diagnostics)
github openlawlibrary / pygls / pygls / lsp_impl.py View on Github external
def _setup_base_features(self):
        # General
        self._base_features[lsp.INITIALIZE] = self.initialize
        self._base_features[lsp.INITIALIZED] = self.initialized
        # self._base_features[lsp.SHUTDOWN] = self.m_shutdown
        # self._base_features[lsp.EXIT] = self.m_exit

        # Workspace
        self._base_features[lsp.EXECUTE_COMMAND] = self.execute_command
        self._base_features[lsp.DID_CHANGE_WORKSPACE_FOLDERS] = self.workspace__did_change_workspace_folders
        self._base_features[lsp.DID_CHANGE_CONFIGURATION] = self.workspace__did_change_configuration

        # Text Synchronization
        self._base_features[lsp.TEXT_DOC_DID_OPEN] = self.text_document__did_open
        self._base_features[lsp.TEXT_DOC_DID_CHANGE] = self.text_document__did_change
        self._base_features[lsp.TEXT_DOC_DID_CLOSE] = self.text_document__did_close
        self._base_features[lsp.TEXT_DOC_DID_SAVE] = self.text_document__did_save
github openlawlibrary / pygls / examples / simple-server / main.py View on Github external
@ls.feature(lsp.CODE_LENS)
def lens(doc_uri=None, **_kwargs):
    pass
github openlawlibrary / pygls / examples / simple-server / main.py View on Github external
@ls.feature(lsp.COMPLETION, triggerCharacters=['.'])
def completions(textDocument=None, position=None, **_kwargs):
    return {
        'isIncomplete': False,
        'items': [{'label': 'AAA'}, {'label': 'BBB'}]
    }
github openlawlibrary / pygls / pygls / ls.py View on Github external
Gets the configuration settings from the client.
        This method is asynchronous and the callback function
        will be called after the response is received.

        Args:
            config_params(dict): ConfigurationParams from lsp specs
            callback(callable): Callabe which will be called after
                response from the client is received
        '''
        def configuration(future):
            result = future.result()
            log.info(f'Configuration for {config_params} received: {result}')
            return callback(result)

        future = self._endpoint.request(
            lsp.WORKSPACE_CONFIGURATION, config_params)
        future.add_done_callback(configuration)