@@ -23,6 +23,44 @@ def main():
2323"""
2424
2525
26+ class FakeEditorMethodsMixin :
27+ """
28+ Represents the methods to be added to a dispatcher class when faking an editor.
29+ """
30+ def m_window__work_done_progress__create (self , * _args , ** _kwargs ):
31+ """
32+ Fake editor method `window/workDoneProgress/create`.
33+
34+ related spec:
35+ https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_workDoneProgress_create
36+ """
37+ return None
38+
39+
40+ class FakePythonLSPServer (FakeEditorMethodsMixin , PythonLSPServer ):
41+ pass
42+
43+
44+ class FakeEndpoint (Endpoint ):
45+ """
46+ Fake Endpoint representing the editor / LSP client.
47+
48+ The `dispatcher` dict will be used to synchronously calculate the responses
49+ for calls to `.request` and resolve the futures with the value or errors.
50+
51+ Fake methods in the `dispatcher` should raise `JsonRpcException` for any
52+ error.
53+ """
54+ def request (self , method , params = None ):
55+ request_future = super ().request (method , params )
56+ try :
57+ request_future .set_result (self ._dispatcher [method ](params ))
58+ except JsonRpcException as e :
59+ request_future .set_exception (e )
60+
61+ return request_future
62+
63+
2664@pytest .fixture
2765def pylsp (tmpdir ):
2866 """ Return an initialized python LS """
@@ -65,44 +103,6 @@ def pylsp_w_workspace_folders(tmpdir):
65103 return (ls , workspace_folders )
66104
67105
68- class FakeEditorMethodsMixin :
69- """
70- Represents the methods to be added to a dispatcher class when faking an editor.
71- """
72- def m_window__work_done_progress__create (self , * _args , ** _kwargs ):
73- """
74- Fake editor method `window/workDoneProgress/create`.
75-
76- related spec:
77- https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_workDoneProgress_create
78- """
79- return None
80-
81-
82- class FakePythonLSPServer (FakeEditorMethodsMixin , PythonLSPServer ):
83- pass
84-
85-
86- class FakeEndpoint (Endpoint ):
87- """
88- Fake Endpoint representing the editor / LSP client.
89-
90- The `dispatcher` dict will be used to synchronously calculate the responses
91- for calls to `.request` and resolve the futures with the value or errors.
92-
93- Fake methods in the `dispatcher` should raise `JsonRpcException` for any
94- error.
95- """
96- def request (self , method , params = None ):
97- request_future = super ().request (method , params )
98- try :
99- request_future .set_result (self ._dispatcher [method ](params ))
100- except JsonRpcException as e :
101- request_future .set_exception (e )
102-
103- return request_future
104-
105-
106106@pytest .fixture ()
107107def consumer ():
108108 return MagicMock ()
0 commit comments