@@ -246,6 +246,40 @@ export class CppProperties {
246246 }
247247 } ) ;
248248
249+ vscode . workspace . onDidSaveTextDocument ( ( doc : vscode . TextDocument ) => {
250+ // For multi-root, the "onDidSaveTextDocument" will be received once for each project folder.
251+ // To avoid misleading telemetry (for CMake retention) skip if the notifying folder
252+ // is not the same workspace folder of the modified document.
253+ // Exception: if the document does not belong to any of the folders in this workspace,
254+ // getWorkspaceFolder will return undefined and we report this as "outside".
255+ // Even in this case make sure we send the telemetry information only once,
256+ // not for each notifying folder.
257+ const savedDocWorkspaceFolder : vscode . WorkspaceFolder | undefined = vscode . workspace . getWorkspaceFolder ( doc . uri ) ;
258+ const notifyingWorkspaceFolder : vscode . WorkspaceFolder | undefined = vscode . workspace . getWorkspaceFolder ( vscode . Uri . file ( settingsPath ) ) ;
259+ if ( ( ! savedDocWorkspaceFolder && vscode . workspace . workspaceFolders && notifyingWorkspaceFolder === vscode . workspace . workspaceFolders [ 0 ] )
260+ || savedDocWorkspaceFolder === notifyingWorkspaceFolder ) {
261+ let fileType : string | undefined ;
262+ const documentPath : string = doc . uri . fsPath . toLowerCase ( ) ;
263+ if ( documentPath . endsWith ( "cmakelists.txt" ) ) {
264+ fileType = "CMakeLists" ;
265+ } else if ( documentPath . endsWith ( "cmakecache.txt" ) ) {
266+ fileType = "CMakeCache" ;
267+ } else if ( documentPath . endsWith ( ".cmake" ) ) {
268+ fileType = ".cmake" ;
269+ }
270+
271+ if ( fileType ) {
272+ // We consider the changed cmake file as outside if it is not found in any
273+ // of the projects folders.
274+ telemetry . logLanguageServerEvent ( "cmakeFileWrite" ,
275+ {
276+ filetype : fileType ,
277+ outside : ( savedDocWorkspaceFolder === undefined ) . toString ( )
278+ } ) ;
279+ }
280+ }
281+ } ) ;
282+
249283 this . handleConfigurationChange ( ) ;
250284 }
251285
0 commit comments