Skip to content

Socket connection added to vscodeclient. #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@
"type": "object",
"default": {},
"description": "Specifies the underlying Phpactor configuration."
},
"phpactor.remote.enabled":{
"type":"boolean",
"default":false,
"description": "Connect to language server via socket instead stdio"
},
"phpactor.remote.host":{
"type":"string",
"default":"127.0.0.1",
"description": "Host that language server is running"
},
"phpactor.remote.port":{
"type":"integer",
"default":9090,
"description": "Port that language server is running"
},
"phpactor.launchServerArgs":{
"type":"array",
"default":[],
"description": "Arguments passeds to language server. Only applies if language server is running in stdio mode"
}
}
}
Expand Down
62 changes: 48 additions & 14 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import {
LanguageClient,
ServerOptions,
LanguageClientOptions,
StreamInfo,
} from "vscode-languageclient";

import * as vscode from "vscode";
import { spawn } from "child_process";
import { existsSync, mkdir, mkdirSync } from "fs";
import { basename, dirname } from "path";
import * as net from 'net';

const LanguageID = 'php';

Expand Down Expand Up @@ -35,21 +37,53 @@ export function deactivate() {
return languageClient.stop();
}

function getServerOptions(config): ServerOptions
{
let serverOptions;
if(!config.remote.enabled)
{
// launch language server via stdio
serverOptions = {
run: {
command: config.path,
args: [
"language-server",
...config.launchServerArgs
]
},
debug: {
command: "phpactor",
args: [
"language-server",
...config.launchServerArgs
]
},
};
}
else{
// credits: https://github.com/itemis/xtext-languageserver-example/blob/master/vscode-extension/src/extension.ts
// launch language server via socket
serverOptions = () => {
let {host,port} = config.remote;
let socket = net.connect({
host,
port
});

let result = <StreamInfo>{
writer:socket,
reader:socket
};

return Promise.resolve(result);
}
}

return serverOptions;
}

function createClient(config: any): LanguageClient {
let serverOptions: ServerOptions = {
run: {
command: config.path,
args: [
"language-server"
]
},
debug: {
command: "phpactor",
args: [
"language-server"
]
},
};
let serverOptions = getServerOptions(config);

let clientOptions: LanguageClientOptions = {
documentSelector: [
Expand Down