-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: only trigger validations for persisted files
fixes #185
- Loading branch information
Showing
3 changed files
with
40 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/vscode-dependencies-validation/src/diagnostics/isNewPersistedFileVersion.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const pathToVersion: Map<string, number> = new Map(); | ||
|
||
/** | ||
* Helper to identify when a newly persisted document in vscode represents | ||
* the latest version. | ||
* | ||
* This is needed to help identify which of the **four** events `onDidChangeTextDocument` | ||
* which happen on every key click is the "real" trigger for updating the diagnostics | ||
*/ | ||
export function isNewPersistedFileVersion( | ||
path: string, | ||
newVer: number | ||
): boolean { | ||
if (pathToVersion.has(path)) { | ||
const oldVer = pathToVersion.get(path)!; | ||
if (newVer > oldVer) { | ||
pathToVersion.set(path, newVer); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
pathToVersion.set(path, newVer); | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters