Skip to content

Commit

Permalink
Random port LSP is working
Browse files Browse the repository at this point in the history
  • Loading branch information
DaelonSuzuka committed Sep 21, 2023
1 parent dfc8de1 commit ddfef95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/lsp/ClientConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ export class ClientConnectionManager {
public client: GDScriptLanguageClient = null;

private reconnection_attempts = 0;
private port: number = null;

private connection_status: vscode.StatusBarItem = null;


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

Expand Down Expand Up @@ -47,8 +45,9 @@ export class ClientConnectionManager {
}

private connect_to_language_server() {
const start = get_configuration("lsp.runAtStartup", false)
this.client.port = -1;

const start = get_configuration("lsp.runAtStartup", false)
if (start) {
this.start_language_server();
}
Expand Down Expand Up @@ -81,7 +80,7 @@ export class ClientConnectionManager {
headlessFlag = "--headless";
}

this.port = await get_free_port();
this.client.port = await get_free_port();

// TODO: find a better way to manage child processes
// This way works, but it creates a terminal that the user might
Expand All @@ -91,7 +90,7 @@ export class ClientConnectionManager {

this.stop_language_server();

const command = `${editorPath} --path "${projectDir}" --editor ${headlessFlag} --lsp-port ${this.port}`;
const command = `${editorPath} --path "${projectDir}" --editor ${headlessFlag} --lsp-port ${this.client.port}`;
const terminal = vscode.window.createTerminal(`${TOOL_NAME}LSP`);
terminal.sendText(command, true);
});
Expand Down
7 changes: 6 additions & 1 deletion src/lsp/GDScriptLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default class GDScriptLanguageClient extends LanguageClient {
private _initialize_request: Message = null;
private message_handler: MessageHandler = null;
private native_doc_manager: NativeDocumentManager = null;

public port: number = -1;

public get started() : boolean { return this._started; }
public get status() : ClientStatus { return this._status; }
Expand Down Expand Up @@ -78,8 +80,11 @@ export default class GDScriptLanguageClient extends LanguageClient {

connect_to_server() {
this.status = ClientStatus.PENDING;
let host = get_configuration("lsp.serverHost", "127.0.0.1");
const host = get_configuration("lsp.serverHost", "127.0.0.1");
let port = get_configuration("lsp.serverPort", 6008);
if (this.port !== -1) {
port = this.port;
}
this.io.connect_to_language_server(host, port);
}

Expand Down

0 comments on commit ddfef95

Please sign in to comment.