Skip to content
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

Configurable LSP transport #3819

Merged
merged 3 commits into from
Jan 11, 2025
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
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
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();
Loading