Skip to content

Commit e8d2b9e

Browse files
authored
Merge pull request #22 from TheColorRed/master
Added Support for Remote files
2 parents bd274e1 + ab65f0d commit e8d2b9e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
"engines": {
1616
"vscode": "^1.10.0"
1717
},
18+
"contributes": {
19+
"configuration": {
20+
"title": "CSS Settings",
21+
"properties": {
22+
"css.remoteStyleSheets": {
23+
"type": "array",
24+
"default": [],
25+
"description": "A list of remote style sheets."
26+
}
27+
}
28+
}
29+
},
1830
"categories": [
1931
"Languages",
2032
"Other"

src/extension.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as lst from 'vscode-languageserver-types';
77
import * as css from 'vscode-css-languageservice';
88
import * as fs from 'fs';
99
import * as path from 'path';
10+
import * as https from 'https';
1011

1112
let service = css.getCSSLanguageService();
1213
let map: { [index: string]: vsc.CompletionItem[]; } = {};
@@ -121,6 +122,25 @@ function parse(uri: vsc.Uri): void {
121122
});
122123
}
123124

125+
function parseRemote(url: string) {
126+
https.get(url, res => {
127+
let styles = '';
128+
res.on('data', d => {
129+
styles += d.toString();
130+
}).on('end', () => {
131+
let doc = lst.TextDocument.create(url, 'css', 1, styles);
132+
let symbols = service.findDocumentSymbols(doc, service.parseStylesheet(doc));
133+
pushSymbols(url, symbols);
134+
});
135+
})
136+
}
137+
138+
function parseRemoteConfig() {
139+
let remoteCssConfig = vsc.workspace.getConfiguration('css');
140+
let urls = remoteCssConfig.get('remoteStyleSheets') as string[];
141+
urls.forEach(url => parseRemote(url));
142+
}
143+
124144
export function activate(context: vsc.ExtensionContext) {
125145

126146
if (vsc.workspace.rootPath) {
@@ -133,6 +153,8 @@ export function activate(context: vsc.ExtensionContext) {
133153
}
134154
});
135155

156+
parseRemoteConfig();
157+
136158
let watcher = vsc.workspace.createFileSystemWatcher(glob);
137159

138160
watcher.onDidCreate(function (uri: vsc.Uri) {
@@ -172,6 +194,9 @@ export function activate(context: vsc.ExtensionContext) {
172194
context.subscriptions.push(vsc.languages.setLanguageConfiguration('jade', { wordPattern: wp }));
173195
context.subscriptions.push(vsc.languages.setLanguageConfiguration('handlebars', { wordPattern: wp }));
174196
context.subscriptions.push(vsc.languages.setLanguageConfiguration('php', { wordPattern: wp }));
197+
context.subscriptions.push(vsc.workspace.onDidChangeConfiguration(e => {
198+
parseRemoteConfig();
199+
}));
175200
}
176201

177202
export function deactivate() {

0 commit comments

Comments
 (0)