Skip to content

Commit

Permalink
fix: prevent mutation that causes Code webview crash (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
michelkaporin authored Dec 1, 2021
1 parent 9ec1ba6 commit ee64ddb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/snyk/common/commands/commandController.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { getIpFamily } from '@snyk/code-client';
import _ from 'lodash';
import * as vscode from 'vscode';
import { IAuthenticationService } from '../../base/services/authenticationService';
import { ScanModeService } from '../../base/services/scanModeService';
import { ISnykCodeService } from '../../snykCode/codeService';
import { IssueUtils } from '../../snykCode/utils/issueUtils';
import { createDCIgnore } from '../../snykCode/utils/ignoreFileUtils';
import { IssueUtils } from '../../snykCode/utils/issueUtils';
import { CodeIssueCommandArg } from '../../snykCode/views/interfaces';
import { capitalizeOssSeverity } from '../../snykOss/ossResult';
import { OssService } from '../../snykOss/services/ossService';
import { OssIssueCommandArg } from '../../snykOss/views/ossVulnerabilityTreeProvider';
import { IAnalytics } from '../analytics/itly';
import {
SNYK_COPY_AUTH_LINK_COMMAND,
SNYK_LOGIN_COMMAND,
Expand All @@ -19,9 +22,6 @@ import { COMMAND_DEBOUNCE_INTERVAL, IDE_NAME, SNYK_NAME_EXTENSION, SNYK_PUBLISHE
import { ILog } from '../logger/interfaces';
import { IOpenerService } from '../services/openerService';
import { OpenCommandIssueType, OpenIssueCommandArg } from './types';
import { IAuthenticationService } from '../../base/services/authenticationService';
import { IAnalytics } from '../analytics/itly';
import { getIpFamily } from '@snyk/code-client';

export class CommandController {
private debouncedCommands: Record<string, _.DebouncedFunc<(...args: unknown[]) => Promise<unknown>>> = {};
Expand Down Expand Up @@ -82,12 +82,12 @@ export class CommandController {
issue.openUri || issue.uri,
issue.openRange || issue.range,
);

this.snykCode.suggestionProvider.show(suggestion.id, issue.uri, issue.range);
suggestion.id = decodeURIComponent(suggestion.id);

this.analytics.logIssueInTreeIsClicked({
ide: IDE_NAME,
issueId: suggestion.id,
issueId: decodeURIComponent(suggestion.id),
issueType: suggestion.isSecurityType ? 'Code Security Vulnerability' : 'Code Quality Issue',
severity: IssueUtils.severityAsText(suggestion.severity),
});
Expand Down
12 changes: 6 additions & 6 deletions src/snyk/snykCode/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type openedTextEditorType = {

export interface IIssuesListOptions {
fileIssuesList: FilePath;
suggestions: ICodeSuggestions;
suggestions: Readonly<ICodeSuggestions>;
fileUri: vscode.Uri;
}

Expand All @@ -30,24 +30,24 @@ export type ICodeSuggestion = Suggestion & {
};

interface ICodeSuggestions {
[suggestionIndex: string]: ICodeSuggestion;
[suggestionIndex: string]: Readonly<ICodeSuggestion>;
}

export interface ISnykCodeResult extends AnalysisResultLegacy {
suggestions: ICodeSuggestions;
suggestions: Readonly<ICodeSuggestions>;
}

export interface ISnykCodeAnalyzer {
codeSecurityReview: DiagnosticCollection | undefined;
codeQualityReview: DiagnosticCollection | undefined;
setAnalysisResults(results: AnalysisResultLegacy): void;
getAnalysisResults(): ISnykCodeResult;
findSuggestion(suggestionName: string): ICodeSuggestion | undefined;
getAnalysisResults(): Readonly<ISnykCodeResult>;
findSuggestion(suggestionName: string): Readonly<ICodeSuggestion | undefined>;
getFullSuggestion(
suggestionId: string,
uri: vscode.Uri,
position: vscode.Range,
): completeFileSuggestionType | undefined;
): Readonly<completeFileSuggestionType | undefined>;
checkFullSuggestion(suggestion: completeFileSuggestionType): boolean;
createReviewResults(): void;
updateReviewResultsPositions(extension: IExtension, updatedFile: openedTextEditorType): Promise<void>;
Expand Down

0 comments on commit ee64ddb

Please sign in to comment.