Skip to content

Commit fc169ea

Browse files
committed
feat: try catch of extension and various quality of life updates
1 parent cfeee02 commit fc169ea

File tree

4 files changed

+58
-50
lines changed

4 files changed

+58
-50
lines changed

ext-src/commands/AnalyzeDocument.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,28 @@ export function activateAnalyzeCommand(context: vscode.ExtensionContext) {
1414
let inflightJobId: string | undefined
1515

1616
const analyzeState = new Analyze(context)
17-
const sessionState = new Session(context).get()
18-
if (!sessionState) return
17+
const sessionToken = new Session(context).get()?.value
18+
if (!sessionToken) {
19+
throw new Error('activateAnalyzeCommand: Session Token is undefined')
20+
}
1921

2022
const editor = vscode.window.activeTextEditor
2123

2224
if (!editor) {
2325
vscode.window.showErrorMessage(CONSTANTS.editorNotSelectorError)
24-
25-
return
26+
throw new Error('activateAnalyzeCommand: Editor is undefined')
2627
}
2728

2829
if (!Util.isValidDocument(editor.document)) {
2930
vscode.window.showErrorMessage(CONSTANTS.editorSelectedIsInvalid)
30-
return
31+
throw new Error('activateAnalyzeCommand: Selected Document is not valid')
3132
}
3233
const documentMetaData = Util.extractMetaDataFromDocument(editor.document)
3334

3435
debugChannel.appendLine(`Metabob: Starting Analysis for ${documentMetaData.filePath}`)
3536

3637
Util.withProgress<SubmitRepresentationResponse>(
37-
handleDocumentAnalyze(documentMetaData, sessionState.value, analyzeState),
38+
handleDocumentAnalyze(documentMetaData, sessionToken, analyzeState),
3839
CONSTANTS.analyzeCommandProgressMessage
3940
).then(response => {
4041
if (response.status === 'pending' || response.status === 'running') {
@@ -43,23 +44,25 @@ export function activateAnalyzeCommand(context: vscode.ExtensionContext) {
4344
}
4445
})
4546

46-
if (isInQueue) {
47-
Util.withProgress<SubmitRepresentationResponse>(
48-
handleDocumentAnalyze(documentMetaData, sessionState.value, analyzeState, inflightJobId),
49-
CONSTANTS.analyzeCommandQueueMessage
50-
).then(response => {
51-
switch (response.status) {
52-
case 'failed':
53-
case 'complete':
54-
isInQueue = false
55-
break
56-
case 'pending':
57-
case 'running':
58-
isInQueue = true
59-
break
60-
}
61-
})
47+
if (!isInQueue) {
48+
return
6249
}
50+
51+
Util.withProgress<SubmitRepresentationResponse>(
52+
handleDocumentAnalyze(documentMetaData, sessionToken, analyzeState, inflightJobId),
53+
CONSTANTS.analyzeCommandQueueMessage
54+
).then(response => {
55+
switch (response.status) {
56+
case 'failed':
57+
case 'complete':
58+
isInQueue = false
59+
break
60+
case 'pending':
61+
case 'running':
62+
isInQueue = true
63+
break
64+
}
65+
})
6366
}
6467

6568
context.subscriptions.push(vscode.commands.registerCommand(command, commandHandler))

ext-src/extension.ts

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,35 @@ export function activate(context: vscode.ExtensionContext): void {
2828

2929
const analyzeDocumentOnSaveConfig = AnalyzeDocumentOnSaveConfig()
3030

31-
// Create User Session, If already created get the refresh token
32-
// otherwise, ping server every 60 second to not destroy the token
33-
// if the user has not done any activity
34-
createOrUpdateUserSession(context)
35-
36-
// Analyze command that hit /analyze endpoint with current file content
37-
// then decorate current file with error
38-
activateAnalyzeCommand(context)
39-
40-
// If the user Discard a suggestion, it would be removed from decoration
41-
// and the global state as well
42-
activateDiscardCommand(context)
43-
44-
// If the user feels suggestion is good, he can endorse that suggestion
45-
// Used to notify the model about positive feedback
46-
activateEndorseCommand(context)
47-
48-
// Deprecated
49-
activateFocusRecommendCommand(context)
50-
51-
// When the user click the detail button on the problem
52-
activateDetailSuggestionCommand(context)
53-
54-
// Whenever the user clicks the fix button
55-
activateFixSuggestionCommand(context)
31+
try {
32+
// Create User Session, If already created get the refresh token
33+
// otherwise, ping server every 60 second to not destroy the token
34+
// if the user has not done any activity
35+
createOrUpdateUserSession(context)
36+
37+
// Analyze command that hit /analyze endpoint with current file content
38+
// then decorate current file with error
39+
activateAnalyzeCommand(context)
40+
41+
// If the user Discard a suggestion, it would be removed from decoration
42+
// and the global state as well
43+
activateDiscardCommand(context)
44+
45+
// If the user feels suggestion is good, he can endorse that suggestion
46+
// Used to notify the model about positive feedback
47+
activateEndorseCommand(context)
48+
49+
// Deprecated
50+
activateFocusRecommendCommand(context)
51+
52+
// When the user click the detail button on the problem
53+
activateDetailSuggestionCommand(context)
54+
55+
// Whenever the user clicks the fix button
56+
activateFixSuggestionCommand(context)
57+
} catch (error: any) {
58+
debugChannel.appendLine(`Metabob: ${error}`)
59+
}
5660

5761
// Analyze on Save functionality is only ran if the user enabled it.
5862
if (analyzeDocumentOnSaveConfig && analyzeDocumentOnSaveConfig === true) {

ext-src/helpers/CreateOrUpdateUserSession.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ export async function createOrUpdateUserSession(context: vscode.ExtensionContext
1313
supplementaryId: requestParamId
1414
}
1515
}
16-
const sessionToken = sessionState.get()
16+
17+
const sessionToken = sessionState.get()?.value
1718
if (sessionToken) {
18-
payload['sessionToken'] = sessionToken.value
19+
payload['sessionToken'] = sessionToken
1920
}
2021

2122
const response = await sessionService.createUserSession(payload)

ext-src/helpers/HandleDocumentAnalyze.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const handleDocumentAnalyze = async (
7171
}
7272
})
7373

74-
await analyzeState.set(results)
74+
analyzeState.set(results)
7575

7676
const decorationFromResponse = Util.transformResponseToDecorations(verifiedResponse.results, editor, jobId)
7777
editor.setDecorations(decorationFromResponse.decorationType, [])

0 commit comments

Comments
 (0)