91 lines
2.6 KiB
Python
91 lines
2.6 KiB
Python
from lsprotocol.types import (
|
|
TEXT_DOCUMENT_COMPLETION,
|
|
TEXT_DOCUMENT_DOCUMENT_SYMBOL,
|
|
CompletionItem,
|
|
CompletionItemKind,
|
|
CompletionItemLabelDetails,
|
|
CompletionOptions,
|
|
CompletionParams,
|
|
DocumentSymbol,
|
|
DocumentSymbolParams,
|
|
NotebookDocumentSyncOptions,
|
|
Position,
|
|
Range,
|
|
SymbolKind,
|
|
TextDocumentSyncKind,
|
|
WorkDoneProgressBegin,
|
|
WorkDoneProgressEnd,
|
|
WorkDoneProgressReport,
|
|
)
|
|
from pygls.lsp.server import LanguageServer
|
|
|
|
from .clickup import ClickupSession, ClickupTask
|
|
|
|
|
|
class CustomServer(LanguageServer):
|
|
cache: dict[str, ClickupTask]
|
|
cu_session: ClickupSession
|
|
|
|
def __init__(
|
|
self,
|
|
name: str,
|
|
version: str,
|
|
text_document_sync_kind: TextDocumentSyncKind = TextDocumentSyncKind.Incremental,
|
|
notebook_document_sync: NotebookDocumentSyncOptions | None = None,
|
|
) -> None:
|
|
super().__init__(name, version, text_document_sync_kind, notebook_document_sync)
|
|
self.cache = {}
|
|
self.cu_session = ClickupSession()
|
|
self.update_task_cache()
|
|
|
|
def update_task_cache(self) -> None:
|
|
self.protocol.progress.begin(
|
|
"startup", WorkDoneProgressBegin("Fetching Cache ...", percentage=0, cancellable=True)
|
|
)
|
|
self.cache = {}
|
|
tasks = self.cu_session.get_ta()
|
|
for ti, t in enumerate(tasks):
|
|
self.cache[t.id] = t
|
|
self.protocol.progress.report(
|
|
"startup",
|
|
WorkDoneProgressReport(
|
|
message="Fetched Cache", percentage=int(100 * (1 + ti) / len(tasks))
|
|
),
|
|
)
|
|
|
|
self.protocol.progress.end("startup", WorkDoneProgressEnd(message="Done Caching"))
|
|
|
|
|
|
server = CustomServer("mrpy-server", "0.1.0")
|
|
|
|
|
|
@server.feature(TEXT_DOCUMENT_DOCUMENT_SYMBOL)
|
|
async def list_ids(params: DocumentSymbolParams) -> list[DocumentSymbol]:
|
|
return [
|
|
DocumentSymbol(
|
|
t.id,
|
|
SymbolKind.Enum,
|
|
Range(Position(i, 0), Position(i, 0)),
|
|
Range(Position(i, 0), Position(i, 0)),
|
|
detail=t.name,
|
|
)
|
|
for i, t in enumerate(server.cache.values())
|
|
]
|
|
|
|
|
|
@server.feature(TEXT_DOCUMENT_COMPLETION)
|
|
async def complete_cu_ids(params: CompletionParams) -> list[CompletionItem]:
|
|
return [
|
|
CompletionItem(
|
|
t.name,
|
|
CompletionItemLabelDetails(detail=f" #{t.id}"),
|
|
kind=CompletionItemKind.Constant,
|
|
insert_text=f"[{t.name} #{t.id}](https://app.clickup.com/t/{t.id})",
|
|
)
|
|
for t in server.cache.values()
|
|
]
|
|
|
|
|
|
def main() -> None:
|
|
server.start_io()
|