Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/workbench/components/errorComparison.tsx
13399 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as mobxlite from 'mobx-react-lite';
7
import * as React from 'react';
8
import { EvaluationError } from '../stores/amlResults';
9
import { ISimulationTest } from '../stores/simulationTestsProvider';
10
import { DiffEditor } from './diffEditor';
11
12
export const ErrorComparison = mobxlite.observer(
13
({ test }: { test: ISimulationTest }) => {
14
const errorsOnlyInBefore = test.errorsOnlyInBefore;
15
const errorsOnlyInAfter = test.errorsOnlyInAfter;
16
if (
17
!errorsOnlyInBefore ||
18
!errorsOnlyInAfter ||
19
!errorsOnlyInBefore.length ||
20
!errorsOnlyInAfter.length
21
) {
22
return null;
23
}
24
25
const [expanded, setExpanded] = React.useState(false);
26
27
return (
28
<div className='error-comparison'>
29
{'\n'}
30
<div className='title' onClick={() => setExpanded(!expanded)}>
31
{expanded ? '▼' : '▶'} Error Comparison
32
</div>{' '}
33
{!expanded ? null : (
34
<div>
35
<p>
36
<span className='category'>{`- Source: `}</span>
37
{errorsOnlyInBefore[0].tool}
38
</p>
39
<p>
40
<span className='category'>{`- Number of errors that appear in the diagnostics strictly only before the change: `}</span>
41
{errorsOnlyInBefore.length}
42
</p>
43
<p>
44
<span className='category'>{`- Number of errors that appear in the diagnostics strictly only after the change: `}</span>
45
{errorsOnlyInAfter.length}
46
</p>
47
<span className='category'>{`- Diff of errors before and after : `}</span>
48
<DiffEditor
49
original={errorText(errorsOnlyInBefore)}
50
modified={errorText(errorsOnlyInAfter)}
51
languageId='plaintext'
52
/>
53
</div>
54
)}
55
</div>
56
);
57
}
58
);
59
60
function errorText(errors: EvaluationError[]) {
61
let errorText = ``;
62
for (const error of errors) {
63
errorText +=
64
[
65
`- Start Line : ${error.startLine}`,
66
`- Start Column : ${error.startColumn}`,
67
`- End line : ${error.endLine}`,
68
`- End column : ${error.endColumn}`,
69
`- Message : ${error.message}`,
70
].join('\n') + '\n\n';
71
}
72
return errorText;
73
}
74
75