Skip to content

Commit 5665872

Browse files
authored
Configurable LSP transport (#3819)
* Configurable LSP transport * Add changeset (minor) * Fix typo in IPC transport
1 parent 869a8c0 commit 5665872

File tree

6 files changed

+64
-8
lines changed

6 files changed

+64
-8
lines changed

.changeset/silent-ties-trade.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'vscode-graphql': minor
3+
---
4+
5+
Make LSP transport configurable (ipc, stdio)

packages/vscode-graphql/esbuild.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ const logger = console;
66
const isWatchMode = arg === '--watch';
77

88
build({
9-
entryPoints: ['src/extension.ts', 'src/server/index.ts'],
9+
entryPoints: [
10+
'src/extension.ts',
11+
'src/serverIpc/index.ts',
12+
'src/serverStdio/index.ts',
13+
],
1014
bundle: true,
1115
minify: arg === '--minify',
1216
platform: 'node',

packages/vscode-graphql/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@
114114
"description": "Schema cache ttl in milliseconds - the interval before requesting a fresh schema when caching the local schema file is enabled. Defaults to 30000 (30 seconds).",
115115
"default": 30000
116116
},
117+
"vscode-graphql.transport": {
118+
"type": "string",
119+
"enum": [
120+
"ipc",
121+
"stdio"
122+
],
123+
"description": "The transport used between the language server and the client.",
124+
"default": "ipc"
125+
},
117126
"graphql-config.load.rootDir": {
118127
"type": [
119128
"string"

packages/vscode-graphql/src/extension.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,47 @@ export async function activate(context: ExtensionContext) {
2525
);
2626

2727
const config = getConfig();
28-
const { debug } = config;
28+
const { debug, transport } = config;
2929
if (debug) {
3030
// eslint-disable-next-line no-console
31-
console.log('Extension "vscode-graphql" is now active!');
31+
console.log(`Extension "vscode-graphql" is now activating (${transport})!`);
3232
}
3333

34-
const serverPath = path.join('out', 'server', 'index.js');
35-
const serverModule = context.asAbsolutePath(serverPath);
36-
3734
const debugOptions = {
3835
execArgv: ['--nolazy', '--inspect=localhost:6009'],
3936
};
4037

38+
let transportKind;
39+
let server;
40+
switch (transport) {
41+
case 'ipc':
42+
transportKind = TransportKind.ipc;
43+
server = 'serverIpc';
44+
break;
45+
case 'stdio':
46+
transportKind = TransportKind.stdio;
47+
server = 'serverStdio';
48+
break;
49+
default:
50+
if (debug) {
51+
// eslint-disable-next-line no-console
52+
console.log('Transport not recognized. Defaulting to IPC!');
53+
}
54+
transportKind = TransportKind.ipc;
55+
server = 'serverIpc';
56+
break;
57+
}
58+
const serverPath = path.join('out', server, 'index.js');
59+
const serverModule = context.asAbsolutePath(serverPath);
60+
4161
const serverOptions: ServerOptions = {
4262
run: {
4363
module: serverModule,
44-
transport: TransportKind.ipc,
64+
transport: transportKind,
4565
},
4666
debug: {
4767
module: serverModule,
48-
transport: TransportKind.ipc,
68+
transport: transportKind,
4969
options: { ...(debug ? debugOptions : {}) },
5070
},
5171
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// this lives in the same monorepo! most errors you see in
2+
// vscode that aren't highlighting or bracket completion
3+
// related are coming from our LSP server
4+
import { startServer } from 'graphql-language-service-server';
5+
6+
// The npm scripts are configured to only build this once before
7+
// watching the extension, so please restart the extension debugger for changes!
8+
9+
async function start() {
10+
try {
11+
await startServer({ method: 'stream' });
12+
} catch (err) {
13+
// eslint-disable-next-line no-console
14+
console.error(err);
15+
}
16+
}
17+
18+
void start();

0 commit comments

Comments
 (0)