@@ -9,7 +9,7 @@ import * as nls from 'vscode-nls';
9
9
import * as util from '../common' ;
10
10
import * as logger from '../logger' ;
11
11
import * as telemetry from '../telemetry' ;
12
- import { ChatContextResult , ProjectContextResult } from './client' ;
12
+ import { ChatContextResult } from './client' ;
13
13
import { getClients } from './extension' ;
14
14
import { checkDuration } from './utils' ;
15
15
@@ -51,7 +51,7 @@ const knownValues: { [Property in keyof ChatContextResult]?: { [id: string]: str
51
51
}
52
52
} ;
53
53
54
- function formatChatContext ( context : ChatContextResult | ProjectContextResult ) : void {
54
+ function formatChatContext ( context : ChatContextResult ) : void {
55
55
type KnownKeys = 'language' | 'standardVersion' | 'compiler' | 'targetPlatform' ;
56
56
for ( const key in knownValues ) {
57
57
const knownKey = key as KnownKeys ;
@@ -68,115 +68,48 @@ export interface ProjectContext {
68
68
compiler : string ;
69
69
targetPlatform : string ;
70
70
targetArchitecture : string ;
71
- compilerArguments : Record < string , string > ;
72
71
}
73
72
74
- export function getCompilerArgumentFilterMap ( compiler : string , context : { flags : Record < string , unknown > } ) : Record < string , string > | undefined {
75
- // The copilotcppXXXCompilerArgumentFilters are maps.
76
- // The keys are regex strings and the values, if not empty, are the prompt text to use when no arguments are found.
77
- let filterMap : Record < string , string > | undefined ;
73
+ export async function getProjectContext ( uri : vscode . Uri , context : { flags : Record < string , unknown > } , cancellationToken : vscode . CancellationToken , telemetryProperties : Record < string , string > , telemetryMetrics : Record < string , number > ) : Promise < ProjectContext | undefined > {
78
74
try {
79
- switch ( compiler ) {
80
- case MSVC :
81
- if ( context . flags . copilotcppMsvcCompilerArgumentFilter !== undefined ) {
82
- filterMap = JSON . parse ( context . flags . copilotcppMsvcCompilerArgumentFilter as string ) ;
83
- }
84
- break ;
85
- case Clang :
86
- if ( context . flags . copilotcppClangCompilerArgumentFilter !== undefined ) {
87
- filterMap = JSON . parse ( context . flags . copilotcppClangCompilerArgumentFilter as string ) ;
88
- }
89
- break ;
90
- case GCC :
91
- if ( context . flags . copilotcppGccCompilerArgumentFilter !== undefined ) {
92
- filterMap = JSON . parse ( context . flags . copilotcppGccCompilerArgumentFilter as string ) ;
93
- }
94
- break ;
95
- }
96
- }
97
- catch {
98
- // Intentionally swallow any exception.
99
- }
100
- return filterMap ;
101
- }
102
-
103
- function filterCompilerArguments ( compiler : string , compilerArguments : string [ ] , context : { flags : Record < string , unknown > } , telemetryProperties : Record < string , string > ) : Record < string , string > {
104
- const filterMap = getCompilerArgumentFilterMap ( compiler , context ) ;
105
- if ( filterMap === undefined ) {
106
- return { } ;
107
- }
108
-
109
- const combinedArguments = compilerArguments . join ( ' ' ) ;
110
- const result : Record < string , string > = { } ;
111
- const filteredCompilerArguments : string [ ] = [ ] ;
112
- for ( const key in filterMap ) {
113
- if ( ! key ) {
114
- continue ;
115
- }
116
- const filter = new RegExp ( key , 'g' ) ;
117
- const filtered = combinedArguments . match ( filter ) ;
118
- if ( filtered ) {
119
- filteredCompilerArguments . push ( ...filtered ) ;
120
- result [ key ] = filtered [ filtered . length - 1 ] ;
121
- }
122
- }
123
-
124
- if ( filteredCompilerArguments . length > 0 ) {
125
- // Telemetry to learn about the argument distribution. The filtered arguments are expected to be non-PII.
126
- telemetryProperties [ "filteredCompilerArguments" ] = filteredCompilerArguments . join ( ',' ) ;
127
- }
128
-
129
- const filters = Object . keys ( filterMap ) . filter ( filter => ! ! filter ) . join ( ',' ) ;
130
- if ( filters ) {
131
- telemetryProperties [ "filters" ] = filters ;
132
- }
133
-
134
- return result ;
135
- }
136
-
137
- export async function getProjectContext ( uri : vscode . Uri , context : { flags : Record < string , unknown > } , telemetryProperties : Record < string , string > , telemetryMetrics : Record < string , number > ) : Promise < ProjectContext | undefined > {
138
- try {
139
- const projectContext = await checkDuration < ProjectContextResult | undefined > ( async ( ) => await getClients ( ) ?. ActiveClient ?. getProjectContext ( uri ) ?? undefined ) ;
140
- telemetryMetrics [ "projectContextDuration" ] = projectContext . duration ;
141
- if ( ! projectContext . result ) {
75
+ const chatContext = await checkDuration < ChatContextResult | undefined > ( async ( ) => await getClients ( ) ?. ActiveClient ?. getChatContext ( uri , cancellationToken ) ?? undefined ) ;
76
+ telemetryMetrics [ "projectContextDuration" ] = chatContext . duration ;
77
+ if ( ! chatContext . result ) {
142
78
return undefined ;
143
79
}
144
80
145
- const originalStandardVersion = projectContext . result . standardVersion ;
81
+ const originalStandardVersion = chatContext . result . standardVersion ;
146
82
147
- formatChatContext ( projectContext . result ) ;
83
+ formatChatContext ( chatContext . result ) ;
148
84
149
85
const result : ProjectContext = {
150
- language : projectContext . result . language ,
151
- standardVersion : projectContext . result . standardVersion ,
152
- compiler : projectContext . result . compiler ,
153
- targetPlatform : projectContext . result . targetPlatform ,
154
- targetArchitecture : projectContext . result . targetArchitecture ,
155
- compilerArguments : { }
86
+ language : chatContext . result . language ,
87
+ standardVersion : chatContext . result . standardVersion ,
88
+ compiler : chatContext . result . compiler ,
89
+ targetPlatform : chatContext . result . targetPlatform ,
90
+ targetArchitecture : chatContext . result . targetArchitecture
156
91
} ;
157
92
158
- if ( projectContext . result . language ) {
159
- telemetryProperties [ "language" ] = projectContext . result . language ;
93
+ if ( result . language ) {
94
+ telemetryProperties [ "language" ] = result . language ;
160
95
}
161
- if ( projectContext . result . compiler ) {
162
- telemetryProperties [ "compiler" ] = projectContext . result . compiler ;
96
+ if ( result . compiler ) {
97
+ telemetryProperties [ "compiler" ] = result . compiler ;
163
98
}
164
- if ( projectContext . result . standardVersion ) {
165
- telemetryProperties [ "standardVersion" ] = projectContext . result . standardVersion ;
99
+ if ( result . standardVersion ) {
100
+ telemetryProperties [ "standardVersion" ] = result . standardVersion ;
166
101
}
167
102
else {
168
103
if ( originalStandardVersion ) {
169
104
telemetryProperties [ "originalStandardVersion" ] = originalStandardVersion ;
170
105
}
171
106
}
172
- if ( projectContext . result . targetPlatform ) {
173
- telemetryProperties [ "targetPlatform" ] = projectContext . result . targetPlatform ;
107
+ if ( result . targetPlatform ) {
108
+ telemetryProperties [ "targetPlatform" ] = result . targetPlatform ;
174
109
}
175
- if ( projectContext . result . targetArchitecture ) {
176
- telemetryProperties [ "targetArchitecture" ] = projectContext . result . targetArchitecture ;
110
+ if ( result . targetArchitecture ) {
111
+ telemetryProperties [ "targetArchitecture" ] = result . targetArchitecture ;
177
112
}
178
- telemetryMetrics [ "compilerArgumentCount" ] = projectContext . result . fileContext . compilerArguments . length ;
179
- result . compilerArguments = filterCompilerArguments ( projectContext . result . compiler , projectContext . result . fileContext . compilerArguments , context , telemetryProperties ) ;
180
113
181
114
return result ;
182
115
}
0 commit comments