Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLVSCODE-966 improve UX with taint vulnerabilities on file change #671

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"groupId": "org.sonarsource.sonarlint.ls",
"artifactId": "sonarlint-language-server",
"version": "3.15.0.75823",
"version": "3.15.0.75834",
"output": "server/sonarlint-ls.jar"
},
{
Expand Down
24 changes: 23 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import { getPlatform } from './util/platform';
import { installManagedJre, JAVA_HOME_CONFIG, resolveRequirements } from './util/requirements';
import { code2ProtocolConverter, protocol2CodeConverter } from './util/uri';
import * as util from './util/util';
import { filterOutFilesIgnoredForAnalysis, shouldAnalyseFile } from './util/util';
import { filterOutFilesIgnoredForAnalysis, getSeverity, shouldAnalyseFile } from './util/util';
import { resolveIssueMultiStepInput } from './issue/resolveIssue';
import { IssueService } from './issue/issue';
import { CAN_SHOW_MISSING_REQUIREMENT_NOTIF, showSslCertificateConfirmationDialog } from './util/showMessage';
Expand Down Expand Up @@ -92,6 +92,7 @@ let hotspotsTreeDataProvider: AllHotspotsTreeDataProvider;
let allHotspotsView: VSCode.TreeView<HotspotTreeViewItem>;
let helpAndFeedbackTreeDataProvider: HelpAndFeedbackTreeDataProvider;
let helpAndFeedbackView: VSCode.TreeView<HelpAndFeedbackLink>;
let taintVulnerabilityCollection: VSCode.DiagnosticCollection;

function runJavaServer(context: VSCode.ExtensionContext): Promise<StreamInfo> {
return resolveRequirements(context)
Expand Down Expand Up @@ -221,6 +222,9 @@ export async function activate(context: VSCode.ExtensionContext) {

await languageClient.start();

taintVulnerabilityCollection = VSCode.languages.createDiagnosticCollection('SonarQube Taint Vulnerabilities');
context.subscriptions.push(taintVulnerabilityCollection);

ConnectionSettingsService.init(context, languageClient);
NewCodeDefinitionService.init(context);
FileSystemServiceImpl.init();
Expand Down Expand Up @@ -623,6 +627,24 @@ function installCustomRequestHandlers(context: VSCode.ExtensionContext) {
await hotspotsTreeDataProvider.refresh(hotspotsPerFile);
updateSonarLintViewContainerBadge();
});
languageClient.onNotification(protocol.PublishTaintVulnerabilitiesForFile.type, async taintVulnerabilitiesPerFile => {
const diagnostics = taintVulnerabilitiesPerFile.diagnostics.map(diagnostic => {
const d = new VSCode.Diagnostic(
new VSCode.Range(
new VSCode.Position(diagnostic.range.start.line, diagnostic.range.start.character),
new VSCode.Position(diagnostic.range.end.line, diagnostic.range.end.character)
),
diagnostic.message,
getSeverity(diagnostic.severity)
);
d.source = diagnostic.source;
d.code = diagnostic.code;
d['data'] = diagnostic.data;
return d;
});
taintVulnerabilityCollection.set(VSCode.Uri.parse(taintVulnerabilitiesPerFile.uri), diagnostics);
});

languageClient.onRequest(
protocol.AssistBinding.type,
async params => await BindingService.instance.assistBinding(params)
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/hotspotsTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Timeout = NodeJS.Timeout;
import * as VSCode from 'vscode';
import { ProviderResult, TextDocument, ThemeColor, ThemeIcon } from 'vscode';
import { Diagnostic, PublishHotspotsForFileParams } from '../lsp/protocol';
import { Diagnostic, PublishDiagnosticsParams } from '../lsp/protocol';
import { ConnectionSettingsService } from '../settings/connectionsettings';
import { Commands } from '../util/commands';
import { getFileNameFromFullPath, getRelativePathFromFullPath, protocol2CodeConverter } from '../util/uri';
Expand Down Expand Up @@ -126,7 +126,7 @@ export class AllHotspotsTreeDataProvider implements VSCode.TreeDataProvider<Hots
await VSCode.commands.executeCommand('setContext', 'SonarLint.Hotspots.ShowMode', showMode);
}

async refresh(hotspotsPerFile?: PublishHotspotsForFileParams) {
async refresh(hotspotsPerFile?: PublishDiagnosticsParams) {
if (hotspotsPerFile && hotspotsPerFile.uri) {
if (hotspotsPerFile.diagnostics.length > 0) {
this.fileHotspotsCache.set(hotspotsPerFile.uri, hotspotsPerFile.diagnostics);
Expand Down
8 changes: 6 additions & 2 deletions src/lsp/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,17 @@ export interface Diagnostic extends lsp.Diagnostic {
flows: Flow[];
}

export interface PublishHotspotsForFileParams {
export interface PublishDiagnosticsParams {
uri: string;
diagnostics: Diagnostic[];
}

export namespace PublishHotspotsForFile {
export const type = new lsp.NotificationType<PublishHotspotsForFileParams>('sonarlint/publishSecurityHotspots');
export const type = new lsp.NotificationType<PublishDiagnosticsParams>('sonarlint/publishSecurityHotspots');
}

export namespace PublishTaintVulnerabilitiesForFile {
export const type = new lsp.NotificationType<PublishDiagnosticsParams>('sonarlint/publishTaintVulnerabilities');
}

export interface ShowHotspotLocationsParams {
Expand Down
19 changes: 19 additions & 0 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,22 @@ function isOpenInEditor(fileUri: string) {
const notebookDocumentIsOpen = vscode.workspace.notebookDocuments.some(d => d.uri.toString(false) === codeFileUri);
return textDocumentIsOpen || notebookDocumentIsOpen;
}

export function getSeverity(severity: number): vscode.DiagnosticSeverity {
const SEVERITY_ERROR = 1;
const SEVERITY_WARNING = 2;
const SEVERITY_INFORMATION = 3;
const SEVERITY_HINT = 4;
switch (severity) {
case SEVERITY_ERROR:
return vscode.DiagnosticSeverity.Error;
case SEVERITY_WARNING:
return vscode.DiagnosticSeverity.Warning;
case SEVERITY_INFORMATION:
return vscode.DiagnosticSeverity.Information;
case SEVERITY_HINT:
return vscode.DiagnosticSeverity.Hint;
default:
return vscode.DiagnosticSeverity.Warning;
}
}
Loading