Skip to content

Commit a6abee8

Browse files
committed
Added file cache
1 parent 00550ae commit a6abee8

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to the extension will be documented in this file.
55
## [1.9.0] - 2021-01-16
66

77
- Added Clear Cache command.
8+
- Added file cache.
89
- Update documentation.
910

1011
## [1.8.1] - 2021-01-15

src/completion.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class SelectorCompletionItemProvider implements CompletionItemProvider, D
2828

2929
readonly start = new Position(0, 0);
3030
readonly cache = new Map<string, CompletionItem[]>();
31+
readonly files = new Map<string, string>();
3132
readonly watchers = new Map<string, Disposable>();
3233
readonly isRemote = /^https?:\/\//i;
3334
readonly canComplete = /(id|class|className)\s*=\s*("|')(?:(?!\2).)*$/si;
@@ -39,6 +40,7 @@ export class SelectorCompletionItemProvider implements CompletionItemProvider, D
3940
this.watchers.forEach(e => e.dispose());
4041
this.watchers.clear();
4142
this.cache.clear();
43+
this.files.clear();
4244
}
4345

4446
watchFile(path: string, listener: (e: Uri) => any) {
@@ -187,11 +189,17 @@ export class SelectorCompletionItemProvider implements CompletionItemProvider, D
187189

188190
const name = extended[2];
189191
const ext = extname(name) || extname(uri.fsPath);
190-
const file = Uri.file(this.getPath(uri, name, ext));
192+
const path = this.getPath(uri, name, ext);
193+
const file = Uri.file(path);
194+
195+
let text = this.files.get(path);
191196

192197
try {
193-
const content = await workspace.fs.readFile(file);
194-
const text = content.toString();
198+
if (!text) {
199+
text = (await workspace.fs.readFile(file)).toString();
200+
this.files.set(path, text);
201+
this.watchFile(path, () => this.files.delete(path));
202+
}
195203

196204
this.findEmbedded(file, keys, text);
197205

0 commit comments

Comments
 (0)