Skip to content

Commit 613cf03

Browse files
author
Ryan Naddy
committed
Added Support for Remote files
1 parent bd274e1 commit 613cf03

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-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: 26 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,26 @@ 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+
console.log('parse remote');
140+
let remoteCssConfig = vsc.workspace.getConfiguration('css');
141+
let urls = remoteCssConfig.get('remoteStyleSheets') as string[];
142+
urls.forEach(url => parseRemote(url));
143+
}
144+
124145
export function activate(context: vsc.ExtensionContext) {
125146

126147
if (vsc.workspace.rootPath) {
@@ -133,6 +154,8 @@ export function activate(context: vsc.ExtensionContext) {
133154
}
134155
});
135156

157+
parseRemoteConfig();
158+
136159
let watcher = vsc.workspace.createFileSystemWatcher(glob);
137160

138161
watcher.onDidCreate(function (uri: vsc.Uri) {
@@ -172,6 +195,9 @@ export function activate(context: vsc.ExtensionContext) {
172195
context.subscriptions.push(vsc.languages.setLanguageConfiguration('jade', { wordPattern: wp }));
173196
context.subscriptions.push(vsc.languages.setLanguageConfiguration('handlebars', { wordPattern: wp }));
174197
context.subscriptions.push(vsc.languages.setLanguageConfiguration('php', { wordPattern: wp }));
198+
context.subscriptions.push(vsc.workspace.onDidChangeConfiguration(e => {
199+
parseRemoteConfig();
200+
}));
175201
}
176202

177203
export function deactivate() {

0 commit comments

Comments
 (0)