Skip to content

Commit 5b806eb

Browse files
committed
Refactoring
1 parent 198f2f1 commit 5b806eb

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/extension.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ export class ClassCompletionItemProvider implements CompletionItemProvider {
3737
});
3838
}
3939

40+
fetchRemote(key: string): Thenable<string> {
41+
return new Promise(resolve => {
42+
const items = new Map<string, CompletionItem>();
43+
44+
fetch(key).then(res => {
45+
if (res.ok) {
46+
res.text().then(text => {
47+
this.parseTextToItems(text, items);
48+
this.cache.set(key, items);
49+
resolve(key);
50+
}, () => resolve(NONE));
51+
} else {
52+
this.cache.set(key, items);
53+
resolve(key);
54+
}
55+
}, () => resolve(NONE));
56+
});
57+
}
58+
4059
fetchStyleSheet(key: string): Thenable<string> {
4160
return new Promise(resolve => {
4261
if (key === NONE) {
@@ -47,20 +66,7 @@ export class ClassCompletionItemProvider implements CompletionItemProvider {
4766
if (items) {
4867
resolve(key);
4968
} else if (this.isRemote.test(key)) {
50-
const items = new Map<string, CompletionItem>();
51-
52-
fetch(key).then(res => {
53-
if (res.ok) {
54-
res.text().then(text => {
55-
this.parseTextToItems(text, items);
56-
this.cache.set(key, items);
57-
resolve(key);
58-
}, () => resolve(NONE));
59-
} else {
60-
this.cache.set(key, items);
61-
resolve(key);
62-
}
63-
}, () => resolve(NONE));
69+
this.fetchRemote(key).then(key => resolve(key));
6470
} else {
6571
resolve(NONE);
6672
}

0 commit comments

Comments
 (0)