fix: 🚧 working on fixing lsp

This commit is contained in:
Nate Sesti 2023-09-06 11:58:26 -07:00
parent b2976c23c8
commit 1f95bb2878
3 changed files with 13 additions and 7 deletions

View file

@ -1,3 +1,4 @@
import asyncio
import os
import socket
import subprocess
@ -57,7 +58,7 @@ class SocketFileWrapper:
return self.sockfile.close()
def create_json_rpc_endpoint(use_subprocess: Optional[str] = None):
async def create_json_rpc_endpoint(use_subprocess: Optional[str] = None):
if use_subprocess is None:
try:
threading.Thread(
@ -67,6 +68,8 @@ def create_json_rpc_endpoint(use_subprocess: Optional[str] = None):
except Exception as e:
logger.warning("Could not start TCP server: %s", e)
await asyncio.sleep(2)
# Connect to the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("localhost", 8080))
@ -100,8 +103,10 @@ def uri_to_filename(uri: str) -> str:
return uri
def create_lsp_client(workspace_dir: str, use_subprocess: Optional[str] = None):
json_rpc_endpoint, process = create_json_rpc_endpoint(use_subprocess=use_subprocess)
async def create_lsp_client(workspace_dir: str, use_subprocess: Optional[str] = None):
json_rpc_endpoint, process = await create_json_rpc_endpoint(
use_subprocess=use_subprocess
)
lsp_endpoint = LspEndpoint(json_rpc_endpoint)
lsp_client = LspClient(lsp_endpoint)
capabilities = {
@ -282,7 +287,7 @@ class ContinueLSPClient(BaseModel):
return original_dict
async def start(self):
self.lsp_client, self.lsp_process = create_lsp_client(
self.lsp_client, self.lsp_process = await create_lsp_client(
self.workspace_dir, use_subprocess=self.use_subprocess
)

View file

@ -97,11 +97,10 @@ class ContinueSDK(AbstractContinueSDK):
try:
sdk.lsp = ContinueLSPClient(
workspace_dir=sdk.ide.workspace_directory,
# use_subprocess="python3.10 -m pylsp",
)
await sdk.lsp.start()
except:
logger.warning("Failed to start LSP client", exc_info=True)
except Exception as e:
logger.warning(f"Failed to start LSP client: {e}", exc_info=True)
sdk.lsp = None
# create_async_task(

View file

@ -1,6 +1,7 @@
from __future__ import print_function
import threading
import time
class LspEndpoint(threading.Thread):
@ -27,6 +28,7 @@ class LspEndpoint(threading.Thread):
def run(self):
while not self.shutdown_flag:
time.sleep(0.1)
jsonrpc_message = self.json_rpc_endpoint.recv_response()
if jsonrpc_message is None: