microsoft / microsoft/multilspy

Add a more low-level LanguageServer.send example to the documentation

Open
#89 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
610
Forks
111
PR merge metrics
No merged PRs in 30d

Description

If I understand it correctly, SyncLanguageServer currently supports only a few API methods directly: request_definition, request_references, request_completions, request_document_symbols, request_hover.

For everyhing else user should use SyncLanguageServer.language_server.server.send.
Would be great to attach some example to the documentation on how to do so. Perhaps in a form of test and just refer to it.

I'll attach a simple example below.

import asyncio
from multilspy import SyncLanguageServer
from multilspy.multilspy_config import MultilspyConfig
from multilspy.multilspy_logger import MultilspyLogger
from multilspy.lsp_protocol_handler.lsp_constants import LSPConstants
from pathlib import Path, PurePath


config = MultilspyConfig.from_dict({"code_language": "python"})
logger = MultilspyLogger()
repository_root_path = r"L:\pomoika\test_files"
lsp = SyncLanguageServer.create(config, logger, repository_root_path)

# Start the language server
with lsp.start_server():
    file_path = "test.py"
    line_number, column_number = 1, 0
    server = lsp.language_server

    async def req_definition():
        with server.open_file(file_path):
            response = await server.server.send.declaration(
                {
                    LSPConstants.TEXT_DOCUMENT: {
                        LSPConstants.URI: Path(str(PurePath(server.repository_root_path, file_path))).as_uri()
                    },
                    LSPConstants.POSITION: {
                        LSPConstants.LINE: line_number,
                        LSPConstants.CHARACTER: column_number,
                    },
                }
            )
            return response

    async def req_declaration():
        with server.open_file(file_path):
            response = await server.server.send.declaration(
                {
                    LSPConstants.TEXT_DOCUMENT: {
                        LSPConstants.URI: Path(str(PurePath(server.repository_root_path, file_path))).as_uri()
                    },
                    LSPConstants.POSITION: {
                        LSPConstants.LINE: line_number,
                        LSPConstants.CHARACTER: column_number,
                    },
                }
            )
            return response

    result = asyncio.run_coroutine_threadsafe(req_definition(), lsp.loop).result(timeout=lsp.timeout)
    # [{'uri': 'file:///l:/pomoika/test_files/test.py', 'range': {'start': {'line': 1, 'character': 0}, 'end': {'line': 1, 'character': 1}}}]
    print(result)
    result = asyncio.run_coroutine_threadsafe(req_declaration(), lsp.loop).result(timeout=lsp.timeout)
    # [{'uri': 'file:///l:/pomoika/test_files/test.py', 'range': {'start': {'line': 1, 'character': 0}, 'end': {'line': 1, 'character': 1}}}]
    print(result)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the existing documentation for SyncLanguageServer and the low-level language_server.server.send entry point. Use the supplied declaration example as the reference, add a documented example for calling an otherwise unsupported LSP method, and verify that the example matches the public API.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.