Skip to content

Commit 4c9d03b

Browse files
committed
chore: match glass-easel 0.12 API
1 parent a29ce5d commit 4c9d03b

File tree

7 files changed

+100
-65
lines changed

7 files changed

+100
-65
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ compact_str = "0.8.0"
1616
cssparser = "0.34.0"
1717
cssparser-color = "0.2.0"
1818
futures = "0.3.31"
19-
glass-easel-template-compiler = "0.11.0"
19+
glass-easel-template-compiler = "0.12.1"
2020
itertools = "0.13.0"
2121
log = "0.4.22"
2222
lsp-server = "0.7.7"
@@ -26,3 +26,6 @@ serde_json = "1.0.132"
2626
tokio = { version = "1.41.0", features = ["fs", "macros", "rt", "sync", "time"] }
2727
tokio-stream = { version = "0.1.16", features = ["fs"] }
2828
toml = "0.8.19"
29+
30+
[patch.crates-io]
31+
glass-easel-template-compiler = { path = "../glass-easel/glass-easel-template-compiler" }

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ A Language Server for glass-easel and glass-easel-miniprogram-adapter
44

55
It handles MiniProgram code structure, i.e. WXML/WXSS files.
66

7-
*Still in early development.*
8-
97

108
## Development Guide
119

src/completion.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ fn completion_wxml(
217217
let has_attr = |name: &str| {
218218
attributes
219219
.iter()
220-
.chain(change_attributes.iter())
221-
.find(|x| x.name.name.as_str() == name)
220+
.map(|x| &x.name)
221+
.chain(change_attributes.iter().map(|x| &x.name))
222+
.find(|x| x.name.as_str() == name)
222223
.is_some()
223224
};
224225
if let Some(_target_path) = project.get_target_component_path(abs_path, &tag_name.name)

src/semantic/wxml.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use glass_easel_template_compiler::parse::{
22
expr::{ArrayFieldKind, Expression, ObjectFieldKind},
33
tag::{
4-
ClassAttribute, CommonElementAttributes, ElementKind, Ident, Node, Script, StrName,
5-
StyleAttribute, Value,
4+
ClassAttribute, CommonElementAttributes, ElementKind, Ident, Node, NormalAttributePrefix, Script, StrName, StyleAttribute, Value
65
},
76
Position, Template,
87
};
@@ -124,8 +123,8 @@ pub(super) fn find_wxml_semantic_tokens(
124123
});
125124
}
126125
tokens.push((&attr.name).into());
127-
if !attr.is_value_unspecified {
128-
collect_in_value(tokens, &attr.value);
126+
if let Some(value) = attr.value.as_ref() {
127+
collect_in_value(tokens, value);
129128
}
130129
}
131130
for attr in common.event_bindings.iter() {
@@ -139,8 +138,8 @@ pub(super) fn find_wxml_semantic_tokens(
139138
ty: TokenType::Event,
140139
modifier: 0,
141140
});
142-
if !attr.is_value_unspecified {
143-
collect_in_value_with_static_type(tokens, &attr.value, TokenType::Method);
141+
if let Some(value) = attr.value.as_ref() {
142+
collect_in_value_with_static_type(tokens, value, TokenType::Method);
144143
}
145144
}
146145
}
@@ -189,7 +188,20 @@ pub(super) fn find_wxml_semantic_tokens(
189188
modifier: 0,
190189
});
191190
}
192-
for attr in attributes.iter().chain(change_attributes.iter()) {
191+
for attr in attributes.iter() {
192+
if let NormalAttributePrefix::Model(p) = &attr.prefix {
193+
tokens.push(WxmlToken {
194+
location: p.clone(),
195+
ty: TokenType::Keyword,
196+
modifier: 0,
197+
});
198+
}
199+
tokens.push((&attr.name).into());
200+
if let Some(value) = attr.value.as_ref() {
201+
collect_in_value(tokens, value);
202+
}
203+
}
204+
for attr in change_attributes.iter() {
193205
if let Some(p) = attr.prefix_location.as_ref() {
194206
tokens.push(WxmlToken {
195207
location: p.clone(),
@@ -198,8 +210,8 @@ pub(super) fn find_wxml_semantic_tokens(
198210
});
199211
}
200212
tokens.push((&attr.name).into());
201-
if !attr.is_value_unspecified {
202-
collect_in_value(tokens, &attr.value);
213+
if let Some(value) = attr.value.as_ref() {
214+
collect_in_value(tokens, value);
203215
}
204216
}
205217
for attr in worklet_attributes
@@ -311,8 +323,8 @@ pub(super) fn find_wxml_semantic_tokens(
311323
});
312324
}
313325
tokens.push((&attr.name).into());
314-
if !attr.is_value_unspecified {
315-
collect_in_value(tokens, &attr.value);
326+
if let Some(value) = attr.value.as_ref() {
327+
collect_in_value(tokens, value);
316328
}
317329
}
318330
collect_in_common_attrs(tokens, common);

src/wxml_utils.rs

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use std::ops::Range;
33
use glass_easel_template_compiler::parse::{
44
expr::Expression,
55
tag::{
6-
ClassAttribute, Comment, CommonElementAttributes, Element, ElementKind, Ident, Node,
7-
Script, StaticAttribute, StrName, StyleAttribute, TagLocation, UnknownMetaTag, Value,
6+
ClassAttribute, Comment, CommonElementAttributes, Element, ElementKind, Ident, Node, NormalAttributePrefix, Script, StaticAttribute, StrName, StyleAttribute, TagLocation, UnknownMetaTag, Value
87
},
98
Position, Template,
109
};
@@ -222,6 +221,17 @@ pub(crate) fn find_token_in_position(template: &Template, pos: Position) -> Toke
222221
_ => None,
223222
}
224223
}
224+
fn find_in_option_value<'a>(
225+
v: &'a Option<Value>,
226+
pos: Position,
227+
scopes: &mut Vec<ScopeKind<'a>>,
228+
) -> Option<Token<'a>> {
229+
if let Some(v) = v {
230+
find_in_value(v, pos, scopes)
231+
} else {
232+
None
233+
}
234+
}
225235
fn find_in_nodes<'a>(
226236
parent: Option<&'a Element>,
227237
nodes: &'a [Node],
@@ -315,23 +325,23 @@ pub(crate) fn find_token_in_position(template: &Template, pos: Position) -> Toke
315325
if ident_contains(&attr.name, pos) {
316326
return Token::DataKey(&attr.name);
317327
}
318-
if let Some(ret) = find_in_value(&attr.value, pos, scopes) {
328+
if let Some(ret) = find_in_option_value(&attr.value, pos, scopes) {
319329
return ret;
320330
}
321331
}
322332
for attr in common.data.iter() {
323333
if ident_contains(&attr.name, pos) {
324334
return Token::MarkKey(&attr.name);
325335
}
326-
if let Some(ret) = find_in_value(&attr.value, pos, scopes) {
336+
if let Some(ret) = find_in_option_value(&attr.value, pos, scopes) {
327337
return ret;
328338
}
329339
}
330340
for ev in common.event_bindings.iter() {
331341
if ident_contains(&ev.name, pos) {
332342
return Token::EventName(&ev.name, elem);
333343
}
334-
if let Some(ret) = find_in_value(&ev.value, pos, scopes) {
344+
if let Some(ret) = find_in_option_value(&ev.value, pos, scopes) {
335345
return ret;
336346
}
337347
}
@@ -357,12 +367,12 @@ pub(crate) fn find_token_in_position(template: &Template, pos: Position) -> Toke
357367
}
358368
for attr in attributes.iter() {
359369
if ident_contains(&attr.name, pos) {
360-
if attr.is_model {
370+
if let NormalAttributePrefix::Model(_) = &attr.prefix {
361371
return Token::ModelAttributeName(&attr.name, elem);
362372
}
363373
return Token::AttributeName(&attr.name, elem);
364374
}
365-
if let Some(ret) = find_in_value(&attr.value, pos, scopes) {
375+
if let Some(ret) = find_in_option_value(&attr.value, pos, scopes) {
366376
if let Token::StaticValuePart(loc, v) = ret {
367377
return Token::AttributeStaticValue(
368378
loc, v, &attr.name, elem,
@@ -375,7 +385,7 @@ pub(crate) fn find_token_in_position(template: &Template, pos: Position) -> Toke
375385
if ident_contains(&attr.name, pos) {
376386
return Token::AttributeName(&attr.name, elem);
377387
}
378-
if let Some(ret) = find_in_value(&attr.value, pos, scopes) {
388+
if let Some(ret) = find_in_option_value(&attr.value, pos, scopes) {
379389
if let Token::StaticValuePart(loc, v) = ret {
380390
return Token::AttributeStaticValue(
381391
loc, v, &attr.name, elem,
@@ -629,7 +639,7 @@ pub(crate) fn find_token_in_position(template: &Template, pos: Position) -> Toke
629639
if ident_contains(&attr.name, pos) {
630640
return Token::SlotValueDefinition(&attr.name);
631641
}
632-
if let Some(ret) = find_in_value(&attr.value, pos, scopes) {
642+
if let Some(ret) = find_in_option_value(&attr.value, pos, scopes) {
633643
return ret;
634644
}
635645
}
@@ -866,10 +876,14 @@ pub(crate) fn for_each_template_value_in_subtree<'a>(
866876
f(value, scopes);
867877
}
868878
for attr in common.data.iter().chain(common.marks.iter()) {
869-
f(&attr.value, scopes);
879+
if let Some(value) = attr.value.as_ref() {
880+
f(value, scopes);
881+
}
870882
}
871883
for ev in common.event_bindings.iter() {
872-
f(&ev.value, scopes);
884+
if let Some(value) = ev.value.as_ref() {
885+
f(value, scopes);
886+
}
873887
}
874888
}
875889
match node {
@@ -890,8 +904,15 @@ pub(crate) fn for_each_template_value_in_subtree<'a>(
890904
common,
891905
..
892906
} => {
893-
for attr in attributes.iter().chain(change_attributes.iter()) {
894-
f(&attr.value, scopes);
907+
for attr in attributes.iter() {
908+
if let Some(value) = attr.value.as_ref() {
909+
f(value, scopes);
910+
}
911+
}
912+
for attr in change_attributes.iter() {
913+
if let Some(value) = attr.value.as_ref() {
914+
f(value, scopes);
915+
}
895916
}
896917
match class {
897918
ClassAttribute::None => {}
@@ -961,7 +982,9 @@ pub(crate) fn for_each_template_value_in_subtree<'a>(
961982
} => {
962983
f(&name.1, scopes);
963984
for attr in values.iter() {
964-
f(&attr.value, scopes);
985+
if let Some(value) = attr.value.as_ref() {
986+
f(value, scopes);
987+
}
965988
}
966989
handle_common(common, scopes, &mut f);
967990
}

0 commit comments

Comments
 (0)