Skip to content

Commit e9e4bb1

Browse files
committed
Remove resource.json
1 parent aef0512 commit e9e4bb1

File tree

6 files changed

+70
-217
lines changed

6 files changed

+70
-217
lines changed

README.md

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Missing CSS support for HTML documents.
1010
- Id attribute completion.
1111
- Supports Zen Coding completion for class and id attributes.
1212
- Scans workspace folder for css files.
13-
- Supports optional resource.json file for fine tuned resource selection.
1413
- Uses [vscode-css-languageservice](https://github.com/Microsoft/vscode-css-languageservice).
1514

1615
## Supported Languages
@@ -22,29 +21,7 @@ Missing CSS support for HTML documents.
2221
- pug
2322
- jade
2423
- handlebars
25-
26-
## Optional resource.json
27-
28-
If a resource.json file is found in the root of the workspace, only files listed in the file will be used for class and id attribute completion.
29-
30-
### Example
31-
32-
```
33-
{
34-
"css": {
35-
"site": [
36-
"node_modules/bootstrap/dist/css/bootstrap.css",
37-
"node_modules/font-awesome/css/font-awesome.css",
38-
"node_modules/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css",
39-
"node_modules/select2/dist/css/select2.css",
40-
"node_modules/select2-bootstrap-theme/dist/select2-bootstrap.css"
41-
],
42-
"style": [
43-
"src/main/resources/main/css/style.css"
44-
]
45-
}
46-
}
47-
```
24+
- php
4825

4926
## Installation
5027

package.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-html-css",
33
"displayName": "HTML CSS Support",
44
"description": "CSS support for HTML documents",
5-
"version": "0.0.36",
5+
"version": "0.1.0",
66
"publisher": "ecmel",
77
"license": "MIT",
88
"homepage": "https://github.com/ecmel/vscode-html-css",
@@ -36,14 +36,6 @@
3636
"onLanguage:jade",
3737
"onLanguage:handlebars"
3838
],
39-
"contributes": {
40-
"jsonValidation": [
41-
{
42-
"fileMatch": "resource.json",
43-
"url": "./schema.json"
44-
}
45-
]
46-
},
4739
"main": "./out/src/extension",
4840
"scripts": {
4941
"vscode:prepublish": "tsc -p ./",

resource.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

schema.json

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/extension.ts

Lines changed: 35 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -39,70 +39,6 @@ class Snippet {
3939
}
4040
}
4141

