@@ -24,6 +24,7 @@ import { PersistentFolderState } from './persistentState';
2424import { CppSettings , OtherSettings } from './settings' ;
2525import { SettingsPanel } from './settingsPanel' ;
2626import { ConfigurationType , getUI } from './ui' ;
27+ import { Deferral } from './utils' ;
2728import escapeStringRegExp = require( 'escape-string-regexp' ) ;
2829
2930nls . config ( { messageFormat : nls . MessageFormat . bundle , bundleFormat : nls . BundleFormat . standalone } ) ( ) ;
@@ -279,13 +280,13 @@ export class CppProperties {
279280
280281 vscode . workspace . onDidChangeTextDocument ( ( e ) => {
281282 if ( e . document . uri . fsPath === settingsPath ) {
282- void this . handleSquiggles ( ) . catch ( logAndReturn . undefined ) ;
283+ this . handleSquiggles ( e . document ) ;
283284 }
284285 } ) ;
285286
286287 vscode . workspace . onDidOpenTextDocument ( document => {
287288 if ( document . uri . fsPath === settingsPath ) {
288- void this . handleSquiggles ( ) . catch ( logAndReturn . undefined ) ;
289+ this . handleSquiggles ( document ) ;
289290 }
290291 } ) ;
291292
@@ -352,7 +353,7 @@ export class CppProperties {
352353
353354 private onSelectionChanged ( ) : void {
354355 this . selectionChanged . fire ( this . CurrentConfigurationIndex ) ;
355- void this . handleSquiggles ( ) . catch ( logAndReturn . undefined ) ;
356+ this . handleSquiggles ( ) ;
356357 }
357358
358359 private onCompileCommandsChanged ( path : string ) : void {
@@ -1590,8 +1591,9 @@ export class CppProperties {
15901591 if ( firstParse ) {
15911592 // Check documents that are already open since no event will fire for them.
15921593 const fsPath = this . propertiesFile . fsPath ;
1593- if ( vscode . workspace . textDocuments . some ( doc => doc . uri . fsPath === fsPath ) ) {
1594- void this . handleSquiggles ( ) . catch ( logAndReturn . undefined ) ;
1594+ const document = vscode . workspace . textDocuments . find ( doc => doc . uri . fsPath === fsPath ) ;
1595+ if ( document ) {
1596+ this . handleSquiggles ( document ) ;
15951597 }
15961598 }
15971599 } catch ( errJS ) {
@@ -1859,7 +1861,22 @@ export class CppProperties {
18591861 return errorMsg ;
18601862 }
18611863
1862- private async handleSquiggles ( ) : Promise < void > {
1864+ private lastConfigurationVersion : number = 0 ;
1865+ private handleSquigglesDeferral : Deferral | undefined ;
1866+
1867+ private handleSquiggles ( doc ?: vscode . TextDocument ) : void {
1868+ // When the active config changes, we don't pass the doc in since the version would not have changed.
1869+ if ( doc ?. version !== this . lastConfigurationVersion ) {
1870+ this . lastConfigurationVersion = doc ?. version ?? 0 ;
1871+ this . handleSquigglesDeferral ?. cancel ( ) ;
1872+ this . handleSquigglesDeferral = new Deferral ( ( ) => void this . handleSquigglesImpl ( ) . catch ( logAndReturn . undefined ) , 1000 ) ;
1873+ }
1874+ }
1875+
1876+ /**
1877+ * Not to be called directly. Use the `handleSquiggles` method instead which will debounce the calls.
1878+ */
1879+ private async handleSquigglesImpl ( ) : Promise < void > {
18631880 if ( ! this . propertiesFile ) {
18641881 return ;
18651882 }
0 commit comments