Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: ideas on caching. #1553

Merged
merged 1 commit into from Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions 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).
49 changes: 49 additions & 0 deletions 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']
];