Skip to content

Commit

Permalink
Merge pull request #49 from MetabobProject/feat/recommendation-diff-n…
Browse files Browse the repository at this point in the history
…ewtab

Feat/recommendation diff newtab
  • Loading branch information
AviGopal authored Oct 22, 2024
2 parents 2ce8cbd + d0e2ee5 commit be1c3c1
Show file tree
Hide file tree
Showing 35 changed files with 1,127 additions and 1,195 deletions.
15 changes: 3 additions & 12 deletions ext-src/commands/AnalyzeDocument.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import { SubmitRepresentationResponse } from '../services';
import { handleDocumentAnalyze } from '../helpers';
import { Analyze, Session } from '../state';
import { Session } from '../state';
import CONSTANTS from '../constants';
import Util from '../utils';
import { getExtensionEventEmitter } from '../events';
Expand All @@ -16,7 +16,6 @@ export function activateAnalyzeCommand(
let isInQueue = false;
let inflightJobId: string | undefined;
const extensionEventEmitter = getExtensionEventEmitter();
const analyzeState = new Analyze(context);
const sessionToken = new Session(context).get()?.value;

const editor = vscode.window.activeTextEditor;
Expand Down Expand Up @@ -71,15 +70,7 @@ export function activateAnalyzeCommand(
);

Util.withProgress<SubmitRepresentationResponse>(
handleDocumentAnalyze(
documentMetaData,
sessionToken,
analyzeState,
context,
undefined,
true,
_debug,
),
handleDocumentAnalyze(documentMetaData, sessionToken, context, undefined, true, _debug),
CONSTANTS.analyzeCommandProgressMessage,
).then(response => {
if (response.status === 'pending' || response.status === 'running') {
Expand All @@ -93,7 +84,7 @@ export function activateAnalyzeCommand(
}

Util.withProgress<SubmitRepresentationResponse>(
handleDocumentAnalyze(documentMetaData, sessionToken, analyzeState, context, inflightJobId),
handleDocumentAnalyze(documentMetaData, sessionToken, context, inflightJobId),
CONSTANTS.analyzeCommandQueueMessage,
).then(response => {
switch (response.status) {
Expand Down
36 changes: 9 additions & 27 deletions ext-src/commands/DetailDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,9 @@ export function activateDetailSuggestionCommand(context: vscode.ExtensionContext
jobId: string;
}) => {
const currentWorkSpaceFolder = Utils.getRootFolderName();
const key = `${args.path}@@${args.id}`;
const setAnalyzeState = new Analyze(context);
const analyzeStateValue = new Analyze(context).get()?.value;
const analyzeState = new Analyze(context);
const analyzeStateValue = analyzeState.value();
const sessionToken = new Session(context).get()?.value;
const extensionEventEmitter = getExtensionEventEmitter();

const documentMetaData = Utils.getCurrentFile();

if (!documentMetaData) {
vscode.window.showErrorMessage(CONSTANTS.editorNotSelectorError);
return;
}

if (!sessionToken || !analyzeStateValue) {
getExtensionEventEmitter().fire({
Expand All @@ -37,25 +28,22 @@ export function activateDetailSuggestionCommand(context: vscode.ExtensionContext
},
});

extensionEventEmitter.fire({
type: 'CURRENT_FILE',
data: { ...documentMetaData.editor.document },
});
vscode.window.showErrorMessage(CONSTANTS.editorNotSelectorError);

return;
}

vscode.commands.executeCommand('recommendation-panel-webview.focus');

const copiedAnalyzeValue = { ...analyzeStateValue };
copiedAnalyzeValue[key].isDiscarded = copiedAnalyzeValue[key].isDiscarded || false;
copiedAnalyzeValue[key].isEndorsed = copiedAnalyzeValue[key].isEndorsed || false;
copiedAnalyzeValue[key].isViewed = true;
const fileProblems = copiedAnalyzeValue[args.path][0].problems;
const problem = fileProblems.find(problem => problem.id === args.id);
if (!problem) return;

const readSuggestionPayload: FeedbackSuggestionPayload = {
problemId: args.id,
discarded: copiedAnalyzeValue[key].isDiscarded || false,
endorsed: copiedAnalyzeValue[key].isEndorsed || false,
discarded: problem.discarded,
endorsed: problem.endorsed,
};

getExtensionEventEmitter().fire({
Expand All @@ -74,23 +62,17 @@ export function activateDetailSuggestionCommand(context: vscode.ExtensionContext
data: {
shouldResetRecomendation: false,
shouldMoveToAnalyzePage: false,
...copiedAnalyzeValue,
},
});

extensionEventEmitter.fire({
type: 'CURRENT_FILE',
data: { ...documentMetaData.editor.document },
});

getExtensionEventEmitter().fire({
type: 'CURRENT_PROJECT',
data: {
name: currentWorkSpaceFolder,
},
});

await setAnalyzeState.set(copiedAnalyzeValue);
await analyzeState.set(copiedAnalyzeValue);

await Promise.allSettled([feedbackService.readSuggestion(readSuggestionPayload, sessionToken)]);
};
Expand Down
47 changes: 20 additions & 27 deletions ext-src/commands/DiscardSuggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { FeedbackSuggestionPayload, feedbackService } from '../services';
import { getExtensionEventEmitter } from '../events';
import CONSTANTS from '../constants';
import Utils from '../utils';
import { Problem } from '../types';

export type DiscardCommandHandler = { id: string; path: string };

Expand All @@ -14,82 +13,76 @@ export function activateDiscardCommand(context: vscode.ExtensionContext): void {
const commandHandler = async (args: DiscardCommandHandler) => {
const currentWorkSpaceFolder = Utils.getRootFolderName();
const analyzeState = new Analyze(context);
const problems = analyzeState.get()?.value;

if (!problems) {
vscode.window.showErrorMessage(CONSTANTS.discardCommandErrorMessage);
return;
}

const currentQuestion = new CurrentQuestion(context);
const extensionEventEmitter = getExtensionEventEmitter();
const { id: problemId, path } = args;
const key = `${path}@@${problemId}`;

const session = new Session(context).get()?.value;
if (!session) {
vscode.window.showErrorMessage(CONSTANTS.discardCommandErrorMessage);

return;
}

// If discard called from recommendation diff, close recommendation
const activeTab = vscode.window.tabGroups.activeTabGroup.activeTab;
if (activeTab && Utils.isRecommendationDiffTab(activeTab.input)) {
vscode.window.tabGroups.close(activeTab);
}

// verifying that in-fact user viewing problem.path file.
const documentMetaData = Utils.getCurrentFile();
if (!documentMetaData) {
vscode.window.showErrorMessage(CONSTANTS.editorNotSelectorError);

return;
}

const filename: string | undefined = documentMetaData.absPath;
const isUserOnProblemFile: boolean = filename === path;

const copyProblems = { ...problems };

const payload: FeedbackSuggestionPayload = {
problemId,
discarded: true,
endorsed: false,
};

// Updating the state with discarded problem values.
copyProblems[key].isDiscarded = true;
copyProblems[key].isEndorsed = false;
copyProblems[key].isViewed = true;

// Filtering the problem that are not not supported by vscode. Line range should be in range [0, lineNumber].
const results: Problem[] | undefined = Utils.getCurrentEditorProblems(copyProblems, path);
if (!results) {
vscode.window.showErrorMessage(CONSTANTS.discardCommandErrorMessage);
return;
}
analyzeState.updateProblem(problemId, { discarded: true, endorsed: false, isViewed: true });

if (isUserOnProblemFile) {
Utils.decorateCurrentEditorWithHighlights(results, documentMetaData.editor);
Utils.decorateCurrentEditorWithHighlights(
analyzeState.getFileProblems(path),
documentMetaData.editor,
);
}

extensionEventEmitter.fire({
type: 'onDiscardSuggestionClicked:Success',
data: {},
});

getExtensionEventEmitter().fire({
extensionEventEmitter.fire({
type: 'Analysis_Completed',
data: { shouldResetRecomendation: true, shouldMoveToAnalyzePage: true, ...copyProblems },
data: {
shouldResetRecomendation: true,
shouldMoveToAnalyzePage: true,
},
});

extensionEventEmitter.fire({
type: 'CURRENT_FILE',
data: { ...documentMetaData.editor.document },
data: documentMetaData.editor.document.uri.fsPath,
});

getExtensionEventEmitter().fire({
extensionEventEmitter.fire({
type: 'CURRENT_PROJECT',
data: {
name: currentWorkSpaceFolder,
},
});

await Promise.allSettled([
analyzeState.set(copyProblems),
feedbackService.discardSuggestion(payload, session),
feedbackService.readSuggestion(payload, session),
]);
Expand Down
17 changes: 6 additions & 11 deletions ext-src/commands/EndorseSuggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,16 @@ export function activateEndorseCommand(
const command = CONSTANTS.endorseSuggestionCommand;

const commandHandler = async (args: EndorseCommandHandler) => {
const { id: problemId, path } = args;
const key = `${path}@@${problemId}`;
const { id: problemId } = args;

const extensionEventEmitter = getExtensionEventEmitter();

const analyzeState = new Analyze(context);
const analyzeStateValue = analyzeState.get()?.value;
if (!analyzeStateValue) return;

const sessionToken = new Session(context).get()?.value;
if (!sessionToken) return;

const copyProblems = { ...analyzeStateValue };

copyProblems[key].isDiscarded = false;
copyProblems[key].isEndorsed = true;
copyProblems[key].isViewed = true;
analyzeState.updateProblem(problemId, { discarded: false, endorsed: true, isViewed: true });

const payload: FeedbackSuggestionPayload = {
problemId,
Expand All @@ -39,10 +32,12 @@ export function activateEndorseCommand(
try {
await feedbackService.endorseSuggestion(payload, sessionToken);
await feedbackService.readSuggestion(payload, sessionToken);
await analyzeState.set(copyProblems);
extensionEventEmitter.fire({
type: 'Analysis_Completed',
data: { shouldResetRecomendation: false, shouldMoveToAnalyzePage: false, ...copyProblems },
data: {
shouldResetRecomendation: false,
shouldMoveToAnalyzePage: false,
},
});
} catch {
_debug?.appendLine(`Metabob: Error Endorsing Problem With ${args.id}`);
Expand Down
40 changes: 0 additions & 40 deletions ext-src/commands/FocusRecommendation.ts

This file was deleted.

1 change: 0 additions & 1 deletion ext-src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export * from './DetailDocument';
export * from './DiscardSuggestion';
export * from './EndorseSuggestion';
export * from './FixSuggestion';
export * from './FocusRecommendation';
4 changes: 4 additions & 0 deletions ext-src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const CONSTANTS = {

// Session
sessionTokenUndefined: 'Metabob: your session has timed out. Please reload your editor window',

// Document Provider
recommendationDocumentProviderScheme: 'metabob-recommendation',
analyzedDocumentProviderScheme: 'metabob-previous-analysis',
};

export default CONSTANTS;
5 changes: 4 additions & 1 deletion ext-src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export interface AnalysisEvents {
| 'CURRENT_FILE'
| 'CURRENT_PROJECT'
| 'INIT_DATA_UPON_NEW_FILE_OPEN'
| 'Analysis_Completed_Empty_Problems';
| 'Analysis_Completed_Empty_Problems'
| 'ANALYZE_STATE_CHANGED'
| 'recommendationCount'
| 'recommendationCurrent';
data: any;
}

Expand Down
Loading

0 comments on commit be1c3c1

Please sign in to comment.