Skip to content

Commit

Permalink
Overhaul LSP Client (#752)
Browse files Browse the repository at this point in the history
* Simplify LSP Client internals
* Streamline control flow between Client, IO, and Buffer classes
* Create canonical, obvious place to implement filters on incoming and outgoing LSP messages
* Remove legacy WS LSP support
  • Loading branch information
DaelonSuzuka authored Nov 18, 2024
1 parent fd637d0 commit 694feea
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 400 deletions.
15 changes: 0 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,21 +296,6 @@
"default": false,
"description": "Whether extra space should be removed from function parameter lists"
},
"godotTools.lsp.serverProtocol": {
"type": [
"string"
],
"enum": [
"ws",
"tcp"
],
"default": "tcp",
"enumDescriptions": [
"Use the WebSocket protocol to connect to Godot 3.2 and Godot 3.2.1",
"Use the TCP protocol to connect to Godot 3.2.2 and newer versions"
],
"description": "The server protocol of the GDScript language server.\nYou must restart VSCode after changing this value."
},
"godotTools.lsp.serverHost": {
"type": "string",
"default": "127.0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function copy_resource_path(uri: vscode.Uri) {
}

async function list_classes() {
await globals.lsp.client.list_classes();
await globals.docsProvider.list_native_classes();
}

async function switch_scene_script() {
Expand Down
23 changes: 11 additions & 12 deletions src/lsp/ClientConnectionManager.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import * as vscode from "vscode";
import GDScriptLanguageClient, { ClientStatus, TargetLSP } from "./GDScriptLanguageClient";

import {
createLogger,
get_configuration,
get_free_port,
get_project_dir,
get_project_version,
set_context,
register_command,
set_configuration,
createLogger,
set_context,
verify_godot_version,
} from "../utils";
import { prompt_for_godot_executable, prompt_for_reload, select_godot_executable } from "../utils/prompts";
import { subProcess, killSubProcesses } from "../utils/subspawn";
import { killSubProcesses, subProcess } from "../utils/subspawn";
import GDScriptLanguageClient, { ClientStatus, TargetLSP } from "./GDScriptLanguageClient";

const log = createLogger("lsp.manager", { output: "Godot LSP" });

Expand All @@ -38,10 +39,8 @@ export class ClientConnectionManager {
private connectedVersion = "";

constructor(private context: vscode.ExtensionContext) {
this.context = context;

this.client = new GDScriptLanguageClient(context);
this.client.watch_status(this.on_client_status_changed.bind(this));
this.client = new GDScriptLanguageClient();
this.client.events.on("status", this.on_client_status_changed.bind(this));

setInterval(() => {
this.retry_callback();
Expand All @@ -60,7 +59,7 @@ export class ClientConnectionManager {
this.start_language_server();
this.reconnectionAttempts = 0;
this.target = TargetLSP.HEADLESS;
this.client.connect_to_server(this.target);
this.client.connect(this.target);
}),
register_command("stopLanguageServer", this.stop_language_server.bind(this)),
register_command("checkStatus", this.on_status_item_click.bind(this)),
Expand All @@ -81,7 +80,7 @@ export class ClientConnectionManager {
}

this.reconnectionAttempts = 0;
this.client.connect_to_server(this.target);
this.client.connect(this.target);
}

private stop_language_server() {
Expand Down Expand Up @@ -269,7 +268,7 @@ export class ClientConnectionManager {
this.reconnectionAttempts = 0;
set_context("connectedToLSP", true);
this.status = ManagerStatus.CONNECTED;
if (!this.client.started) {
if (this.client.needsStart()) {
this.context.subscriptions.push(this.client.start());
}
break;
Expand Down Expand Up @@ -305,7 +304,7 @@ export class ClientConnectionManager {
const maxAttempts = get_configuration("lsp.autoReconnect.attempts");
if (autoRetry && this.reconnectionAttempts <= maxAttempts - 1) {
this.reconnectionAttempts++;
this.client.connect_to_server(this.target);
this.client.connect(this.target);
this.retry = true;
return;
}
Expand Down
Loading

0 comments on commit 694feea

Please sign in to comment.