Hopefully addresses #742

pull/744/head
Zef Hemel 2024-02-23 13:42:02 +01:00
parent cfd1e53f62
commit 60a42048ba
1 changed files with 24 additions and 7 deletions

View File

@ -61,6 +61,7 @@ import { KvPrimitives } from "$lib/data/kv_primitives.ts";
import { builtinFunctions } from "$lib/builtin_query_functions.ts"; import { builtinFunctions } from "$lib/builtin_query_functions.ts";
import { ensureAndLoadSettingsAndIndex } from "$common/settings.ts"; import { ensureAndLoadSettingsAndIndex } from "$common/settings.ts";
import { LimitedMap } from "$lib/limited_map.ts"; import { LimitedMap } from "$lib/limited_map.ts";
import { currentCompletions } from "@codemirror/autocomplete";
const frontMatterRegex = /^---\n(([^\n]|\n)*?)---\n/; const frontMatterRegex = /^---\n(([^\n]|\n)*?)---\n/;
const autoSaveInterval = 1000; const autoSaveInterval = 1000;
@ -869,21 +870,37 @@ export class Client {
pos: selection.from, pos: selection.from,
parentNodes, parentNodes,
} as CompleteEvent); } as CompleteEvent);
let actualResult = null; let currentResult: CompletionResult | null = null;
for (const result of results) { for (const result of results) {
if (result) { if (!result) {
if (actualResult) { continue;
}
if (currentResult) {
// Let's see if we can merge results
if (currentResult.from !== result.from) {
console.error( console.error(
"Got completion results from multiple sources, cannot deal with that", "Got completion results from multiple sources with different `from` locators, cannot deal with that",
);
console.error(
"Previously had",
currentResult,
"now also got",
result,
); );
console.error("Previously had", actualResult, "now also got", result);
return null; return null;
} else {
// Merge
currentResult = {
from: result.from,
options: [...currentResult.options, ...result.options],
};
} }
actualResult = result; } else {
currentResult = result;
} }
} }
// console.log("Compeltion result", actualResult); // console.log("Compeltion result", actualResult);
return actualResult; return currentResult;
} }
editorComplete( editorComplete(