mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-07-19 02:15:09 +00:00
Get rid of all transport types and settle on Protobuf (#25)
* Get rid of all transport types and settle on Protobuf hope i don't regret this * Update Cargo.toml * Update agent.py
This commit is contained in:
parent
643a47953e
commit
0a6e975ca5
38 changed files with 1484 additions and 685 deletions
|
@ -9,34 +9,6 @@ from .scripts import has_import
|
|||
from .scripts import python_setup
|
||||
|
||||
|
||||
def handle_command(command: str) -> str:
|
||||
parts = command.strip().split()
|
||||
command = parts[0]
|
||||
args = parts[1:] if len(parts) > 1 else []
|
||||
|
||||
if command == "django_setup":
|
||||
return json.dumps(django_setup.get_django_setup_info())
|
||||
if command == "has_import":
|
||||
if not args:
|
||||
return "error: Missing module name argument"
|
||||
return json.dumps({"can_import": has_import.check_import(args[0])})
|
||||
if command == "health":
|
||||
return "ok"
|
||||
if command == "installed_apps_check":
|
||||
import django
|
||||
from django.conf import settings
|
||||
|
||||
django.setup()
|
||||
if not args:
|
||||
return "error: Missing module name argument"
|
||||
return json.dumps({"has_app": args[0] in settings.INSTALLED_APPS})
|
||||
if command == "python_setup":
|
||||
return json.dumps(python_setup.get_python_info())
|
||||
if command == "version":
|
||||
return "0.1.0"
|
||||
return f"Unknown command: {command}"
|
||||
|
||||
|
||||
def handle_json_command(data: dict[str, Any]) -> dict[str, Any]:
|
||||
command = data["command"]
|
||||
args = data.get("args", []) # Get args if they exist
|
||||
|
@ -84,20 +56,12 @@ def main():
|
|||
if not line:
|
||||
break
|
||||
|
||||
if transport_type == "json":
|
||||
data = json.loads(line)
|
||||
response = handle_json_command(data)
|
||||
print(json.dumps(response), flush=True)
|
||||
else:
|
||||
command = line.strip()
|
||||
response = handle_command(command)
|
||||
print(response, flush=True)
|
||||
data = json.loads(line)
|
||||
response = handle_json_command(data)
|
||||
print(json.dumps(response), flush=True)
|
||||
|
||||
except Exception as e:
|
||||
if transport_type == "json":
|
||||
print(json.dumps({"status": "error", "error": str(e)}), flush=True)
|
||||
else:
|
||||
print(f"error: {str(e)}", flush=True)
|
||||
print(json.dumps({"status": "error", "error": str(e)}), flush=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue