Skip to content

Commit 2adaf8f

Browse files
committed
first progress reporting
1 parent fdf2b22 commit 2adaf8f

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

pylsp/python_lsp.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,14 @@ def _match_uri_to_workspace(self, uri):
228228
def _hook(self, hook_name, doc_uri=None, **kwargs):
229229
"""Calls hook_name and returns a list of results from all registered handlers"""
230230
workspace = self._match_uri_to_workspace(doc_uri)
231+
progress_token = self.workspace.progress_begin(hook_name.removeprefix("pylsp_"))
232+
231233
doc = workspace.get_document(doc_uri) if doc_uri else None
232234
hook_handlers = self.config.plugin_manager.subset_hook_caller(hook_name, self.config.disabled_plugins)
233-
return hook_handlers(config=self.config, workspace=workspace, document=doc, **kwargs)
235+
result = hook_handlers(config=self.config, workspace=workspace, document=doc, **kwargs)
236+
237+
self.workspace.progress_end(progress_token)
238+
return result
234239

235240
def capabilities(self):
236241
server_capabilities = {

pylsp/workspace.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import logging
66
import os
77
import re
8+
import uuid
89
import functools
10+
from typing import Optional
911
from threading import RLock
1012

1113
import jedi
@@ -31,6 +33,7 @@ def wrapper(self, *args, **kwargs):
3133
class Workspace:
3234

3335
M_PUBLISH_DIAGNOSTICS = 'textDocument/publishDiagnostics'
36+
M_PROGRESS = '$/progress'
3437
M_APPLY_EDIT = 'workspace/applyEdit'
3538
M_SHOW_MESSAGE = 'window/showMessage'
3639

@@ -109,6 +112,58 @@ def apply_edit(self, edit):
109112
def publish_diagnostics(self, doc_uri, diagnostics):
110113
self._endpoint.notify(self.M_PUBLISH_DIAGNOSTICS, params={'uri': doc_uri, 'diagnostics': diagnostics})
111114

115+
def progress_begin(self, title: str, message: Optional[str]=None, percentage: Optional[int]=None) -> str:
116+
token = str(uuid.uuid4())
117+
value = {
118+
'kind': 'begin',
119+
'title': title,
120+
}
121+
if message:
122+
value['message'] = message
123+
if percentage:
124+
value['percentage'] = percentage
125+
126+
self._endpoint.notify(
127+
self.M_PROGRESS,
128+
params={
129+
'token': token,
130+
'value': value,
131+
}
132+
)
133+
return token
134+
135+
def progress_report(self, token: str, message: Optional[str]=None, percentage: Optional[int]=None) -> None:
136+
value = {
137+
'kind': 'report',
138+
}
139+
if message:
140+
value['message'] = message
141+
if percentage:
142+
value['percentage'] = percentage
143+
144+
self._endpoint.notify(
145+
self.M_PROGRESS,
146+
params={
147+
'token': token,
148+
'value': value,
149+
}
150+
)
151+
152+
def progress_end(self, token: str, message: Optional[str]=None) -> None:
153+
value = {
154+
'kind': 'end',
155+
}
156+
if message:
157+
value['message'] = message
158+
159+
self._endpoint.notify(
160+
self.M_PROGRESS,
161+
params={
162+
'token': token,
163+
'value': value,
164+
}
165+
)
166+
112167
def show_message(self, message, msg_type=lsp.MessageType.Info):
113168
self._endpoint.notify(self.M_SHOW_MESSAGE, params={'type': msg_type, 'message': message})
114169

0 commit comments

Comments
 (0)