Skip to content

Commit

Permalink
Configurable LSP transport (#3819)
Browse files Browse the repository at this point in the history
* Configurable LSP transport

* Add changeset (minor)

* Fix typo in IPC transport
  • Loading branch information
robertoaloi authored Jan 11, 2025
1 parent 869a8c0 commit 5665872
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-ties-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vscode-graphql': minor
---

Make LSP transport configurable (ipc, stdio)
6 changes: 5 additions & 1 deletion packages/vscode-graphql/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ const logger = console;
const isWatchMode = arg === '--watch';

build({
entryPoints: ['src/extension.ts', 'src/server/index.ts'],
entryPoints: [
'src/extension.ts',
'src/serverIpc/index.ts',
'src/serverStdio/index.ts',
],
bundle: true,
minify: arg === '--minify',
platform: 'node',
Expand Down
9 changes: 9 additions & 0 deletions packages/vscode-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@
"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).",
"default": 30000
},
"vscode-graphql.transport": {
"type": "string",
"enum": [
"ipc",
"stdio"
],
"description": "The transport used between the language server and the client.",
"default": "ipc"
},
"graphql-config.load.rootDir": {
"type": [
"string"
Expand Down
34 changes: 27 additions & 7 deletions packages/vscode-graphql/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,47 @@ export async function activate(context: ExtensionContext) {
);

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

const serverPath = path.join('out', 'server', 'index.js');
const serverModule = context.asAbsolutePath(serverPath);

const debugOptions = {
execArgv: ['--nolazy', '--inspect=localhost:6009'],
};

let transportKind;
let server;
switch (transport) {
case 'ipc':
transportKind = TransportKind.ipc;
server = 'serverIpc';
break;
case 'stdio':
transportKind = TransportKind.stdio;
server = 'serverStdio';
break;
default:
if (debug) {
// eslint-disable-next-line no-console
console.log('Transport not recognized. Defaulting to IPC!');
}
transportKind = TransportKind.ipc;
server = 'serverIpc';
break;
}
const serverPath = path.join('out', server, 'index.js');
const serverModule = context.asAbsolutePath(serverPath);

const serverOptions: ServerOptions = {
run: {
module: serverModule,
transport: TransportKind.ipc,
transport: transportKind,
},
debug: {
module: serverModule,
transport: TransportKind.ipc,
transport: transportKind,
options: { ...(debug ? debugOptions : {}) },
},
};
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions packages/vscode-graphql/src/serverStdio/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// this lives in the same monorepo! most errors you see in
// vscode that aren't highlighting or bracket completion
// related are coming from our LSP server
import { startServer } from 'graphql-language-service-server';

// The npm scripts are configured to only build this once before
// watching the extension, so please restart the extension debugger for changes!

async function start() {
try {
await startServer({ method: 'stream' });
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
}
}

void start();

0 comments on commit 5665872

Please sign in to comment.