🐛 fix autocomplete bug

This commit is contained in:
Nate Sesti 2024-04-01 22:20:45 -07:00
parent 2abdfe1ec4
commit d98264ac5a
3 changed files with 12 additions and 8 deletions

View file

@ -237,17 +237,18 @@ export async function getTabCompletion(
for await (const update of generator) {
if (token.aborted) {
cancelled = true;
return undefined;
return;
}
yield update;
}
};
let chars = generatorWithCancellation();
const gen2 = onlyWhitespaceAfterEndOfLine(
noFirstCharNewline(chars),
lang.endOfLine,
);
let lineGenerator = stopAtRepeatingLines(stopAtLines(streamLines(gen2)));
let charGenerator = generatorWithCancellation();
charGenerator = noFirstCharNewline(charGenerator);
charGenerator = onlyWhitespaceAfterEndOfLine(charGenerator, lang.endOfLine);
let lineGenerator = streamLines(charGenerator);
lineGenerator = stopAtLines(lineGenerator);
lineGenerator = stopAtRepeatingLines(lineGenerator);
lineGenerator = avoidPathLine(lineGenerator, lang.comment);
lineGenerator = noTopLevelKeywordsMidline(lineGenerator, lang.stopWords);
lineGenerator = streamWithNewLines(lineGenerator);

View file

@ -6,7 +6,7 @@ export interface AutocompleteLanguageInfo {
// TypeScript
export const Typescript = {
stopWords: ["function", "class", "module", "export"],
stopWords: ["function", "class", "module", "export", "import"],
comment: "//",
endOfLine: [";"],
};

View file

@ -50,6 +50,9 @@ export class ListenableGenerator<T> {
async *tee(): AsyncGenerator<T> {
try {
let i = 0;
while (i < this._buffer.length) {
yield this._buffer[i++];
}
while (!this._isEnded) {
let resolve: (value: any) => void;
let promise = new Promise<T>((res) => {