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