@@ -9,7 +9,7 @@ import * as nls from 'vscode-nls';
99import * as util from '../common' ;
1010import * as logger from '../logger' ;
1111import * as telemetry from '../telemetry' ;
12- import { ChatContextResult , ProjectContextResult } from './client' ;
12+ import { ChatContextResult } from './client' ;
1313import { getClients } from './extension' ;
1414import { checkDuration } from './utils' ;
1515
@@ -51,7 +51,7 @@ const knownValues: { [Property in keyof ChatContextResult]?: { [id: string]: str
5151 }
5252} ;
5353
54- function formatChatContext ( context : ChatContextResult | ProjectContextResult ) : void {
54+ function formatChatContext ( context : ChatContextResult ) : void {
5555 type KnownKeys = 'language' | 'standardVersion' | 'compiler' | 'targetPlatform' ;
5656 for ( const key in knownValues ) {
5757 const knownKey = key as KnownKeys ;
@@ -68,115 +68,48 @@ export interface ProjectContext {
6868 compiler : string ;
6969 targetPlatform : string ;
7070 targetArchitecture : string ;
71- compilerArguments : Record < string , string > ;
7271}
7372
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 > {
7874 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 ) {
14278 return undefined ;
14379 }
14480
145- const originalStandardVersion = projectContext . result . standardVersion ;
81+ const originalStandardVersion = chatContext . result . standardVersion ;
14682
147- formatChatContext ( projectContext . result ) ;
83+ formatChatContext ( chatContext . result ) ;
14884
14985 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
15691 } ;
15792
158- if ( projectContext . result . language ) {
159- telemetryProperties [ "language" ] = projectContext . result . language ;
93+ if ( result . language ) {
94+ telemetryProperties [ "language" ] = result . language ;
16095 }
161- if ( projectContext . result . compiler ) {
162- telemetryProperties [ "compiler" ] = projectContext . result . compiler ;
96+ if ( result . compiler ) {
97+ telemetryProperties [ "compiler" ] = result . compiler ;
16398 }
164- if ( projectContext . result . standardVersion ) {
165- telemetryProperties [ "standardVersion" ] = projectContext . result . standardVersion ;
99+ if ( result . standardVersion ) {
100+ telemetryProperties [ "standardVersion" ] = result . standardVersion ;
166101 }
167102 else {
168103 if ( originalStandardVersion ) {
169104 telemetryProperties [ "originalStandardVersion" ] = originalStandardVersion ;
170105 }
171106 }
172- if ( projectContext . result . targetPlatform ) {
173- telemetryProperties [ "targetPlatform" ] = projectContext . result . targetPlatform ;
107+ if ( result . targetPlatform ) {
108+ telemetryProperties [ "targetPlatform" ] = result . targetPlatform ;
174109 }
175- if ( projectContext . result . targetArchitecture ) {
176- telemetryProperties [ "targetArchitecture" ] = projectContext . result . targetArchitecture ;
110+ if ( result . targetArchitecture ) {
111+ telemetryProperties [ "targetArchitecture" ] = result . targetArchitecture ;
177112 }
178- telemetryMetrics [ "compilerArgumentCount" ] = projectContext . result . fileContext . compilerArguments . length ;
179- result . compilerArguments = filterCompilerArguments ( projectContext . result . compiler , projectContext . result . fileContext . compilerArguments , context , telemetryProperties ) ;
180113
181114 return result ;
182115 }
0 commit comments