From a2c192c778720c21742e863bd17350deab91b4c9 Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 31 Oct 2024 20:32:58 -0700 Subject: [PATCH] fix bug --- core/autocomplete/READEME.md | 3 +++ core/autocomplete/util/HelperVars.ts | 29 +++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 core/autocomplete/READEME.md diff --git a/core/autocomplete/READEME.md b/core/autocomplete/READEME.md new file mode 100644 index 000000000..170e673a5 --- /dev/null +++ b/core/autocomplete/READEME.md @@ -0,0 +1,3 @@ +TODO + +- The generator reuse thing isn't working it seems diff --git a/core/autocomplete/util/HelperVars.ts b/core/autocomplete/util/HelperVars.ts index dd8eb717b..a6ecb21a9 100644 --- a/core/autocomplete/util/HelperVars.ts +++ b/core/autocomplete/util/HelperVars.ts @@ -19,13 +19,13 @@ import { AutocompleteInput } from "./types"; export class HelperVars { lang: AutocompleteLanguageInfo; treePath: AstPath | undefined; - prunedPrefix: string; - prunedSuffix: string; private _fileContents: string | undefined; private _fileLines: string[] | undefined; private _fullPrefix: string | undefined; private _fullSuffix: string | undefined; + private _prunedPrefix: string | undefined; + private _prunedSuffix: string | undefined; private constructor( public readonly input: AutocompleteInput, @@ -34,9 +34,6 @@ export class HelperVars { private readonly ide: IDE, ) { this.lang = languageForFilepath(input.filepath); - const { prunedPrefix, prunedSuffix } = this.prunePrefixSuffix(); - this.prunedPrefix = prunedPrefix; - this.prunedSuffix = prunedSuffix; } private async init() { @@ -55,6 +52,10 @@ export class HelperVars { this._fullPrefix = fullPrefix; this._fullSuffix = fullSuffix; + const { prunedPrefix, prunedSuffix } = this.prunePrefixSuffix(); + this._prunedPrefix = prunedPrefix; + this._prunedSuffix = prunedSuffix; + try { const ast = await getAst(this.filepath, fullPrefix + fullSuffix); if (ast) { @@ -153,4 +154,22 @@ export class HelperVars { } return this._fullSuffix; } + + get prunedPrefix(): string { + if (this._prunedPrefix === undefined) { + throw new Error( + "HelperVars must be initialized before accessing prunedPrefix", + ); + } + return this._prunedPrefix; + } + + get prunedSuffix(): string { + if (this._prunedSuffix === undefined) { + throw new Error( + "HelperVars must be initialized before accessing prunedSuffix", + ); + } + return this._prunedSuffix; + } }