From e0b704e98a1f566e00b4799f598b66d486844d18 Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Fri, 20 Aug 2021 10:04:19 +0200 Subject: [PATCH] dev: ideas on caching. --- packages/cspell-lib/docs/cache.md | 9 ++++ packages/cspell-lib/src/Cache/cspell.cache.ts | 49 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 packages/cspell-lib/docs/cache.md create mode 100644 packages/cspell-lib/src/Cache/cspell.cache.ts diff --git a/packages/cspell-lib/docs/cache.md b/packages/cspell-lib/docs/cache.md new file mode 100644 index 00000000000..1a447d5b486 --- /dev/null +++ b/packages/cspell-lib/docs/cache.md @@ -0,0 +1,9 @@ +# Caching Spell Checking Results + +Spell checking a large project can take a lot of time. + +In most cases, the files do not change from run to run, so the results are not expected to change. + +The idea is to cache the results of the previous runs and use those same results if nothing has changed. + +This is also related to ignoring known issues, see [Feature: Support Known Spelling Issues · Issue #1297 · streetsidesoftware/cspell](https://github.com/streetsidesoftware/cspell/issues/1297). diff --git a/packages/cspell-lib/src/Cache/cspell.cache.ts b/packages/cspell-lib/src/Cache/cspell.cache.ts new file mode 100644 index 00000000000..be19e7d9c79 --- /dev/null +++ b/packages/cspell-lib/src/Cache/cspell.cache.ts @@ -0,0 +1,49 @@ +/** + * Proposed CSpell Cache file. + * To be stored at `./.cspell/cache/cache.json` + */ + +export interface CSpellCache { + version: Version; + signature: Hash; + files: CachedFile[]; +} + +type Version = '0.1'; + +/** + * Hash used. Starts with hash id. i.e. `sha1-` or `sha512-`. + */ +type Hash = string; + +type UriRelPath = string; + +enum IssueCode { + UnknownWord = 1 << 0, + ForbiddenWord = 1 << 1, + KnownIssue = 1 << 2, +} + +interface CachedFile { + hash: Hash; + path: UriRelPath; + issues: Issue[]; +} + +type Issue = IssueEntry | IssueLine; + +interface IssueEntry { + line: number; + character: number; + code: IssueCode; + text: string; + len: number; +} + +type IssueLine = [ + line: IssueEntry['line'], + character: IssueEntry['character'], + code: IssueEntry['code'], + text: IssueEntry['text'], + len: IssueEntry['len'] +];