fix misused promises errors in core folder
This commit is contained in:
parent
0d66c60381
commit
4b4e3e4702
7 changed files with 82 additions and 74 deletions
|
|
@ -40,7 +40,7 @@ export async function testRootPathContext(
|
|||
// @ts-ignore
|
||||
.spyOn(service, "getSnippets")
|
||||
// @ts-ignore
|
||||
.mockImplementation(async (_filepath, _endPosition) => {
|
||||
.mockImplementation((_filePath, _endPosition) => {
|
||||
return [];
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -87,38 +87,40 @@ export class ProfileLifecycleManager {
|
|||
}
|
||||
|
||||
// Set pending config promise
|
||||
this.pendingConfigPromise = new Promise(async (resolve, reject) => {
|
||||
let result: ConfigResult<ContinueConfig>;
|
||||
// This try catch is expected to catch high-level errors that aren't block-specific
|
||||
// Like invalid json, invalid yaml, file read errors, etc.
|
||||
// NOT block-specific loading errors
|
||||
try {
|
||||
result = await this.profileLoader.doLoadConfig();
|
||||
} catch (e) {
|
||||
const message =
|
||||
e instanceof Error
|
||||
? `${e.message}\n${e.stack ? e.stack : ""}`
|
||||
: "Error loading config";
|
||||
result = {
|
||||
errors: [
|
||||
{
|
||||
fatal: true,
|
||||
message,
|
||||
},
|
||||
],
|
||||
config: undefined,
|
||||
configLoadInterrupted: true,
|
||||
};
|
||||
}
|
||||
this.pendingConfigPromise = new Promise((resolve) => {
|
||||
void (async () => {
|
||||
let result: ConfigResult<ContinueConfig>;
|
||||
// This try catch is expected to catch high-level errors that aren't block-specific
|
||||
// Like invalid json, invalid yaml, file read errors, etc.
|
||||
// NOT block-specific loading errors
|
||||
try {
|
||||
result = await this.profileLoader.doLoadConfig();
|
||||
} catch (e) {
|
||||
const message =
|
||||
e instanceof Error
|
||||
? `${e.message}\n${e.stack ? e.stack : ""}`
|
||||
: "Error loading config";
|
||||
result = {
|
||||
errors: [
|
||||
{
|
||||
fatal: true,
|
||||
message,
|
||||
},
|
||||
],
|
||||
config: undefined,
|
||||
configLoadInterrupted: true,
|
||||
};
|
||||
}
|
||||
|
||||
if (result.config) {
|
||||
// Add registered context providers
|
||||
result.config.contextProviders = (
|
||||
result.config.contextProviders ?? []
|
||||
).concat(additionalContextProviders);
|
||||
}
|
||||
if (result.config) {
|
||||
// Add registered context providers
|
||||
result.config.contextProviders = (
|
||||
result.config.contextProviders ?? []
|
||||
).concat(additionalContextProviders);
|
||||
}
|
||||
|
||||
resolve(result);
|
||||
resolve(result);
|
||||
})();
|
||||
});
|
||||
|
||||
// Wait for the config promise to resolve
|
||||
|
|
|
|||
40
core/core.ts
40
core/core.ts
|
|
@ -145,8 +145,8 @@ export class Core {
|
|||
this.messenger,
|
||||
);
|
||||
|
||||
MCPManagerSingleton.getInstance().onConnectionsRefreshed = async () => {
|
||||
await this.configHandler.reloadConfig();
|
||||
MCPManagerSingleton.getInstance().onConnectionsRefreshed = () => {
|
||||
void this.configHandler.reloadConfig();
|
||||
};
|
||||
|
||||
this.codeBaseIndexer = new CodebaseIndexer(
|
||||
|
|
@ -156,24 +156,26 @@ export class Core {
|
|||
this.globalContext.get("indexingPaused"),
|
||||
);
|
||||
|
||||
this.configHandler.onConfigUpdate(async (result) => {
|
||||
const serializedResult = await this.configHandler.getSerializedConfig();
|
||||
this.messenger.send("configUpdate", {
|
||||
result: serializedResult,
|
||||
profileId:
|
||||
this.configHandler.currentProfile?.profileDescription.id || null,
|
||||
organizations: this.configHandler.getSerializedOrgs(),
|
||||
selectedOrgId: this.configHandler.currentOrg.id,
|
||||
});
|
||||
|
||||
// update additional submenu context providers registered via VSCode API
|
||||
const additionalProviders =
|
||||
this.configHandler.getAdditionalSubmenuContextProviders();
|
||||
if (additionalProviders.length > 0) {
|
||||
this.messenger.send("refreshSubmenuItems", {
|
||||
providers: additionalProviders,
|
||||
this.configHandler.onConfigUpdate((result) => {
|
||||
void (async () => {
|
||||
const serializedResult = await this.configHandler.getSerializedConfig();
|
||||
this.messenger.send("configUpdate", {
|
||||
result: serializedResult,
|
||||
profileId:
|
||||
this.configHandler.currentProfile?.profileDescription.id || null,
|
||||
organizations: this.configHandler.getSerializedOrgs(),
|
||||
selectedOrgId: this.configHandler.currentOrg.id,
|
||||
});
|
||||
}
|
||||
|
||||
// update additional submenu context providers registered via VSCode API
|
||||
const additionalProviders =
|
||||
this.configHandler.getAdditionalSubmenuContextProviders();
|
||||
if (additionalProviders.length > 0) {
|
||||
this.messenger.send("refreshSubmenuItems", {
|
||||
providers: additionalProviders,
|
||||
});
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
||||
// Dev Data Logger
|
||||
|
|
|
|||
|
|
@ -97,8 +97,8 @@ export class LanceDbIndex implements CodebaseIndex {
|
|||
contents TEXT NOT NULL
|
||||
)`);
|
||||
|
||||
await new Promise((resolve) =>
|
||||
migrate(
|
||||
await new Promise((resolve) => {
|
||||
void migrate(
|
||||
"lancedb_sqlite_artifact_id_column",
|
||||
async () => {
|
||||
try {
|
||||
|
|
@ -118,8 +118,8 @@ export class LanceDbIndex implements CodebaseIndex {
|
|||
}
|
||||
},
|
||||
() => resolve(undefined),
|
||||
),
|
||||
);
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
private async computeRows(items: PathAndCacheKey[]): Promise<LanceDbRow[]> {
|
||||
|
|
|
|||
|
|
@ -50,21 +50,23 @@ export async function* chunkDocument({
|
|||
maxChunkSize,
|
||||
)) {
|
||||
chunkPromises.push(
|
||||
new Promise(async (resolve) => {
|
||||
if ((await countTokensAsync(chunkWithoutId.content)) > maxChunkSize) {
|
||||
// console.debug(
|
||||
// `Chunk with more than ${maxChunkSize} tokens constructed: `,
|
||||
// filepath,
|
||||
// countTokens(chunkWithoutId.content),
|
||||
// );
|
||||
return resolve(undefined);
|
||||
}
|
||||
resolve({
|
||||
...chunkWithoutId,
|
||||
digest,
|
||||
index,
|
||||
filepath,
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
void (async () => {
|
||||
if ((await countTokensAsync(chunkWithoutId.content)) > maxChunkSize) {
|
||||
// console.debug(
|
||||
// `Chunk with more than ${maxChunkSize} tokens constructed: `,
|
||||
// filepath,
|
||||
// countTokens(chunkWithoutId.content),
|
||||
// );
|
||||
return resolve(undefined);
|
||||
}
|
||||
resolve({
|
||||
...chunkWithoutId,
|
||||
digest,
|
||||
index,
|
||||
filepath,
|
||||
});
|
||||
})();
|
||||
}),
|
||||
);
|
||||
index++;
|
||||
|
|
|
|||
|
|
@ -186,7 +186,9 @@ export default class DocsService {
|
|||
private async init(configHandler: ConfigHandler) {
|
||||
const result = await configHandler.loadConfig();
|
||||
await this.handleConfigUpdate(result);
|
||||
configHandler.onConfigUpdate(this.handleConfigUpdate.bind(this));
|
||||
configHandler.onConfigUpdate(
|
||||
this.handleConfigUpdate.bind(this) as (arg: any) => void,
|
||||
);
|
||||
}
|
||||
|
||||
readonly statuses: Map<string, IndexingStatus> = new Map();
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import { editConfigFile, migrate } from "../../util/paths.js";
|
|||
import DocsService, { SqliteDocsRow } from "./DocsService.js";
|
||||
|
||||
export async function runLanceMigrations(table: Table) {
|
||||
await new Promise((resolve) =>
|
||||
migrate(
|
||||
await new Promise((resolve) => {
|
||||
void migrate(
|
||||
"rename_baseurl_column_for_lance_docs",
|
||||
async () => {
|
||||
try {
|
||||
|
|
@ -21,8 +21,8 @@ export async function runLanceMigrations(table: Table) {
|
|||
}
|
||||
},
|
||||
() => resolve(undefined),
|
||||
),
|
||||
);
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export async function runSqliteMigrations(db: Database) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue