Skip to content

Commit eac6fd3

Browse files
committed
Exclude active document from C# completion's related files
1 parent 5fc720a commit eac6fd3

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/lsptoolshost/copilot.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,22 @@ export function registerCopilotExtension(languageServer: RoslynLanguageServer, c
5151
};
5252

5353
relatedAPI.registerRelatedFilesProvider(id, async (uri, _, token) => {
54-
const buildResult = (reports: CopilotRelatedDocumentsReport[], builder?: vscode.Uri[]) => {
54+
const buildResult = (
55+
activeDocumentUri: vscode.Uri,
56+
reports: CopilotRelatedDocumentsReport[],
57+
builder: vscode.Uri[]
58+
) => {
5559
if (reports) {
5660
for (const report of reports) {
5761
if (report._vs_file_paths) {
5862
for (const filePath of report._vs_file_paths) {
59-
builder?.push(vscode.Uri.file(filePath));
63+
// The Roslyn related document service would return the active document as related file to itself
64+
// if the code contains reference to the types defined in the same document. Skip it so the active file
65+
// won't be used as additonal context.
66+
const relatedUri = vscode.Uri.file(filePath);
67+
if (relatedUri.fsPath !== activeDocumentUri.fsPath) {
68+
builder.push(relatedUri);
69+
}
6070
}
6171
}
6272
}
@@ -75,7 +85,7 @@ export function registerCopilotExtension(languageServer: RoslynLanguageServer, c
7585
character: 0,
7686
},
7787
},
78-
async (r) => buildResult(r, relatedFiles),
88+
async (r) => buildResult(uri, r, relatedFiles),
7989
token
8090
);
8191
} catch (e) {

0 commit comments

Comments
 (0)