Skip to content

Commit c115078

Browse files
authored
Fix Test Explorer issues (#2291)
This PR fixes two issues. Firstly, Q# code used in chat contexts was showing up in the Test Explorer as additional documents (and possibly other locations). It seems to use a few schemes all starting with 'chat', so excluding those. Secondly, the location given for failing tests was often wrong, and falling back to the first 'related' location span when we're also using that for the document uri anyway resolves that issue. (And seems like the correct thing to do anyway).
1 parent cd5c2e3 commit c115078

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

vscode/src/common.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export function isQsharpDocument(document: TextDocument): boolean {
2121
document.languageId === qsharpLanguageId &&
2222
(Utils.extname(document.uri) === ".qs" || document.isUntitled) &&
2323
document.uri.scheme !== "git" &&
24-
document.uri.scheme !== "pr"
24+
document.uri.scheme !== "pr" &&
25+
// The Copilot Chat window also creates documents with various schemes that start
26+
// with "chat", such as "chat-editing-text-model" and others.
27+
!document.uri.scheme.startsWith("chat")
2528
);
2629
}
2730

vscode/src/language-service/testExplorer.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,26 @@ export function startTestDiscovery(
9393
if (msg.detail.success) {
9494
run.passed(testCase);
9595
} else {
96-
const failureLocation =
96+
const failureLocationUri =
9797
msg.detail?.value?.uri ||
9898
(msg.detail?.value?.related &&
9999
msg.detail.value.related[0].location?.source) ||
100100
null;
101+
// If there was no 'uri' on 'value', then the 'range' on 'value' tends to be unreliable too,
102+
// so use the span on the first related location if available.
103+
const failureLocationRange =
104+
!msg.detail?.value?.uri && msg.detail?.value?.related?.[0]
105+
? msg.detail.value.related[0].location.span
106+
: msg.detail.value.range;
101107

102108
const message: vscode.TestMessage = {
103109
message: msg.detail.value.message,
104110
location:
105-
failureLocation === null
111+
failureLocationUri === null
106112
? undefined
107113
: {
108-
range: toVsCodeRange(msg.detail.value.range),
109-
uri: vscode.Uri.parse(failureLocation),
114+
range: toVsCodeRange(failureLocationRange),
115+
uri: vscode.Uri.parse(failureLocationUri),
110116
},
111117
};
112118
run.failed(testCase, message);

0 commit comments

Comments
 (0)