Skip to content

Commit ada4a0b

Browse files
committed
fixed word range
1 parent ffb76de commit ada4a0b

File tree

5 files changed

+79
-66
lines changed

5 files changed

+79
-66
lines changed

CHANGELOG.md

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,140 +2,141 @@
22

33
All notable changes to the extension will be documented in this file.
44

5-
## [2.0.1] - 2023-12-31
5+
## [2.0.2] - 2024-01-01
66

7-
- Go to definition support.
8-
- Ported to custom parser.
7+
- Go to definition support
8+
- Ported to custom parser
9+
- Fixed word range for selectors
910

1011
## [1.14.1] - 2023-12-28
1112

12-
- Added glob support for local files.
13-
- Initial support for lit css.
14-
- Match on patterns with a colon in addition to equals.
15-
- Ported to rollup & fast-glob.
16-
- Updated dependencies.
13+
- Added glob support for local files
14+
- Initial support for lit css
15+
- Match on patterns with a colon in addition to equals
16+
- Ported to rollup & fast-glob
17+
- Updated dependencies
1718

1819
## [1.13.1] - 2022-07-31
1920

20-
- Updated sponsor field.
21+
- Updated sponsor field
2122

2223
## [1.13.0] - 2022-06-13
2324

24-
- Added sponsor field.
25+
- Added sponsor field
2526

2627
## [1.12.2] - 2022-05-05
2728

28-
- Update dependencies.
29+
- Update dependencies
2930

3031
## [1.11.0] - 2022-02-06
3132

32-
- Update dependencies.
33-
- Added source file name to completion list.
33+
- Update dependencies
34+
- Added source file name to completion list
3435

3536
## [1.10.2] - 2021-02-10
3637

37-
- Update dependencies.
38+
- Update dependencies
3839

3940
## [1.9.1] - 2021-01-17
4041

41-
- Update documentation.
42+
- Update documentation
4243

4344
## [1.9.0] - 2021-01-16
4445

45-
- Added Clear Cache command.
46-
- Added file cache.
47-
- Update documentation.
46+
- Added Clear Cache command
47+
- Added file cache
48+
- Update documentation
4849

4950
## [1.8.1] - 2021-01-15
5051

51-
- Added ${fileBasenameNoExtension} setting variable.
52+
- Added ${fileBasenameNoExtension} setting variable
5253

5354
## [1.8.0] - 2021-01-11
5455

55-
- Added validate command.
56-
- Allow multi level inheritance.
56+
- Added validate command
57+
- Allow multi level inheritance
5758

5859
## [1.7.2] - 2021-01-10
5960

60-
- Update internals.
61+
- Update internals
6162

6263
## [1.7.1] - 2021-01-09
6364

64-
- Update documentation.
65+
- Update documentation
6566

6667
## [1.7.0] - 2021-01-09
6768

68-
- Removed validation.
69+
- Removed validation
6970

7071
## [1.6.3] - 2021-01-07
7172

