MCPcopy Create free account
hub / github.com/modelscope/ms-agent / initialize

Method initialize

ms_agent/tools/code_server/lsp_code_server.py:147–209  ·  view source on GitHub ↗

Initialize the LSP server and wait for it to be ready

(self)

Source from the content-addressed store, hash-verified

145 return {}
146
147 async def initialize(self):
148 """Initialize the LSP server and wait for it to be ready"""
149 response = await self.send_request(
150 'initialize', {
151 'processId':
152 os.getpid(),
153 'rootUri':
154 self.workspace_dir.as_uri(),
155 'rootPath':
156 str(self.workspace_dir),
157 'workspaceFolders': [{
158 'uri': self.workspace_dir.as_uri(),
159 'name': self.workspace_dir.name
160 }],
161 'capabilities': {
162 'textDocument': {
163 'publishDiagnostics': {},
164 'synchronization': {
165 'didOpen': True,
166 'didChange': True,
167 'didClose': True
168 }
169 }
170 }
171 })
172
173 if 'result' in response:
174 await self.send_notification('initialized', {})
175
176 # CRITICAL: Wait for server to be fully ready
177 # Read and discard any startup messages
178 await asyncio.sleep(
179 1.0) # Give server time to complete initialization
180
181 await self.send_notification(
182 'workspace/didChangeConfiguration', {
183 'settings': {
184 'python': {
185 'pythonPath': sys.executable,
186 },
187 'pyright': {
188 'extraPaths': [str(self.workspace_dir)]
189 },
190 }
191 })
192
193 # Consume any pending messages (like "starting" notifications)
194 try:
195 for _ in range(10):
196 try:
197 await asyncio.wait_for(
198 self._read_message(), timeout=2.0)
199 except asyncio.TimeoutError:
200 break
201 except Exception as e:
202 logger.error(f'Cleared startup messages: {e}')
203
204 self.initialized = True

Callers 4

connect_to_serverMethod · 0.45
startMethod · 0.45
startMethod · 0.45
startMethod · 0.45

Calls 3

send_requestMethod · 0.95
send_notificationMethod · 0.95
_read_messageMethod · 0.95

Tested by

no test coverage detected