diff --git a/ext-src/commands/AnalyzeDocument.ts b/ext-src/commands/AnalyzeDocument.ts index 58bf91d..97c91ad 100644 --- a/ext-src/commands/AnalyzeDocument.ts +++ b/ext-src/commands/AnalyzeDocument.ts @@ -14,27 +14,28 @@ export function activateAnalyzeCommand(context: vscode.ExtensionContext) { let inflightJobId: string | undefined const analyzeState = new Analyze(context) - const sessionState = new Session(context).get() - if (!sessionState) return + const sessionToken = new Session(context).get()?.value + if (!sessionToken) { + throw new Error('activateAnalyzeCommand: Session Token is undefined') + } const editor = vscode.window.activeTextEditor if (!editor) { vscode.window.showErrorMessage(CONSTANTS.editorNotSelectorError) - - return + throw new Error('activateAnalyzeCommand: Editor is undefined') } if (!Util.isValidDocument(editor.document)) { vscode.window.showErrorMessage(CONSTANTS.editorSelectedIsInvalid) - return + throw new Error('activateAnalyzeCommand: Selected Document is not valid') } const documentMetaData = Util.extractMetaDataFromDocument(editor.document) debugChannel.appendLine(`Metabob: Starting Analysis for ${documentMetaData.filePath}`) Util.withProgress( - handleDocumentAnalyze(documentMetaData, sessionState.value, analyzeState), + handleDocumentAnalyze(documentMetaData, sessionToken, analyzeState), CONSTANTS.analyzeCommandProgressMessage ).then(response => { if (response.status === 'pending' || response.status === 'running') { @@ -43,23 +44,25 @@ export function activateAnalyzeCommand(context: vscode.ExtensionContext) { } }) - if (isInQueue) { - Util.withProgress( - handleDocumentAnalyze(documentMetaData, sessionState.value, analyzeState, inflightJobId), - CONSTANTS.analyzeCommandQueueMessage - ).then(response => { - switch (response.status) { - case 'failed': - case 'complete': - isInQueue = false - break - case 'pending': - case 'running': - isInQueue = true - break - } - }) + if (!isInQueue) { + return } + + Util.withProgress( + handleDocumentAnalyze(documentMetaData, sessionToken, analyzeState, inflightJobId), + CONSTANTS.analyzeCommandQueueMessage + ).then(response => { + switch (response.status) { + case 'failed': + case 'complete': + isInQueue = false + break + case 'pending': + case 'running': + isInQueue = true + break + } + }) } context.subscriptions.push(vscode.commands.registerCommand(command, commandHandler)) diff --git a/ext-src/extension.ts b/ext-src/extension.ts index 4e540a4..fd68c2c 100644 --- a/ext-src/extension.ts +++ b/ext-src/extension.ts @@ -28,31 +28,35 @@ export function activate(context: vscode.ExtensionContext): void { const analyzeDocumentOnSaveConfig = AnalyzeDocumentOnSaveConfig() - // Create User Session, If already created get the refresh token - // otherwise, ping server every 60 second to not destroy the token - // if the user has not done any activity - createOrUpdateUserSession(context) - - // Analyze command that hit /analyze endpoint with current file content - // then decorate current file with error - activateAnalyzeCommand(context) - - // If the user Discard a suggestion, it would be removed from decoration - // and the global state as well - activateDiscardCommand(context) - - // If the user feels suggestion is good, he can endorse that suggestion - // Used to notify the model about positive feedback - activateEndorseCommand(context) - - // Deprecated - activateFocusRecommendCommand(context) - - // When the user click the detail button on the problem - activateDetailSuggestionCommand(context) - - // Whenever the user clicks the fix button - activateFixSuggestionCommand(context) + try { + // Create User Session, If already created get the refresh token + // otherwise, ping server every 60 second to not destroy the token + // if the user has not done any activity + createOrUpdateUserSession(context) + + // Analyze command that hit /analyze endpoint with current file content + // then decorate current file with error + activateAnalyzeCommand(context) + + // If the user Discard a suggestion, it would be removed from decoration + // and the global state as well + activateDiscardCommand(context) + + // If the user feels suggestion is good, he can endorse that suggestion + // Used to notify the model about positive feedback + activateEndorseCommand(context) + + // Deprecated + activateFocusRecommendCommand(context) + + // When the user click the detail button on the problem + activateDetailSuggestionCommand(context) + + // Whenever the user clicks the fix button + activateFixSuggestionCommand(context) + } catch (error: any) { + debugChannel.appendLine(`Metabob: ${error}`) + } // Analyze on Save functionality is only ran if the user enabled it. if (analyzeDocumentOnSaveConfig && analyzeDocumentOnSaveConfig === true) { diff --git a/ext-src/helpers/CreateOrUpdateUserSession.ts b/ext-src/helpers/CreateOrUpdateUserSession.ts index 004e309..373962d 100644 --- a/ext-src/helpers/CreateOrUpdateUserSession.ts +++ b/ext-src/helpers/CreateOrUpdateUserSession.ts @@ -13,9 +13,10 @@ export async function createOrUpdateUserSession(context: vscode.ExtensionContext supplementaryId: requestParamId } } - const sessionToken = sessionState.get() + + const sessionToken = sessionState.get()?.value if (sessionToken) { - payload['sessionToken'] = sessionToken.value + payload['sessionToken'] = sessionToken } const response = await sessionService.createUserSession(payload) diff --git a/ext-src/helpers/HandleDocumentAnalyze.ts b/ext-src/helpers/HandleDocumentAnalyze.ts index bbff2a8..02a3460 100644 --- a/ext-src/helpers/HandleDocumentAnalyze.ts +++ b/ext-src/helpers/HandleDocumentAnalyze.ts @@ -71,7 +71,7 @@ export const handleDocumentAnalyze = async ( } }) - await analyzeState.set(results) + analyzeState.set(results) const decorationFromResponse = Util.transformResponseToDecorations(verifiedResponse.results, editor, jobId) editor.setDecorations(decorationFromResponse.decorationType, [])