Skip to content

Commit 62f2714

Browse files
committed
optimize formatter
1 parent ffe32ba commit 62f2714

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

crates/xmake_formatter/src/style_ruler/basic_space.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ impl StyleRuler for BasicSpaceRuler {
1515
let syntax_id = LuaSyntaxId::from_token(&token);
1616
match token.kind().to_token() {
1717
LuaTokenKind::TkLeftParen | LuaTokenKind::TkLeftBracket => {
18+
if let Some(prev_token) = get_prev_sibling_token_without_space(&token) {
19+
match prev_token.kind().to_token() {
20+
LuaTokenKind::TkName
21+
| LuaTokenKind::TkRightParen
22+
| LuaTokenKind::TkRightBracket => {
23+
f.add_token_left_expected(syntax_id, TokenExpected::Space(0));
24+
}
25+
LuaTokenKind::TkString
26+
| LuaTokenKind::TkRightBrace
27+
| LuaTokenKind::TkLongString => {
28+
f.add_token_left_expected(syntax_id, TokenExpected::Space(1));
29+
}
30+
_ => {}
31+
}
32+
}
33+
1834
f.add_token_right_expected(syntax_id, TokenExpected::Space(0));
1935
}
2036
LuaTokenKind::TkRightBracket | LuaTokenKind::TkRightParen => {
@@ -123,3 +139,15 @@ fn is_parent_syntax(token: &LuaSyntaxToken, kind: LuaSyntaxKind) -> bool {
123139
}
124140
false
125141
}
142+
143+
fn get_prev_sibling_token_without_space(token: &LuaSyntaxToken) -> Option<LuaSyntaxToken> {
144+
let mut current = token.clone();
145+
while let Some(prev) = current.prev_token() {
146+
if prev.kind().to_token() != LuaTokenKind::TkWhitespace {
147+
return Some(prev);
148+
}
149+
current = prev;
150+
}
151+
152+
None
153+
}

crates/xmake_ls/src/handlers/document_range_formatting/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub async fn on_range_formatting_handler(
8585
Some(vec![text_edit])
8686
}
8787

88+
#[allow(unused)]
8889
pub struct DocumentRangeFormattingCapabilities;
8990

9091
impl RegisterCapabilities for DocumentRangeFormattingCapabilities {

crates/xmake_ls/src/handlers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ capabilities!(modules: {
7373
document_selection_range => DocumentSelectionRangeCapabilities,
7474
document_highlight => DocumentHighlightCapabilities,
7575
document_formatting => DocumentFormattingCapabilities,
76-
document_range_formatting => DocumentRangeFormattingCapabilities,
76+
// document_range_formatting => DocumentRangeFormattingCapabilities,
7777
// document_type_format => DocumentTypeFormattingCapabilities,
7878
completion => CompletionCapabilities,
7979
inlay_hint => InlayHintCapabilities,

crates/xmake_wrapper/src/lib.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,8 @@ impl XmakeWrapper {
7575
return Some(xmake_path);
7676
}
7777

78-
// 尝试从环境变量获取 xmake 路径
79-
if let Ok(xmake_root) = std::env::var("XMAKE_ROOT") {
80-
let xmake_exe = PathBuf::from(xmake_root).join("bin").join("xmake");
81-
if xmake_exe.exists() {
82-
return Some(xmake_exe);
83-
}
84-
}
85-
8678
if let Ok(xmake_home) = std::env::var("XMAKE_HOME") {
87-
let xmake_exe = PathBuf::from(xmake_home).join("bin").join("xmake");
79+
let xmake_exe = PathBuf::from(xmake_home).join("xmake");
8880
if xmake_exe.exists() {
8981
return Some(xmake_exe);
9082
}

0 commit comments

Comments
 (0)