Update for languageclient API changes

This commit is contained in:
Laurențiu Nicola 2022-04-08 14:24:28 +03:00
parent d3d6267112
commit bfa2a08da1
2 changed files with 11 additions and 11 deletions

View file

@ -90,9 +90,9 @@ export function createClient(serverPath: string, workspace: Workspace, extraEnv:
const params: lc.CodeActionParams = { const params: lc.CodeActionParams = {
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document), textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document),
range: client.code2ProtocolConverter.asRange(range), range: client.code2ProtocolConverter.asRange(range),
context: client.code2ProtocolConverter.asCodeActionContext(context) context: await client.code2ProtocolConverter.asCodeActionContext(context, token)
}; };
return client.sendRequest(lc.CodeActionRequest.type, params, token).then((values) => { return client.sendRequest(lc.CodeActionRequest.type, params, token).then(async (values) => {
if (values === null) return undefined; if (values === null) return undefined;
const result: (vscode.CodeAction | vscode.Command)[] = []; const result: (vscode.CodeAction | vscode.Command)[] = [];
const groups = new Map<string, { index: number; items: vscode.CodeAction[] }>(); const groups = new Map<string, { index: number; items: vscode.CodeAction[] }>();
@ -100,7 +100,7 @@ export function createClient(serverPath: string, workspace: Workspace, extraEnv:
// In our case we expect to get code edits only from diagnostics // In our case we expect to get code edits only from diagnostics
if (lc.CodeAction.is(item)) { if (lc.CodeAction.is(item)) {
assert(!item.command, "We don't expect to receive commands in CodeActions"); assert(!item.command, "We don't expect to receive commands in CodeActions");
const action = client.protocol2CodeConverter.asCodeAction(item); const action = await client.protocol2CodeConverter.asCodeAction(item, token);
result.push(action); result.push(action);
continue; continue;
} }

View file

@ -127,8 +127,8 @@ export function joinLines(ctx: Ctx): Cmd {
ranges: editor.selections.map((it) => client.code2ProtocolConverter.asRange(it)), ranges: editor.selections.map((it) => client.code2ProtocolConverter.asRange(it)),
textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document), textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
}); });
await editor.edit((builder) => { await editor.edit(async (builder) => {
client.protocol2CodeConverter.asTextEdits(items).forEach((edit: any) => { (await client.protocol2CodeConverter.asTextEdits(items)).forEach((edit: any) => {
builder.replace(edit.range, edit.newText); builder.replace(edit.range, edit.newText);
}); });
}); });
@ -157,7 +157,7 @@ export function moveItem(ctx: Ctx, direction: ra.Direction): Cmd {
if (!lcEdits) return; if (!lcEdits) return;
const edits = client.protocol2CodeConverter.asTextEdits(lcEdits); const edits = await client.protocol2CodeConverter.asTextEdits(lcEdits);
await applySnippetTextEdits(editor, edits); await applySnippetTextEdits(editor, edits);
}; };
} }
@ -180,7 +180,7 @@ export function onEnter(ctx: Ctx): Cmd {
}); });
if (!lcEdits) return false; if (!lcEdits) return false;
const edits = client.protocol2CodeConverter.asTextEdits(lcEdits); const edits = await client.protocol2CodeConverter.asTextEdits(lcEdits);
await applySnippetTextEdits(editor, edits); await applySnippetTextEdits(editor, edits);
return true; return true;
} }
@ -277,12 +277,12 @@ export function ssr(ctx: Ctx): Cmd {
location: vscode.ProgressLocation.Notification, location: vscode.ProgressLocation.Notification,
title: "Structured search replace in progress...", title: "Structured search replace in progress...",
cancellable: false, cancellable: false,
}, async (_progress, _token) => { }, async (_progress, token) => {
const edit = await client.sendRequest(ra.ssr, { const edit = await client.sendRequest(ra.ssr, {
query: request, parseOnly: false, textDocument, position, selections, query: request, parseOnly: false, textDocument, position, selections,
}); });
await vscode.workspace.applyEdit(client.protocol2CodeConverter.asWorkspaceEdit(edit)); await vscode.workspace.applyEdit(await client.protocol2CodeConverter.asWorkspaceEdit(edit, token));
}); });
}; };
} }
@ -728,11 +728,11 @@ export function resolveCodeAction(ctx: Ctx): Cmd {
return; return;
} }
const itemEdit = item.edit; const itemEdit = item.edit;
const edit = client.protocol2CodeConverter.asWorkspaceEdit(itemEdit); const edit = await client.protocol2CodeConverter.asWorkspaceEdit(itemEdit);
// filter out all text edits and recreate the WorkspaceEdit without them so we can apply // filter out all text edits and recreate the WorkspaceEdit without them so we can apply
// snippet edits on our own // snippet edits on our own
const lcFileSystemEdit = { ...itemEdit, documentChanges: itemEdit.documentChanges?.filter(change => "kind" in change) }; const lcFileSystemEdit = { ...itemEdit, documentChanges: itemEdit.documentChanges?.filter(change => "kind" in change) };
const fileSystemEdit = client.protocol2CodeConverter.asWorkspaceEdit(lcFileSystemEdit); const fileSystemEdit = await client.protocol2CodeConverter.asWorkspaceEdit(lcFileSystemEdit);
await vscode.workspace.applyEdit(fileSystemEdit); await vscode.workspace.applyEdit(fileSystemEdit);
await applySnippetWorkspaceEdit(edit); await applySnippetWorkspaceEdit(edit);
}; };