42-
class StyleServer implements vsc.CompletionItemProvider, vsc.HoverProvider {
43-
44-
private regex = [
45-
/style=["|']([^"^']*$)/i //,
46-
// /<style[^\<\s\S]*\>([^\<]*)/i
47-
];
48-
49-
private convertCompletionList(list: lst.CompletionList): vsc.CompletionList {
50-
let ci: vsc.CompletionItem[] = [];
51-
for (let i = 0; i < list.items.length; i++) {
52-
ci[i] = new vsc.CompletionItem(list.items[i].label);
53-
ci[i].detail = list.items[i].detail;
54-
ci[i].documentation = list.items[i].documentation;
55-
ci[i].filterText = list.items[i].filterText;
56-
ci[i].insertText = list.items[i].insertText;
57-
ci[i].kind = list.items[i].kind;
58-
ci[i].sortText = list.items[i].sortText;
59-
}
60-
return new vsc.CompletionList(ci, list.isIncomplete);
61-
}
62-
63-
private createSnippet(document: vsc.TextDocument, position: vsc.Position): Snippet {
64-
let start = new vsc.Position(0, 0);
65-
let range = new vsc.Range(start, position);
66-
let text = document.getText(range);
67-
68-
let tag = this.regex[0].exec(text);
69-
if (tag) {
70-
return new Snippet('.c {\n' + tag[1], position.character);
71-
}
72-
73-
// tag = this.regex[1].exec(text);
74-
// if (tag) {
75-
// return new Snippet(tag[1], position.character);
76-
// }
77-
78-
return null;
79-
}
80-
81-
provideCompletionItems(document: vsc.TextDocument, position: vsc.Position, token: vsc.CancellationToken): vsc.CompletionList {
82-
let snippet = this.createSnippet(document, position);
83-
84-
if (snippet) {
85-
let result = service.doComplete(snippet.document, snippet.position, snippet.stylesheet);
86-
return this.convertCompletionList(result);
87-
}
88-
return null;
89-
}
90-
91-
resolveCompletionItem(item: vsc.CompletionItem, token: vsc.CancellationToken): vsc.CompletionItem {
92-
return item;
93-
}
94-
95-
provideHover(document: vsc.TextDocument, position: vsc.Position, token: vsc.CancellationToken): vsc.Hover {
96-
let snippet = this.createSnippet(document, position);
97-
98-
if (snippet) {
99-
let result = service.doHover(snippet.document, snippet.position, snippet.stylesheet);
100-
return new vsc.Hover(result.contents);
101-
}
102-
return null;
103-
}
104-
}
105-
10642
class ClassServer implements vsc.CompletionItemProvider {
10743

10844
private regex = [
@@ -188,96 +124,54 @@ function parse(uri: vsc.Uri): void {
188124
export function activate(context: vsc.ExtensionContext) {
189125

190126
if (vsc.workspace.rootPath) {
191-
let resourceJson = path.resolve(vsc.workspace.rootPath, 'resource.json');
192-
let resourceJsonPaths = [];
193-
194-
fs.readFile(resourceJson, 'utf8', function (err: any, data: string) {
195-
let glob = '**/*.css';
196127

197-
if (err) {
198-
vsc.workspace.findFiles(glob, '').then(function (uris: vsc.Uri[]) {
199-
for (let i = 0; i < uris.length; i++) {
200-
parse(uris[i]);
201-
}
202-
});
203-
} else {
204-
let resources = JSON.parse(data);
128+
let glob = '**/*.css';
205129

206-
for (let key in resources.css) {
207-
for (let resource of resources.css[key]) {
208-
let uri = vsc.Uri.file(path.resolve(vsc.workspace.rootPath, resource));
209-
resourceJsonPaths.push(uri.fsPath);
210-
parse(uri);
211-
}
212-
}
130+
vsc.workspace.findFiles(glob, '').then(function (uris: vsc.Uri[]) {
131+
for (let i = 0; i < uris.length; i++) {
132+
parse(uris[i]);
213133
}
134+
});
214135

215-
let watcher = vsc.workspace.createFileSystemWatcher(glob);
216-
217-
watcher.onDidCreate(function (uri: vsc.Uri) {
218-
if (resourceJsonPaths.length === 0 || resourceJsonPaths.indexOf(uri.fsPath) !== -1) {
219-
parse(uri);
220-
}
221-
});
222-
watcher.onDidChange(function (uri: vsc.Uri) {
223-
if (resourceJsonPaths.length === 0 || resourceJsonPaths.indexOf(uri.fsPath) !== -1) {
224-
parse(uri);
225-
}
226-
});
227-
watcher.onDidDelete(function (uri: vsc.Uri) {
228-
delete map[uri.fsPath];
229-
});
136+
let watcher = vsc.workspace.createFileSystemWatcher(glob);
230137

231-
context.subscriptions.push(watcher);
138+
watcher.onDidCreate(function (uri: vsc.Uri) {
139+
parse(uri);
140+
});
141+
watcher.onDidChange(function (uri: vsc.Uri) {
142+
parse(uri);
143+
});
144+
watcher.onDidDelete(function (uri: vsc.Uri) {
145+
delete map[uri.fsPath];
232146
});
233-
}
234-
235-
// let styleServer = new StyleServer();
236147

237-
//context.subscriptions.push(vsc.languages.registerCompletionItemProvider(
238-
// ['html', 'laravel-blade', 'razor', 'vue', 'blade'], styleServer));
239-
//context.subscriptions.push(vsc.languages.registerHoverProvider(
240-
// ['html', 'laravel-blade', 'razor', 'vue', 'blade'], styleServer));
148+
context.subscriptions.push(watcher);
149+
};
241150

242151
let classServer = new ClassServer();
243152

244-
context.subscriptions.push(vsc.languages.registerCompletionItemProvider(
245-
['html', 'laravel-blade', 'razor', 'vue', 'blade', 'pug', 'jade', 'handlebars'], classServer));
153+
context.subscriptions.push(vsc.languages.registerCompletionItemProvider([
154+
'html',
155+
'laravel-blade',
156+
'razor',
157+
'vue',
158+
'blade',
159+
'pug',
160+
'jade',
161+
'handlebars',
162+
'php'
163+
], classServer));
246164

247-
// https://github.com/Microsoft/vscode/issues/13675
248165
let wp = /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\.\"\,\<\>\/\?\s]+)/g;
249166

250-
// context.subscriptions.push(vsc.languages.setLanguageConfiguration('html', {
251-
// wordPattern: wp
252-
// }));
253-
254-
context.subscriptions.push(vsc.languages.setLanguageConfiguration('laravel-blade', {
255-
wordPattern: wp
256-
}));
257-
258-
context.subscriptions.push(vsc.languages.setLanguageConfiguration('razor', {
259-
wordPattern: wp
260-
}));
261-
262-
context.subscriptions.push(vsc.languages.setLanguageConfiguration('vue', {
263-
wordPattern: wp
264-
}));
265-
266-
context.subscriptions.push(vsc.languages.setLanguageConfiguration('blade', {
267-
wordPattern: wp
268-
}));
269-
270-
context.subscriptions.push(vsc.languages.setLanguageConfiguration('pug', {
271-
wordPattern: wp
272-
}));
273-
274-
context.subscriptions.push(vsc.languages.setLanguageConfiguration('jade', {
275-
wordPattern: wp
276-
}));
277-
278-
context.subscriptions.push(vsc.languages.setLanguageConfiguration('handlebars', {
279-
wordPattern: wp
280-
}));
167+
context.subscriptions.push(vsc.languages.setLanguageConfiguration('laravel-blade', { wordPattern: wp }));
168+
context.subscriptions.push(vsc.languages.setLanguageConfiguration('razor', { wordPattern: wp }));
169+
context.subscriptions.push(vsc.languages.setLanguageConfiguration('vue', { wordPattern: wp }));
170+
context.subscriptions.push(vsc.languages.setLanguageConfiguration('blade', { wordPattern: wp }));
171+
context.subscriptions.push(vsc.languages.setLanguageConfiguration('pug', { wordPattern: wp }));
172+
context.subscriptions.push(vsc.languages.setLanguageConfiguration('jade', { wordPattern: wp }));
173+
context.subscriptions.push(vsc.languages.setLanguageConfiguration('handlebars', { wordPattern: wp }));
174+
context.subscriptions.push(vsc.languages.setLanguageConfiguration('php', { wordPattern: wp }));
281175
}
282176

283177
export function deactivate() {

test/test.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<html>
2+
3+
<head>
4+
<style>
5+
.internal {
6+
color: red;
7+
}
8+
9+
.internal-test1 .internal-test2 {
10+
color: red;
11+
}
12+
13+
#internal_id {
14+
color: red;
15+
}
16+
17+
#internal_id-test1 #internal_id-test2 {
18+
color: red;
19+
}
20+
</style>
21+
</head>
22+
23+
<body>
24+
<a href="#" id="external_id" style="color: white;" class="external-test1">TEST</a>
25+
<a href="#" id="internal_id" style="
26+
color: white;
27+
background-color: red;" class="
28+
external
29+
internal
30+
">TEST</a>
31+
</body>
32+
33+
</html>

0 commit comments

Comments
 (0)