Skip to content

Commit

Permalink
upgrade vscode-languageserver (#2557)
Browse files Browse the repository at this point in the history
* upgrades the `vscode-languageserver` and `vscode-jsonrpc` reference implementations under the hood.
also upgrades `vscode-languageclient` to match. 
* works in `vscode-graphql` and `nvim.coc`, as well as other LSP clients hopefully
* fix cli stderr bug
  • Loading branch information
acao authored Jul 10, 2022
1 parent eb1db96 commit 3304606
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 101 deletions.
9 changes: 9 additions & 0 deletions .changeset/chatty-insects-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'graphql-language-service-server': minor
'graphql-language-service-cli': minor
'vscode-graphql': minor
---

upgrades the `vscode-languageserver` and `vscode-jsonrpc` reference implementations for the lsp server to the latest. also upgrades `vscode-languageclient` in `vscode-graphql` to the latest 8.0.1. seems to work fine for IPC in `vscode-graphql` at least!

hopefully this solves #2230 once and for all!
5 changes: 3 additions & 2 deletions packages/graphql-language-service-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ if (!command) {
switch (command) {
case 'server':
process.on('uncaughtException', error => {
process.stdout.write(
process.stderr.write(
'An error was thrown from GraphQL language service: ' + String(error),
);
process.exit(0);
// don't exit at all if there is an uncaughtException
// process.exit(0);
});

const options: { [key: string]: any } = {};
Expand Down
9 changes: 3 additions & 6 deletions packages/graphql-language-service-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@
"mkdirp": "^1.0.4",
"node-fetch": "^2.6.1",
"nullthrows": "^1.0.0",
"vscode-jsonrpc": "^5.0.1",
"vscode-languageserver": "^6.1.1",
"vscode-languageserver-protocol": "~3.15.3",
"vscode-languageserver-types": "~3.15.1",
"vscode-languageserver": "^8.0.1",
"vscode-jsonrpc": "^8.0.1",
"fast-glob": "^3.2.7",
"vscode-uri": "^3.0.2",
"glob": "^7.2.0",
Expand All @@ -54,7 +52,6 @@
"devDependencies": {
"@types/mkdirp": "^1.0.1",
"cross-env": "^7.0.2",
"graphql": "^16.4.0",
"vscode-languageserver-types": "^3.15.1"
"graphql": "^16.4.0"
}
}
14 changes: 7 additions & 7 deletions packages/graphql-language-service-server/src/MessageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type {
DidSaveTextDocumentParams,
DidOpenTextDocumentParams,
DidChangeConfigurationParams,
} from 'vscode-languageserver-protocol';
} from 'vscode-languageserver/node';

import type {
Diagnostic,
Expand All @@ -53,9 +53,9 @@ import type {
DocumentSymbolParams,
SymbolInformation,
WorkspaceSymbolParams,
IConnection,
Connection,
DidChangeConfigurationRegistrationOptions,
} from 'vscode-languageserver';
} from 'vscode-languageserver/node';

import type { UnnormalizedTypeDefPointer } from '@graphql-tools/load';

Expand Down Expand Up @@ -90,7 +90,7 @@ function toPosition(position: VscodePosition): IPosition {
}

export class MessageProcessor {
_connection: IConnection;
_connection: Connection;
_graphQLCache!: GraphQLCache;
_graphQLConfig: GraphQLConfig | undefined;
_languageService!: GraphQLLanguageService;
Expand Down Expand Up @@ -126,7 +126,7 @@ export class MessageProcessor {
config?: GraphQLConfig;
parser?: typeof parseDocument;
tmpDir?: string;
connection: IConnection;
connection: Connection;
}) {
this._connection = connection;
this._textDocumentCache = new Map();
Expand Down Expand Up @@ -154,10 +154,10 @@ export class MessageProcessor {
mkdirp(this._tmpDirBase);
}
}
get connection(): IConnection {
get connection(): Connection {
return this._connection;
}
set connection(connection: IConnection) {
set connection(connection: Connection) {
this._connection = connection;
}

Expand Down
12 changes: 6 additions & 6 deletions packages/graphql-language-service-server/src/startServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
SocketMessageWriter,
StreamMessageReader,
StreamMessageWriter,
} from 'vscode-jsonrpc';
} from 'vscode-jsonrpc/node';

import {
CompletionRequest,
Expand All @@ -37,8 +37,8 @@ import {
PublishDiagnosticsParams,
WorkspaceSymbolRequest,
createConnection,
IConnection,
} from 'vscode-languageserver';
Connection,
} from 'vscode-languageserver/node';

import { Logger } from './Logger';
import {
Expand Down Expand Up @@ -228,7 +228,7 @@ async function initializeHandlers({
writer,
logger,
options,
}: InitializerParams): Promise<IConnection> {
}: InitializerParams): Promise<Connection> {
try {
const connection = createConnection(reader, writer);

Expand All @@ -243,7 +243,7 @@ async function initializeHandlers({

function reportDiagnostics(
diagnostics: PublishDiagnosticsParams | null,
connection: IConnection,
connection: Connection,
) {
if (diagnostics) {
connection.sendNotification(
Expand All @@ -254,7 +254,7 @@ function reportDiagnostics(
}

type HandlerOptions = {
connection: IConnection;
connection: Connection;
logger: Logger;
config?: GraphQLConfig;
parser?: typeof parseDocument;
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-language-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"graphql": "^15.5.0 || ^16.0.0"
},
"dependencies": {
"vscode-languageserver-types": "^3.15.1",
"vscode-languageserver-types": "^3.17.1",
"nullthrows": "^1.0.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,8 @@ describe('getAutocompleteSuggestions', () => {
{ label: 'skip' },
];

console.log({ graphQLVersion });

// TODO: remove this once defer and stream are merged to `graphql`
if (graphQLVersion.startsWith('16.0.0-experimental-stream-defer')) {
console.log('expect stream');
expectedDirectiveSuggestions.push({ label: 'stream' }, { label: 'test' });
} else {
expectedDirectiveSuggestions.push({ label: 'test' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
* LICENSE file in the root directory of this source tree.
*
*/
import {
CompletionItemKind,
InsertTextFormat,
} from 'vscode-languageserver-types';

import {
FragmentDefinitionNode,
Expand All @@ -31,7 +27,13 @@ import {
isNonNullType,
} from 'graphql';

import { CompletionItem, AllTypeInfo, IPosition } from '../types';
import {
CompletionItem,
AllTypeInfo,
IPosition,
CompletionItemKind,
InsertTextFormat,
} from '../types';

import {
GraphQLBoolean,
Expand Down
2 changes: 2 additions & 0 deletions packages/graphql-language-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type {
CompletionItem as CompletionItemType,
} from 'vscode-languageserver-types';

export { InsertTextFormat } from 'vscode-languageserver-types';

import type { ASTNode, GraphQLSchema } from 'graphql';

import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/monaco-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"devDependencies": {
"graphql": "^16.4.0",
"monaco-editor": "^0.31.0",
"vscode-languageserver-types": "^3.15.1"
"vscode-languageserver-types": "^3.17.1"
},
"peerDependencies": {
"graphql": "^15.5.0 || ^16.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@
"vsce": "^2.7.0"
},
"dependencies": {
"graphql": "16.0.0-experimental-stream-defer.5",
"graphql": "^16.4.0",
"graphql-language-service-server": "^2.7.29",
"vscode-languageclient": "5.2.1"
"vscode-languageclient": "^8.0.1"
}
}
3 changes: 2 additions & 1 deletion packages/vscode-graphql/src/apis/statusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
ThemeColor,
version,
} from 'vscode';
import { LanguageClient, State } from 'vscode-languageclient';

import { LanguageClient, State } from 'vscode-languageclient/node';

enum Status {
INIT = 1,
Expand Down
36 changes: 17 additions & 19 deletions packages/vscode-graphql/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import {
} from 'vscode';

import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
TransportKind,
RevealOutputChannelOn,
} from 'vscode-languageclient';
LanguageClient,
} from 'vscode-languageclient/node';

import * as path from 'path';
import { createStatusBar, initStatusBar } from './apis/statusBar';

export function activate(context: ExtensionContext) {
let client: LanguageClient;

export async function activate(context: ExtensionContext) {
const outputChannel: OutputChannel = window.createOutputChannel(
'GraphQL Language Server',
);
Expand Down Expand Up @@ -90,16 +92,18 @@ export function activate(context: ExtensionContext) {
},
};

const client = new LanguageClient(
client = new LanguageClient(
'vscode-graphql',
'GraphQL Language Server',
serverOptions,
clientOptions,
debug,
);

let clientLSPDisposable = client.start();
context.subscriptions.push(clientLSPDisposable);
const statusBarItem = createStatusBar();
context.subscriptions.push(statusBarItem);

await client.start();
initStatusBar(statusBarItem, client, window.activeTextEditor);

const commandShowOutputChannel = commands.registerCommand(
'vscode-graphql.showOutputChannel',
Expand All @@ -108,28 +112,22 @@ export function activate(context: ExtensionContext) {

context.subscriptions.push(commandShowOutputChannel);

const statusBarItem = createStatusBar();
context.subscriptions.push(statusBarItem);
client.onReady().then(() => {
initStatusBar(statusBarItem, client, window.activeTextEditor);
});

commands.registerCommand('vscode-graphql.restart', async () => {
outputChannel.appendLine(`Stopping GraphQL LSP`);
await client.stop();

clientLSPDisposable.dispose();

outputChannel.appendLine(`Restarting GraphQL LSP`);
clientLSPDisposable = client.start();
context.subscriptions.push(clientLSPDisposable);

await client.start();
outputChannel.appendLine(`GraphQL LSP restarted`);
});
}

export function deactivate() {
console.log('Extension "vscode-graphql" has been de-activated!!');
if (!client) {
return undefined;
}
console.log('Extension "vscode-graphql" will be de-activated!!');
return client.stop();
}

function getConfig() {
Expand Down
Loading

0 comments on commit 3304606

Please sign in to comment.