72-
- Added Handlebars inheritance (https://jknack.github.io/handlebars.java/reuse.html).
73-
- Update documentation.
74-
- Internal refactoring.
73+
- Added Handlebars inheritance (https://jknack.github.io/handlebars.java/reuse.html)
74+
- Update documentation
75+
- Internal refactoring
7576

7677
## [1.6.2] - 2021-01-04
7778

78-
- Handle file watcher create events.
79-
- Update documentation.
79+
- Handle file watcher create events
80+
- Update documentation
8081

8182
## [1.6.1] - 2020-12-31
8283

83-
- Update documentation.
84-
- Update dependencies.
84+
- Update documentation
85+
- Update dependencies
8586

8687
## [1.6.0] - 2020-12-29
8788

88-
- Updated settings.
89+
- Updated settings
8990

9091
## [1.5.0] - 2020-12-28
9192

92-
- Added `css.validation` setting.
93+
- Added `css.validation` setting
9394

9495
## [1.4.5] - 2020-12-28
9596

96-
- Update documentation.
97+
- Update documentation
9798

9899
## [1.4.4] - 2020-12-27
99100

100-
- Fixed regex.
101+
- Fixed regex
101102

102103
## [1.4.3] - 2020-12-27
103104

104-
- Fixed regex.
105+
- Fixed regex
105106

106107
## [1.4.2] - 2020-12-26
107108

108-
- Update documentation.
109+
- Update documentation
109110

110111
## [1.4.1] - 2020-12-26
111112

112-
- Validates startup and newly opened documents.
113+
- Validates startup and newly opened documents
113114

114115
## [1.4.0] - 2020-12-26
115116

116-
- Added validation.
117-
- Added @extends('base') tag for inheritance.
118-
- Added integration test.
117+
- Added validation
118+
- Added @extends('base') tag for inheritance
119+
- Added integration test
119120

120121
## [1.3.3] - 2020-12-22
121122

122-
- Fixed watcher bug.
123-
- Fixed cleanup.
123+
- Fixed watcher bug
124+
- Fixed cleanup
124125

125126
## [1.3.2] - 2020-12-22
126127

127-
- Update documentation.
128+
- Update documentation
128129

129130
## [1.3.1] - 2020-12-22
130131

131-
- Unified path handling.
132-
- Fixed recursion bug for template inheritance.
132+
- Unified path handling
133+
- Fixed recursion bug for template inheritance
133134

134135
## [1.3.0] - 2020-12-21
135136

136-
- Update documentation.
137+
- Update documentation
137138
- Update to VS Code 1.52
138139

139140
## [1.2.5] - 2020-12-20
140141

141-
- Added initial template inheritance support for Twig and Mustache like template engines.
142+
- Added initial template inheritance support for Twig and Mustache like template engines

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
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 Intellisense for HTML",
5-
"version": "2.0.1",
5+
"version": "2.0.2",
66
"license": "MIT",
77
"publisher": "ecmel",
88
"author": {

src/extension.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ export function activate(context: ExtensionContext) {
2121
context.subscriptions.push(
2222
languages.registerCompletionItemProvider(enabledLanguages, provider),
2323
languages.registerDefinitionProvider(enabledLanguages, provider),
24-
workspace.onDidChangeTextDocument((event) => {
25-
const uri = event.document.uri;
26-
invalidate(uri.toString());
27-
validations.delete(uri);
28-
}),
24+
workspace.onDidSaveTextDocument((document) =>
25+
invalidate(document.uri.toString())
26+
),
2927
workspace.onDidCloseTextDocument((document) =>
3028
validations.delete(document.uri)
3129
),
30+
workspace.onDidChangeTextDocument((event) =>
31+
validations.delete(event.document.uri)
32+
),
3233
commands.registerCommand("vscode-html-css.validate", async () => {
3334
const editor = window.activeTextEditor;
3435
if (editor) {

src/provider.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { Style, StyleType, parse } from "./parser";
3131
const start = new Position(0, 0);
3232
const cache = new Map<string, Style[]>();
3333
const isRemote = /^https?:\/\//i;
34-
const wordRange = /-?[_a-zA-Z]+[_a-zA-Z0-9-]*/;
34+
const wordRange = /[_a-zA-Z0-9-]+/;
3535
const findSelector = /([^(\[{}\])\s]+)(?![^(\[{]*[}\])])/gi;
3636
const findAttribute = /(class|className)\s*[=:]\s*(["'])(.*?)\2/gis;
3737
const canComplete = /(id|class|className)\s*[=:]\s*(["'])(?:.(?!\2))*$/is;
@@ -96,7 +96,7 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
9696
}
9797

9898
private async getCompletionMap(document: TextDocument, type: StyleType) {
99-
const items = new Map<string, CompletionItem>();
99+
const map = new Map<string, CompletionItem>();
100100
const styles = await this.getStyles(document);
101101
for (const value of styles.values()) {
102102
for (const style of value) {
@@ -107,16 +107,26 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
107107
? CompletionItemKind.Value
108108
: CompletionItemKind.Enum
109109
);
110-
items.set(style.selector, item);
110+
map.set(style.selector, item);
111111
}
112112
}
113113
}
114-
return items;
114+
return map;
115115
}
116116

117-
private async getCompletionItems(document: TextDocument, type: StyleType) {
118-
const items = await this.getCompletionMap(document, type);
119-
return [...items.values()];
117+
private async getCompletionItems(
118+
document: TextDocument,
119+
position: Position,
120+
type: StyleType
121+
) {
122+
const map = await this.getCompletionMap(document, type);
123+
const range = document.getWordRangeAtPosition(position, wordRange);
124+
const items = [];
125+
for (const item of map.values()) {
126+
item.range = range;
127+
items.push(item);
128+
}
129+
return items;
120130
}
121131

122132
provideCompletionItems(
@@ -134,6 +144,7 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
134144
resolve(
135145
this.getCompletionItems(
136146
document,
147+
position,
137148
match[1] === "id" ? StyleType.ID : StyleType.CLASS
138149
)
139150
);
@@ -186,9 +197,9 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
186197
}
187198

188199
async validate(document: TextDocument) {
189-
const text = document.getText();
190200
const diagnostics: Diagnostic[] = [];
191-
const styles = await this.getCompletionMap(document, StyleType.CLASS);
201+
const map = await this.getCompletionMap(document, StyleType.CLASS);
202+
const text = document.getText();
192203

193204
let attribute, offset, value, anchor, end, start;
194205

@@ -199,7 +210,7 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
199210
attribute[3].indexOf(attribute[2]);
200211

201212
while ((value = findSelector.exec(attribute[3]))) {
202-
if (styles.has(value[1])) {
213+
if (map.has(value[1])) {
203214
continue;
204215
}
205216

0 commit comments

Comments
 (0)