Skip to content

Commit b2d6841

Browse files
committed
fmt: cargo
1 parent 4077bf1 commit b2d6841

File tree

8 files changed

+127
-105
lines changed

8 files changed

+127
-105
lines changed

src/completion.rs

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use lsp_types::{
1414
use crate::{
1515
context::{
1616
backend_configuration::MediaFeatureType,
17-
project::{FileContentMetadata, Project}, FileLang,
17+
project::{FileContentMetadata, Project},
18+
FileLang,
1819
},
1920
wxml_utils::{
2021
for_each_static_class_name_in_element, for_each_template_element, Token as WxmlToken,
@@ -317,11 +318,11 @@ fn completion_wxml(
317318
} else {
318319
let choices = item_set
319320
.into_iter()
320-
.filter(|x| {
321-
match class {
322-
ClassAttribute::Multiple(arr) => arr.iter().find(|y| y.1.name == x).is_none(),
323-
_ => true,
321+
.filter(|x| match class {
322+
ClassAttribute::Multiple(arr) => {
323+
arr.iter().find(|y| y.1.name == x).is_none()
324324
}
325+
_ => true,
325326
})
326327
.join(",");
327328
if let ClassAttribute::None = class {
@@ -354,11 +355,11 @@ fn completion_wxml(
354355
.style_property
355356
.iter()
356357
.map(|x| &x.name)
357-
.filter(|x| {
358-
match style {
359-
StyleAttribute::Multiple(arr) => arr.iter().find(|y| y.1.name == x).is_none(),
360-
_ => true,
358+
.filter(|x| match style {
359+
StyleAttribute::Multiple(arr) => {
360+
arr.iter().find(|y| y.1.name == x).is_none()
361361
}
362+
_ => true,
362363
})
363364
.join(",");
364365
items.push(snippet_completion_item(
@@ -672,56 +673,46 @@ fn completion_wxml(
672673
WxmlToken::ModelAttributeName(_attr_name, elem) => handle_attr(elem, true),
673674
WxmlToken::ChangeAttributeName(_attr_name, elem) => handle_attr(elem, true),
674675
WxmlToken::AttributeKeyword(_loc, elem) => handle_attr(elem, false),
675-
WxmlToken::StaticClassName(_loc, _name, elem) => {
676-
match &elem.kind {
677-
ElementKind::Normal { class, .. } => {
678-
let items = collect_classes_in_wxss(project, abs_path)
679-
.into_iter()
680-
.filter(|x| {
681-
match class {
682-
ClassAttribute::Multiple(arr) => arr.iter().find(|y| y.1.name == x).is_none(),
683-
_ => true,
684-
}
685-
})
686-
.map(|x| {
687-
simple_completion_item(
688-
x,
689-
CompletionItemKind::PROPERTY,
690-
false,
691-
)
692-
})
693-
.collect();
694-
Some(CompletionList { is_incomplete: false, items })
695-
}
696-
_ => None,
676+
WxmlToken::StaticClassName(_loc, _name, elem) => match &elem.kind {
677+
ElementKind::Normal { class, .. } => {
678+
let items = collect_classes_in_wxss(project, abs_path)
679+
.into_iter()
680+
.filter(|x| match class {
681+
ClassAttribute::Multiple(arr) => {
682+
arr.iter().find(|y| y.1.name == x).is_none()
683+
}
684+
_ => true,
685+
})
686+
.map(|x| simple_completion_item(x, CompletionItemKind::PROPERTY, false))
687+
.collect();
688+
Some(CompletionList {
689+
is_incomplete: false,
690+
items,
691+
})
697692
}
698-
}
699-
WxmlToken::StaticStylePropertyName(_, elem) => {
700-
match &elem.kind {
701-
ElementKind::Normal { style, .. } => {
702-
let items = backend_config
703-
.style_property
704-
.iter()
705-
.map(|x| &x.name)
706-
.filter(|x| {
707-
match style {
708-
StyleAttribute::Multiple(arr) => arr.iter().find(|y| y.1.name == x).is_none(),
709-
_ => true,
710-
}
711-
})
712-
.map(|x| {
713-
simple_completion_item(
714-
x,
715-
CompletionItemKind::PROPERTY,
716-
false,
717-
)
718-
})
719-
.collect();
720-
Some(CompletionList { is_incomplete: false, items })
721-
}
722-
_ => None,
693+
_ => None,
694+
},
695+
WxmlToken::StaticStylePropertyName(_, elem) => match &elem.kind {
696+
ElementKind::Normal { style, .. } => {
697+
let items = backend_config
698+
.style_property
699+
.iter()
700+
.map(|x| &x.name)
701+
.filter(|x| match style {
702+
StyleAttribute::Multiple(arr) => {
703+
arr.iter().find(|y| y.1.name == x).is_none()
704+
}
705+
_ => true,
706+
})
707+
.map(|x| simple_completion_item(x, CompletionItemKind::PROPERTY, false))
708+
.collect();
709+
Some(CompletionList {
710+
is_incomplete: false,
711+
items,
712+
})
723713
}
724-
}
714+
_ => None,
715+
},
725716
WxmlToken::EventName(_event_name, elem) => {
726717
let mut items: Vec<CompletionItem> = vec![];
727718
let has_event = |common: &CommonElementAttributes, name: &str| {

src/context/project.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use glass_easel_template_compiler::{
1212
use lsp_types::{Diagnostic, DiagnosticSeverity, Position, Range};
1313
use tokio::sync::Mutex as AsyncMutex;
1414

15-
use crate::wxss::{self, StyleSheet};
1615
use super::FileLang;
16+
use crate::wxss::{self, StyleSheet};
1717

1818
#[derive(Debug)]
1919
pub(crate) struct FileContentMetadata {
@@ -348,8 +348,10 @@ impl Project {
348348
.insert(abs_path.to_path_buf(), Default::default());
349349
}
350350
}
351-
self.file_contents
352-
.insert(abs_path.to_path_buf(), FileContentMetadata::new(content, FileLang::Json));
351+
self.file_contents.insert(
352+
abs_path.to_path_buf(),
353+
FileContentMetadata::new(content, FileLang::Json),
354+
);
353355
Ok(ret)
354356
}
355357

@@ -387,8 +389,10 @@ impl Project {
387389

388390
fn update_wxss(&mut self, abs_path: &Path, content: String) -> anyhow::Result<Vec<Diagnostic>> {
389391
let (ss, err_list) = StyleSheet::parse_str(&content);
390-
self.file_contents
391-
.insert(abs_path.to_path_buf(), FileContentMetadata::new(content, FileLang::Wxss));
392+
self.file_contents.insert(
393+
abs_path.to_path_buf(),
394+
FileContentMetadata::new(content, FileLang::Wxss),
395+
);
392396
self.style_sheet_map.insert(abs_path.to_path_buf(), ss);
393397
let diagnostics = err_list
394398
.into_iter()
@@ -436,8 +440,10 @@ impl Project {
436440
fn update_wxml(&mut self, abs_path: &Path, content: String) -> anyhow::Result<Vec<Diagnostic>> {
437441
let tmpl_path = self.unix_rel_path_or_fallback(&abs_path);
438442
let err_list = self.template_group.add_tmpl(&tmpl_path, &content);
439-
self.file_contents
440-
.insert(abs_path.to_path_buf(), FileContentMetadata::new(content, FileLang::Wxml));
443+
self.file_contents.insert(
444+
abs_path.to_path_buf(),
445+
FileContentMetadata::new(content, FileLang::Wxml),
446+
);
441447
let diagnostics = err_list
442448
.into_iter()
443449
.filter_map(diagnostic_from_wxml_parse_error)

src/file.rs

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ use lsp_types::{
44
FileChangeType, PublishDiagnosticsParams, TextDocumentContentChangeEvent,
55
};
66

7-
use crate::{context::{project::Project, FileLang}, utils::log_if_err, ServerContext};
7+
use crate::{
8+
context::{project::Project, FileLang},
9+
utils::log_if_err,
10+
ServerContext,
11+
};
812

913
fn apply_content_changes_to_content(
1014
content: &str,
@@ -68,33 +72,38 @@ pub(crate) async fn did_change(
6872
let uri = params.text_document.uri.clone();
6973
log_if_err(
7074
ctx.clone()
71-
.project_thread_task(&params.text_document.uri, move |project, abs_path, file_lang| {
72-
if let Some(content) = project.cached_file_content(&abs_path) {
73-
let new_content =
74-
apply_content_changes_to_content(&content.content, params.content_changes);
75-
let diag = match file_lang {
76-
FileLang::Wxml => project.open_wxml(&abs_path, new_content),
77-
FileLang::Wxss => project.open_wxss(&abs_path, new_content),
78-
FileLang::Json => project.open_json(&abs_path, new_content),
79-
_ => return,
80-
};
81-
match diag {
82-
Ok(diagnostics) => {
83-
log_if_err(ctx.send_notification(
84-
"textDocument/publishDiagnostics",
85-
PublishDiagnosticsParams {
86-
uri,
87-
diagnostics,
88-
version: None,
89-
},
90-
));
91-
}
92-
Err(err) => {
93-
log::error!("{}", err);
75+
.project_thread_task(
76+
&params.text_document.uri,
77+
move |project, abs_path, file_lang| {
78+
if let Some(content) = project.cached_file_content(&abs_path) {
79+
let new_content = apply_content_changes_to_content(
80+
&content.content,
81+
params.content_changes,
82+
);
83+
let diag = match file_lang {
84+
FileLang::Wxml => project.open_wxml(&abs_path, new_content),
85+
FileLang::Wxss => project.open_wxss(&abs_path, new_content),
86+
FileLang::Json => project.open_json(&abs_path, new_content),
87+
_ => return,
88+
};
89+
match diag {
90+
Ok(diagnostics) => {
91+
log_if_err(ctx.send_notification(
92+
"textDocument/publishDiagnostics",
93+
PublishDiagnosticsParams {
94+
uri,
95+
diagnostics,
96+
version: None,
97+
},
98+
));
99+
}
100+
Err(err) => {
101+
log::error!("{}", err);
102+
}
94103
}
95104
}
96-
}
97-
})
105+
},
106+
)
98107
.await,
99108
);
100109
Ok(())

src/reference/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use std::path::{Path, PathBuf};
22

33
use lsp_types::{GotoDefinitionParams, Location, LocationLink, ReferenceParams};
44

5-
use crate::{context::{project::Project, FileLang}, ServerContext};
5+
use crate::{
6+
context::{project::Project, FileLang},
7+
ServerContext,
8+
};
69

710
mod wxml;
811
mod wxss;

src/reference/wxml.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,7 @@ pub(super) fn find_declaration(
272272
origin_selection_range: Some(location_to_lsp_range(&loc)),
273273
target_uri: lsp_types::Url::from_file_path(abs_path).unwrap(),
274274
target_range: location_to_lsp_range(&v.name.location),
275-
target_selection_range: location_to_lsp_range(
276-
&v.name.location,
277-
),
275+
target_selection_range: location_to_lsp_range(&v.name.location),
278276
});
279277
}
280278
},

src/semantic/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use lsp_types::{
66
SemanticTokensRangeParams,
77
};
88

9-
use crate::{context::{project::FileContentMetadata, FileLang}, ServerContext};
9+
use crate::{
10+
context::{project::FileContentMetadata, FileLang},
11+
ServerContext,
12+
};
1013

1114
mod wxml;
1215
mod wxss;

src/symbol.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ use glass_easel_template_compiler::parse::{Template, TemplateStructure};
22
use lsp_types::{DocumentSymbol, DocumentSymbolParams, SymbolKind};
33

44
use crate::{
5-
context::FileLang, utils::location_to_lsp_range, wxss::{
5+
context::FileLang,
6+
utils::location_to_lsp_range,
7+
wxss::{
68
keyframe::Keyframe, token::BraceOrSemicolon, CSSParse, List, Rule, RuleOrProperty,
79
StyleSheet,
8-
}, ServerContext
10+
},
11+
ServerContext,
912
};
1013

1114
pub(crate) async fn document_symbol(

src/wxml_utils.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use std::ops::Range;
33
use glass_easel_template_compiler::parse::{
44
expr::Expression,
55
tag::{
6-
Attribute, ClassAttribute, Comment, CommonElementAttributes, Element, ElementKind, Ident, Node, NormalAttributePrefix, Script, StaticAttribute, StrName, StyleAttribute, TagLocation, UnknownMetaTag, Value
6+
Attribute, ClassAttribute, Comment, CommonElementAttributes, Element, ElementKind, Ident,
7+
Node, NormalAttributePrefix, Script, StaticAttribute, StrName, StyleAttribute, TagLocation,
8+
UnknownMetaTag, Value,
79
},
810
Position, Template, TemplateStructure,
911
};
@@ -272,9 +274,7 @@ pub(crate) fn find_token_in_position(template: &Template, pos: Position) -> Toke
272274
if ident_contains(&attr.name, pos) {
273275
return Token::LetVarDefinition(&attr, elem);
274276
}
275-
if let Some(ret) =
276-
find_in_option_value(&attr.value, pos, &scopes)
277-
{
277+
if let Some(ret) = find_in_option_value(&attr.value, pos, &scopes) {
278278
if let Token::StaticValuePart(loc, v) = ret {
279279
return Token::AttributeStaticValue(
280280
loc, v, &attr.name, elem,
@@ -453,7 +453,11 @@ pub(crate) fn find_token_in_position(template: &Template, pos: Position) -> Toke
453453
if let Some(ret) = find_in_value(v, pos, scopes) {
454454
return match ret {
455455
Token::StaticValuePart(loc, name) => {
456-
Token::StaticClassName(loc.clone(), name, &elem)
456+
Token::StaticClassName(
457+
loc.clone(),
458+
name,
459+
&elem,
460+
)
457461
}
458462
x => x,
459463
};
@@ -468,7 +472,9 @@ pub(crate) fn find_token_in_position(template: &Template, pos: Position) -> Toke
468472
&elem,
469473
);
470474
}
471-
if let Some(ret) = find_in_option_value(v, pos, scopes) {
475+
if let Some(ret) =
476+
find_in_option_value(v, pos, scopes)
477+
{
472478
return ret;
473479
}
474480
}
@@ -488,7 +494,9 @@ pub(crate) fn find_token_in_position(template: &Template, pos: Position) -> Toke
488494
StyleAttribute::Multiple(list) => {
489495
for (_pos, name, v) in list {
490496
if ident_contains(name, pos) {
491-
return Token::StaticStylePropertyName(name, &elem);
497+
return Token::StaticStylePropertyName(
498+
name, &elem,
499+
);
492500
}
493501
if let Some(ret) = find_in_value(v, pos, scopes) {
494502
return ret;
@@ -832,7 +840,8 @@ pub(crate) fn insert_element_scopes<'a>(scopes: &mut Vec<ScopeKind<'a>>, elem: &
832840
}
833841
| ElementKind::Pure {
834842
let_vars,
835-
slot_value_refs, ..
843+
slot_value_refs,
844+
..
836845
} => {
837846
for attr in slot_value_refs {
838847
scopes.push(ScopeKind::SlotValue(attr, elem));

0 commit comments

Comments
 (0)