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

display '\n' separators & artifact text description to result locations #413

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
27 changes: 18 additions & 9 deletions src/panel/details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as React from 'react';
import { Component, Fragment } from 'react';
import ReactMarkdown from 'react-markdown';
import { Location, Result, StackFrame } from 'sarif';
import { parseArtifactLocation, parseLocation, decodeFileUri } from '../shared';
import { parseArtifactLocation, parseLocation, decodeFileUri, parseMessage } from '../shared';
import './details.scss';
import './index.scss';
import { postSelectArtifact, postSelectLog } from './indexStore';
Expand Down Expand Up @@ -83,14 +83,23 @@ interface DetailsProps { result: Result, height: IObservableValue<number> }
<span>Locations</span> <span>
{result.locations?.map((loc, i) => {
const ploc = loc.physicalLocation;
const [uri, _] = parseArtifactLocation(result, ploc?.artifactLocation);
return <a key={i} href="#" className="ellipsis" title={uri}
onClick={e => {
e.preventDefault(); // Cancel # nav.
postSelectArtifact(result, ploc);
}}>
{uri?.file ?? '-'}
</a>;
const artifactLocation = ploc?.artifactLocation;
const artifactDescription = artifactLocation?.description;
let artifactTextDescription = '';
if (artifactDescription) {
[artifactTextDescription, ] = parseMessage(result, artifactDescription);
}
const [uri, ] = parseArtifactLocation(result, artifactLocation);

return <>
<a key={i} href="#" className="ellipsis" title={uri}
onClick={e => {
e.preventDefault(); // Cancel # nav.
postSelectArtifact(result, ploc);
}}>
{uri?.file ?? '-'}
</a>&nbsp;{artifactTextDescription ?? ''}<br/>
</>;
}) ?? <span>—</span>}
</span>
<span>Log</span> <a href="#" title={decodeFileUri(result._log._uri)}
Expand Down
13 changes: 9 additions & 4 deletions src/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { ArtifactLocation, Location, Log, ReportingDescriptor, Result } from 'sarif';
import { ArtifactLocation, Location, Log, ReportingDescriptor, Result, Message } from 'sarif';
import urlJoin from 'url-join';
import { URI } from 'vscode-uri';

Expand Down Expand Up @@ -122,9 +122,7 @@ export function augmentLog(log: Log, rules?: Map<string, ReportingDescriptor>) {
?? toolComponent?.rules?.find(rule => rule.id === result.ruleId)
?? getDriverlessRule(result.ruleId);

const message = result._rule?.messageStrings?.[result.message.id ?? -1] ?? result.message;
result._message = format(message.text || result.message?.text, result.message.arguments) ?? '—';
result._markdown = format(message.markdown || result.message?.markdown, result.message.arguments); // No '—', leave undefined if empty.
[result._message, result._markdown] = parseMessage(result, result.message);

result.level = effectiveLevel(result);
result.baselineState = result.baselineState ?? 'new';
Expand Down Expand Up @@ -180,6 +178,13 @@ export function parseLocation(result: Result, loc?: Location) {
return { message, uri, uriContent, region };
}

export function parseMessage(result: Result, message: Message): [string, string | undefined] {
const _message = result._rule?.messageStrings?.[message.id ?? -1] ?? message;
const textMessage = format(_message.text, message.arguments) ?? '—';
const markdownMessage = format(_message.markdown, message.arguments); // No '—', leave undefined if empty.
return [textMessage, markdownMessage]
}

// Improve: `result` purely used for `_run.artifacts`.
export function parseArtifactLocation(result: Result, anyArtLoc: ArtifactLocation | undefined) {
if (!anyArtLoc) return [undefined, undefined];
Expand Down