Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entirely use lsprotocol types for serialization and deserialization. #1

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/fountain-extension/src/server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from pygls.server import LanguageServer
from pygls.lsp.methods import COMPLETION
from pygls.lsp.types import (CompletionItem, CompletionParams, CompletionList, CompletionOptions)
from lsprotocol.types import TEXT_DOCUMENT_COMPLETION
from lsprotocol.types import (CompletionItem, CompletionParams, CompletionList, CompletionOptions)

# The following imports are required for the glue code in 'server.ts'
import json
Expand All @@ -12,7 +12,7 @@

CHARACTER = re.compile(r"^[A-Z][A-Z ]+$", re.MULTILINE)

@server.feature(COMPLETION, CompletionOptions(trigger_characters=['.']))
@server.feature(TEXT_DOCUMENT_COMPLETION, CompletionOptions(trigger_characters=['.']))
def on_completion(ls: LanguageServer, params: CompletionParams) -> CompletionList:
"""Completion suggestions for character names."""

Expand Down
25 changes: 12 additions & 13 deletions examples/json-extension/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@
from json import JSONDecodeError
from typing import Optional

from pygls.lsp.methods import (COMPLETION, TEXT_DOCUMENT_DID_CHANGE,
TEXT_DOCUMENT_DID_CLOSE, TEXT_DOCUMENT_DID_OPEN,
from lsprotocol.types import (TEXT_DOCUMENT_COMPLETION, TEXT_DOCUMENT_DID_CHANGE,
TEXT_DOCUMENT_DID_CLOSE, TEXT_DOCUMENT_DID_OPEN,
TEXT_DOCUMENT_SEMANTIC_TOKENS_FULL)
from pygls.lsp.types import (CompletionItem, CompletionList, CompletionOptions,
from lsprotocol.types import (CompletionItem, CompletionList, CompletionOptions,
CompletionParams, ConfigurationItem,
ConfigurationParams, Diagnostic,
DidChangeTextDocumentParams,
DidCloseTextDocumentParams,
DidOpenTextDocumentParams, MessageType, Position,
Range, Registration, RegistrationParams,
SemanticTokens, SemanticTokensLegend, SemanticTokensParams,
Unregistration, UnregistrationParams)
from pygls.lsp.types.basic_structures import (WorkDoneProgressBegin,
WorkDoneProgressEnd,
WorkDoneProgressReport)
Unregistration, UnregistrationParams,
WorkDoneProgressBegin, WorkDoneProgressEnd,
WorkDoneProgressReport)
from pygls.server import LanguageServer

COUNT_DOWN_START_IN_SECONDS = 10
Expand Down Expand Up @@ -98,7 +97,7 @@ def _validate_json(source):
return diagnostics


@json_server.feature(COMPLETION, CompletionOptions(trigger_characters=[',']))
@json_server.feature(TEXT_DOCUMENT_COMPLETION, CompletionOptions(trigger_characters=[',']))
def completions(params: Optional[CompletionParams] = None) -> CompletionList:
"""Returns completion items."""
return CompletionList(
Expand Down Expand Up @@ -164,9 +163,9 @@ async def did_open(ls, params: DidOpenTextDocumentParams):
def semantic_tokens(ls: JsonLanguageServer, params: SemanticTokensParams):
"""See https://microsoft.github.io/language-server-protocol/specification#textDocument_semanticTokens
for details on how semantic tokens are encoded."""

TOKENS = re.compile('".*"(?=:)')

uri = params.text_document.uri
doc = ls.workspace.get_document(uri)

Expand All @@ -184,7 +183,7 @@ def semantic_tokens(ls: JsonLanguageServer, params: SemanticTokensParams):
(lineno - last_line),
(start - last_start),
(end - start),
0,
0,
0
]

Expand Down Expand Up @@ -220,7 +219,7 @@ async def register_completions(ls: JsonLanguageServer, *args):
params = RegistrationParams(registrations=[
Registration(
id=str(uuid.uuid4()),
method=COMPLETION,
method=TEXT_DOCUMENT_COMPLETION,
register_options={"triggerCharacters": "[':']"})
])
response = await ls.register_capability_async(params)
Expand Down Expand Up @@ -292,7 +291,7 @@ def show_configuration_thread(ls: JsonLanguageServer, *args):
async def unregister_completions(ls: JsonLanguageServer, *args):
"""Unregister completions method on the client."""
params = UnregistrationParams(unregisterations=[
Unregistration(id=str(uuid.uuid4()), method=COMPLETION)
Unregistration(id=str(uuid.uuid4()), method=TEXT_DOCUMENT_COMPLETION)
])
response = await ls.unregister_capability_async(params)
if response is None:
Expand Down
2 changes: 1 addition & 1 deletion examples/json-extension/server/tests/unit/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import pytest
from mock import Mock
from pygls.lsp.types import (DidCloseTextDocumentParams,
from lsprotocol.types import (DidCloseTextDocumentParams,
DidOpenTextDocumentParams, TextDocumentIdentifier,
TextDocumentItem)
from pygls.workspace import Document, Workspace
Expand Down
Loading