5
5
import logging
6
6
import os
7
7
import re
8
+ import uuid
8
9
import functools
10
+ from typing import Optional
9
11
from threading import RLock
10
12
11
13
import jedi
@@ -31,6 +33,7 @@ def wrapper(self, *args, **kwargs):
31
33
class Workspace :
32
34
33
35
M_PUBLISH_DIAGNOSTICS = 'textDocument/publishDiagnostics'
36
+ M_PROGRESS = '$/progress'
34
37
M_APPLY_EDIT = 'workspace/applyEdit'
35
38
M_SHOW_MESSAGE = 'window/showMessage'
36
39
@@ -109,6 +112,58 @@ def apply_edit(self, edit):
109
112
def publish_diagnostics (self , doc_uri , diagnostics ):
110
113
self ._endpoint .notify (self .M_PUBLISH_DIAGNOSTICS , params = {'uri' : doc_uri , 'diagnostics' : diagnostics })
111
114
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
+
112
167
def show_message (self , message , msg_type = lsp .MessageType .Info ):
113
168
self ._endpoint .notify (self .M_SHOW_MESSAGE , params = {'type' : msg_type , 'message' : message })
114
169
0 commit comments