@@ -51,12 +51,22 @@ export function registerCopilotExtension(languageServer: RoslynLanguageServer, c
51
51
} ;
52
52
53
53
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
+ ) => {
55
59
if ( reports ) {
56
60
for ( const report of reports ) {
57
61
if ( report . _vs_file_paths ) {
58
62
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
+ }
60
70
}
61
71
}
62
72
}
@@ -75,7 +85,7 @@ export function registerCopilotExtension(languageServer: RoslynLanguageServer, c
75
85
character : 0 ,
76
86
} ,
77
87
} ,
78
- async ( r ) => buildResult ( r , relatedFiles ) ,
88
+ async ( r ) => buildResult ( uri , r , relatedFiles ) ,
79
89
token
80
90
) ;
81
91
} catch ( e ) {
0 commit comments