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

[Code] fix lang-sever initializing popover #33482

Merged
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
19 changes: 3 additions & 16 deletions x-pack/plugins/code/server/lsp/request_expander.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import fs from 'fs';
import mkdirp from 'mkdirp';
import rimraf from 'rimraf';
import sinon from 'sinon';
import { ServerNotInitialized } from '../../common/lsp_error_codes';
import { ServerOptions } from '../server_options';
import { LanguageServerProxy } from './proxy';
import { RequestExpander } from './request_expander';
import { InitializingError, RequestExpander } from './request_expander';

// @ts-ignore
const options: ServerOptions = {
Expand Down Expand Up @@ -90,20 +89,8 @@ test('requests should throw error after lsp init timeout', async () => {
mkdirp.sync(request1.workspacePath);
const response1Promise = expander.handleRequest(request1);
const response2Promise = expander.handleRequest(request2);
await expect(response1Promise).rejects.toEqual({
id: -1,
error: {
code: ServerNotInitialized,
message: 'Server is initializing',
},
});
await expect(response2Promise).rejects.toEqual({
id: -1,
error: {
code: ServerNotInitialized,
message: 'Server is initializing',
},
});
await expect(response1Promise).rejects.toEqual(InitializingError);
await expect(response2Promise).rejects.toEqual(InitializingError);
});

test('be able to open multiple workspace', async () => {
Expand Down
10 changes: 2 additions & 8 deletions x-pack/plugins/code/server/lsp/request_expander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import fs from 'fs';
import path from 'path';
import { ResponseMessage } from 'vscode-jsonrpc/lib/messages';
import { ResponseError, ResponseMessage } from 'vscode-jsonrpc/lib/messages';
import { DidChangeWorkspaceFoldersParams, InitializeResult } from 'vscode-languageserver-protocol';
import { ServerNotInitialized } from '../../common/lsp_error_codes';
import { LspRequest } from '../../model';
Expand All @@ -33,13 +33,7 @@ interface Workspace {
initPromise?: Promise<any>;
}

const InitializingError = {
id: -1,
error: {
code: ServerNotInitialized,
message: 'Server is initializing',
},
};
export const InitializingError = new ResponseError(ServerNotInitialized, 'Server is initializing');

export class RequestExpander implements ILanguageServerHandler {
public lastAccess: number = 0;
Expand Down
14 changes: 7 additions & 7 deletions x-pack/plugins/code/server/routes/lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function lspRoute(
lspService: LspService,
serverOptions: ServerOptions
) {
const log = new Logger(server);
server.route({
path: '/api/lsp/textDocument/{method}',
async handler(req, h: hapi.ResponseToolkit) {
Expand All @@ -51,18 +52,18 @@ export function lspRoute(
if (error instanceof ResponseError) {
// hide some errors;
if (error.code !== UnknownFileLanguage) {
const log = new Logger(server);
log.error(error);
log.info(error);
}
return h
.response({ code: error.code, msg: LANG_SERVER_ERROR })
.response({ error: { code: error.code, msg: LANG_SERVER_ERROR } })
.type('json')
.code(503); // different code for LS errors and other internal errors.
} else if (error.isBoom) {
return error;
} else {
log.error(error);
return h
.response('language server error')
.response({ error: { code: error.code || 500, msg: LANG_SERVER_ERROR } })
.type('json')
.code(500);
}
Expand Down Expand Up @@ -150,18 +151,17 @@ export function lspRoute(
}
return { title, files: groupBy(files, 'repo'), uri, position };
} catch (error) {
const log = new Logger(server);
log.error(error);
if (error instanceof ResponseError) {
return h
.response({ code: error.code, msg: LANG_SERVER_ERROR })
.response({ error: { code: error.code, msg: LANG_SERVER_ERROR } })
.type('json')
.code(503); // different code for LS errors and other internal errors.
} else if (error.isBoom) {
return error;
} else {
return h
.response(LANG_SERVER_ERROR)
.response({ error: { code: 500, msg: LANG_SERVER_ERROR } })
.type('json')
.code(500);
}
Expand Down