Skip to content

Commit 900fb5f

Browse files
committed
Added suggestion closing when fixed.
1 parent 66a4a60 commit 900fb5f

6 files changed

Lines changed: 52 additions & 3 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/deepcode/lib/analyzer/DeepCodeAnalyzer.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
createDeepCodeSeveritiesMap,
1515
getDeepCodeSeverity,
1616
findCompleteSuggestion,
17+
checkCompleteSuggestion,
1718
findSuggestionByMessage,
1819
} from '../../utils/analysisUtils';
1920
import { DEEPCODE_NAME } from "../../constants/general";
@@ -58,6 +59,10 @@ class DeepCodeAnalyzer implements AnalyzerInterface {
5859
return findCompleteSuggestion(this.analysisResults, suggestionId, uri, position);
5960
}
6061

62+
public checkFullSuggestion(suggestion: completeFileSuggestionType): boolean {
63+
return checkCompleteSuggestion(this.analysisResults, suggestion);
64+
}
65+
6166
public findSuggestion(suggestionName: string): ISuggestion | undefined {
6267
return findSuggestionByMessage(this.analysisResults, suggestionName);
6368
}

src/deepcode/lib/modules/BundlesModule.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ abstract class BundlesModule extends LoginModule implements BundlesModuleInterfa
7474
this.analyzer.createReviewResults();
7575

7676
this.refreshViews();
77+
this.suggestionProvider.checkCurrentSuggestion();
7778
}
7879
} else {
7980
await this.setContext(DEEPCODE_CONTEXT.WORKSPACE_FOUND, false);

src/deepcode/utils/analysisUtils.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,33 @@ export const findCompleteSuggestion = (
240240
};
241241
};
242242

243+
export const checkCompleteSuggestion = (
244+
analysisResults: IAnalysisResult,
245+
suggestion: completeFileSuggestionType,
246+
): boolean => {
247+
let filePath = vscode.Uri.parse(suggestion.uri).fsPath;
248+
if (!analysisResults.files[filePath]) return false;
249+
const file: IFilePath = analysisResults.files[filePath];
250+
let suggestionIndex: string | undefined = Object.keys(file).find((i) => {
251+
const index = parseInt(i, 10);
252+
if (
253+
analysisResults.suggestions[index].id !== suggestion.id ||
254+
analysisResults.suggestions[index].message !== suggestion.message
255+
) return false;
256+
const found = file[index].find((fs) => {
257+
let equal = true;
258+
for(let dir of ['cols','rows']) {
259+
for(let index of [0, 1]) {
260+
equal = equal && fs[dir][index] === suggestion[dir][index];
261+
}
262+
}
263+
return equal;
264+
});
265+
return !!found;
266+
});
267+
return !!suggestionIndex;
268+
}
269+
243270
export const findSuggestionByMessage = (
244271
analysisResults: IAnalysisResult,
245272
suggestionName: string,

src/deepcode/view/SuggestionProvider.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,9 @@ function getWebviewContent(images: Record<string,string>) { return `
506506
export class SuggestionProvider implements SuggestionProviderInterface {
507507
private extension: ExtensionInterface | undefined;
508508
private panel: vscode.WebviewPanel | undefined;
509+
// For consistency reasons, the single source of truth for the current suggestion is the
510+
// panel state. The following field is only used in
511+
private suggestion: completeFileSuggestionType | undefined;
509512

510513
activate(extension: ExtensionInterface) {
511514
this.extension = extension;
@@ -515,12 +518,22 @@ export class SuggestionProvider implements SuggestionProviderInterface {
515518
}
516519

517520
show(suggestionId: string, uri: vscode.Uri, position: vscode.Range): void {
518-
if (!this.extension) return;
521+
if (!this.extension) return this.checkPanelAndDispose();
519522
const suggestion = this.extension.analyzer.getFullSuggestion(suggestionId, uri, position);
520-
if (!suggestion) return;
523+
if (!suggestion) return this.checkPanelAndDispose();
521524
this.showPanel(suggestion);
522525
}
523526

527+
checkCurrentSuggestion(): void {
528+
if (!this.panel || !this.suggestion || !this.extension) return;
529+
const found = this.extension.analyzer.checkFullSuggestion(this.suggestion);
530+
if (!found) return this.checkPanelAndDispose();
531+
}
532+
533+
private checkPanelAndDispose() {
534+
if (this.panel) this.panel.dispose();
535+
}
536+
524537
private disposePanel() {
525538
this.panel = undefined;
526539
}
@@ -600,6 +613,7 @@ export class SuggestionProvider implements SuggestionProviderInterface {
600613
undefined,
601614
this.extension?.context?.subscriptions
602615
);
616+
this.suggestion = suggestion;
603617
} catch (e) {
604618
if (!this.extension) return;
605619
this.extension.processError(e, {

src/interfaces/DeepCodeInterfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export interface DeepCodeWatcherInterface {
8080
export interface SuggestionProviderInterface {
8181
activate(extension: ExtensionInterface): void;
8282
show(suggestionId: string, uri: vscode.Uri, position: vscode.Range): void;
83+
checkCurrentSuggestion(): void;
8384
}
8485

8586
export type userStateItemType = string | number | boolean | undefined;
@@ -142,6 +143,7 @@ export interface AnalyzerInterface {
142143
analysisResults: IAnalysisResult;
143144
findSuggestion(suggestionName: string): ISuggestion | undefined;
144145
getFullSuggestion(suggestionId: string, uri: vscode.Uri, position: vscode.Range): completeFileSuggestionType | undefined;
146+
checkFullSuggestion(suggestion: completeFileSuggestionType): boolean;
145147
createReviewResults(): Promise<void>;
146148
updateReviewResultsPositions(extension: ExtensionInterface, updatedFile: openedTextEditorType): Promise<void>;
147149
setIssuesMarkersDecoration(editor: TextEditor | undefined): void;

0 commit comments

Comments
 (0)