WIP: alternate autocomplete flow for LSP tests

This commit is contained in:
Radon Rosborough 2020-08-22 19:49:52 -06:00
parent 5610772c15
commit 157bd83a33
1 changed files with 31 additions and 5 deletions

View File

@ -242,16 +242,19 @@ class Test {
} }
}; };
testLsp = async () => { testLsp = async () => {
const insertedCode = this.config.lsp!.code!; const code = this.config.lsp!.code!;
const after = this.config.lsp!.after; const after = this.config.lsp!.after;
const item = this.config.lsp!.item!; const item = this.config.lsp!.item!;
const idx = after const idx = after
? this.config.template.indexOf(after) + after.length ? this.config.template.indexOf(after) + after.length
: this.config.template.length; : this.config.template.length;
const code = const pos = findPosition(this.config.template, idx);
const newCode =
this.config.template.slice(0, idx) + this.config.template.slice(0, idx) +
insertedCode + code +
this.config.template.slice(idx); this.config.template.slice(idx);
const newIdx = idx + code.length;
const newPos = findPosition(newCode, newIdx);
const root = await this.wait("lspStarted message", (msg: any) => { const root = await this.wait("lspStarted message", (msg: any) => {
if (msg.event === "lspStarted") { if (msg.event === "lspStarted") {
return msg.root; return msg.root;
@ -484,11 +487,34 @@ class Test {
languageId: languageId:
this.config.lsp!.lang || this.config.monacoLang || "plaintext", this.config.lsp!.lang || this.config.monacoLang || "plaintext",
version: 1, version: 1,
text: code, text: this.config.template,
}, },
}, },
}, },
}); });
this.send({
event: "lspInput",
input: {
jsonrpc: "2.0",
method: "textDocument/didChange",
params: {
textDocument: {
uri: `file://${root}/${this.config.main}`,
version: 3,
},
contentChanges: [
{
range: {
start: pos,
end: pos,
},
rangeLength: 0,
text: code,
},
],
},
},
});
this.send({ this.send({
event: "lspInput", event: "lspInput",
input: { input: {
@ -499,7 +525,7 @@ class Test {
textDocument: { textDocument: {
uri: `file://${root}/${this.config.main}`, uri: `file://${root}/${this.config.main}`,
}, },
position: findPosition(code, idx + insertedCode.length), position: newPos,
context: { triggerKind: 1 }, context: { triggerKind: 1 },
}, },
}, },