adjusts on client-server connection (LSP)
This commit is contained in:
parent
85a224fc7b
commit
0ac7d9e732
@ -7,7 +7,7 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
public class LspServerConfiguration {
|
public class LspServerConfiguration {
|
||||||
public static final String DEFAULT_HOST = "127.0.0.1";
|
public static final String DEFAULT_HOST = "127.0.0.1";
|
||||||
public static final int DEFAULT_PORT = 7777;
|
public static final int DEFAULT_PORT = 7775;
|
||||||
|
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private final LspServerEndpoint endpoint = new LspServerEndpoint(DEFAULT_HOST, DEFAULT_PORT);
|
private final LspServerEndpoint endpoint = new LspServerEndpoint(DEFAULT_HOST, DEFAULT_PORT);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -7,7 +7,7 @@ This extension does **not** start the language server itself. It connects to the
|
|||||||
```text
|
```text
|
||||||
VS Code Extension
|
VS Code Extension
|
||||||
-> vscode-languageclient
|
-> vscode-languageclient
|
||||||
-> TCP 127.0.0.1:7777
|
-> TCP 127.0.0.1:7775
|
||||||
-> Prometeu Studio Java/LSP4J
|
-> Prometeu Studio Java/LSP4J
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ VS Code Extension
|
|||||||
The Studio LSP server must be listening on:
|
The Studio LSP server must be listening on:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
127.0.0.1:7777
|
127.0.0.1:7775
|
||||||
```
|
```
|
||||||
|
|
||||||
## Install dependencies
|
## Install dependencies
|
||||||
@ -80,7 +80,7 @@ View -> Output -> Prometeu LSP
|
|||||||
|
|
||||||
```text
|
```text
|
||||||
Prometeu VS Code extension activated.
|
Prometeu VS Code extension activated.
|
||||||
Connecting to Prometeu Studio LSP at 127.0.0.1:7777...
|
Connecting to Prometeu Studio LSP at 127.0.0.1:7775...
|
||||||
TCP connection established with Prometeu Studio.
|
TCP connection established with Prometeu Studio.
|
||||||
Prometeu Studio LSP client started.
|
Prometeu Studio LSP client started.
|
||||||
[Info] Hello from Prometeu Studio LSP
|
[Info] Hello from Prometeu Studio LSP
|
||||||
@ -136,7 +136,7 @@ Default settings:
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"prometeu.studio.host": "127.0.0.1",
|
"prometeu.studio.host": "127.0.0.1",
|
||||||
"prometeu.studio.port": 7777
|
"prometeu.studio.port": 7775
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -48,7 +48,7 @@
|
|||||||
},
|
},
|
||||||
"prometeu.studio.port": {
|
"prometeu.studio.port": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": 7777,
|
"default": 7775,
|
||||||
"description": "Prometeu Studio LSP TCP port."
|
"description": "Prometeu Studio LSP TCP port."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,4 +66,4 @@
|
|||||||
"@types/vscode": "^1.90.0",
|
"@types/vscode": "^1.90.0",
|
||||||
"typescript": "^5.0.0"
|
"typescript": "^5.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,16 +2,25 @@ import * as net from "node:net";
|
|||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
CloseAction,
|
||||||
|
ErrorAction,
|
||||||
LanguageClient,
|
LanguageClient,
|
||||||
LanguageClientOptions,
|
LanguageClientOptions,
|
||||||
ServerOptions,
|
ServerOptions,
|
||||||
|
State,
|
||||||
StreamInfo
|
StreamInfo
|
||||||
} from "vscode-languageclient/node";
|
} from "vscode-languageclient/node";
|
||||||
|
|
||||||
let client: LanguageClient | undefined;
|
let client: LanguageClient | undefined;
|
||||||
let output: vscode.OutputChannel;
|
let output: vscode.OutputChannel;
|
||||||
|
let reconnectTimer: NodeJS.Timeout | undefined;
|
||||||
|
let reconnectContext: vscode.ExtensionContext | undefined;
|
||||||
|
let stoppingClient = false;
|
||||||
|
|
||||||
|
const RECONNECT_DELAY_MS = 2000;
|
||||||
|
|
||||||
export function activate(context: vscode.ExtensionContext): void {
|
export function activate(context: vscode.ExtensionContext): void {
|
||||||
|
reconnectContext = context;
|
||||||
output = vscode.window.createOutputChannel("Prometeu LSP");
|
output = vscode.window.createOutputChannel("Prometeu LSP");
|
||||||
output.appendLine("Prometeu VS Code extension activated.");
|
output.appendLine("Prometeu VS Code extension activated.");
|
||||||
|
|
||||||
@ -40,6 +49,8 @@ export async function deactivate(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function startClient(context: vscode.ExtensionContext): Promise<void> {
|
async function startClient(context: vscode.ExtensionContext): Promise<void> {
|
||||||
|
clearReconnectTimer();
|
||||||
|
|
||||||
if (client) {
|
if (client) {
|
||||||
output.appendLine("Prometeu LSP client is already running.");
|
output.appendLine("Prometeu LSP client is already running.");
|
||||||
return;
|
return;
|
||||||
@ -48,7 +59,7 @@ async function startClient(context: vscode.ExtensionContext): Promise<void> {
|
|||||||
const config = vscode.workspace.getConfiguration("prometeu.studio");
|
const config = vscode.workspace.getConfiguration("prometeu.studio");
|
||||||
|
|
||||||
const host = config.get<string>("host", "127.0.0.1");
|
const host = config.get<string>("host", "127.0.0.1");
|
||||||
const port = config.get<number>("port", 7777);
|
const port = config.get<number>("port", 7775);
|
||||||
|
|
||||||
output.show(true);
|
output.show(true);
|
||||||
output.appendLine(`Connecting to Prometeu Studio LSP at ${host}:${port}...`);
|
output.appendLine(`Connecting to Prometeu Studio LSP at ${host}:${port}...`);
|
||||||
@ -114,38 +125,66 @@ async function startClient(context: vscode.ExtensionContext): Promise<void> {
|
|||||||
clientKind: "vscode",
|
clientKind: "vscode",
|
||||||
prometeuClientVersion: context.extension.packageJSON.version
|
prometeuClientVersion: context.extension.packageJSON.version
|
||||||
},
|
},
|
||||||
outputChannel: output
|
outputChannel: output,
|
||||||
|
errorHandler: {
|
||||||
|
error: (error) => {
|
||||||
|
output.appendLine(`Prometeu LSP transport error: ${error.message}`);
|
||||||
|
return { action: ErrorAction.Continue };
|
||||||
|
},
|
||||||
|
closed: () => {
|
||||||
|
output.appendLine("Prometeu LSP transport closed.");
|
||||||
|
return { action: CloseAction.DoNotRestart };
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
client = new LanguageClient(
|
const nextClient = new LanguageClient(
|
||||||
"prometeuStudioLsp",
|
"prometeuStudioLsp",
|
||||||
"Prometeu Studio LSP",
|
"Prometeu Studio LSP",
|
||||||
serverOptions,
|
serverOptions,
|
||||||
clientOptions
|
clientOptions
|
||||||
);
|
);
|
||||||
|
client = nextClient;
|
||||||
|
nextClient.onDidChangeState((event) => {
|
||||||
|
output.appendLine(`Prometeu LSP state changed: ${State[event.oldState]} -> ${State[event.newState]}`);
|
||||||
|
if (event.newState !== State.Stopped) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (client === nextClient) {
|
||||||
|
client = undefined;
|
||||||
|
}
|
||||||
|
if (!stoppingClient) {
|
||||||
|
scheduleReconnect();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.start();
|
await nextClient.start();
|
||||||
|
|
||||||
output.appendLine("Prometeu Studio LSP client started.");
|
output.appendLine("Prometeu Studio LSP client started.");
|
||||||
vscode.window.showInformationMessage("Connected to Prometeu Studio LSP.");
|
vscode.window.showInformationMessage("Connected to Prometeu Studio LSP.");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
client = undefined;
|
if (client === nextClient) {
|
||||||
|
client = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
|
|
||||||
output.appendLine(`Failed to start Prometeu LSP client: ${message}`);
|
output.appendLine(`Failed to start Prometeu LSP client: ${message}`);
|
||||||
vscode.window.showErrorMessage(`Could not connect to Prometeu Studio LSP: ${message}`);
|
vscode.window.showErrorMessage(`Could not connect to Prometeu Studio LSP: ${message}`);
|
||||||
|
scheduleReconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function stopClient(): Promise<void> {
|
async function stopClient(): Promise<void> {
|
||||||
|
clearReconnectTimer();
|
||||||
if (!client) {
|
if (!client) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentClient = client;
|
const currentClient = client;
|
||||||
client = undefined;
|
client = undefined;
|
||||||
|
stoppingClient = true;
|
||||||
|
|
||||||
output.appendLine("Stopping Prometeu Studio LSP client...");
|
output.appendLine("Stopping Prometeu Studio LSP client...");
|
||||||
|
|
||||||
@ -155,5 +194,29 @@ async function stopClient(): Promise<void> {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
output.appendLine(`Failed to stop Prometeu LSP client cleanly: ${message}`);
|
output.appendLine(`Failed to stop Prometeu LSP client cleanly: ${message}`);
|
||||||
|
} finally {
|
||||||
|
stoppingClient = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function scheduleReconnect(): void {
|
||||||
|
if (!reconnectContext) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (reconnectTimer || client) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
output.appendLine(`Scheduling Prometeu LSP reconnect in ${RECONNECT_DELAY_MS}ms...`);
|
||||||
|
reconnectTimer = setTimeout(() => {
|
||||||
|
reconnectTimer = undefined;
|
||||||
|
void startClient(reconnectContext!);
|
||||||
|
}, RECONNECT_DELAY_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearReconnectTimer(): void {
|
||||||
|
if (!reconnectTimer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clearTimeout(reconnectTimer);
|
||||||
|
reconnectTimer = undefined;
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user