Skip to content

Commit 98238d7

Browse files
committed
fix completion_test
1 parent 41bc0f5 commit 98238d7

File tree

1 file changed

+20
-21
lines changed
  • crates/emmylua_ls/src/handlers/completion/test

1 file changed

+20
-21
lines changed

crates/emmylua_ls/src/handlers/completion/test/mod.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,29 @@ impl CompletionVirtualWorkspace {
7676

7777
/// 处理文件内容
7878
fn handle_file_content(content: &str) -> Option<(String, Position)> {
79-
let mut content = content.to_string();
80-
let cursor_pos = content.find("<??>");
81-
if let Some(cursor_pos) = cursor_pos {
82-
// 确保只有一个 <??> 标记
83-
if content.matches("<??>").count() > 1 {
84-
return None;
85-
}
86-
87-
let mut line = 0;
88-
let mut column = 0;
89-
for (i, c) in content.chars().take(cursor_pos).enumerate() {
90-
if c == '\n' {
91-
line += 1;
92-
column = 0;
93-
} else {
94-
column += 1;
95-
}
96-
}
79+
let content = content.to_string();
80+
let cursor_byte_pos = content.find("<??>")?;
81+
if content.matches("<??>").count() > 1 {
82+
return None;
83+
}
9784

98-
content = content.replace("<??>", "");
85+
let mut line = 0;
86+
let mut column = 0;
9987

100-
return Some((content, Position::new(line as u32, column as u32)));
88+
for (byte_pos, c) in content.char_indices() {
89+
if byte_pos >= cursor_byte_pos {
90+
break;
91+
}
92+
if c == '\n' {
93+
line += 1;
94+
column = 0;
95+
} else {
96+
column += 1;
97+
}
10198
}
102-
None
99+
100+
let new_content = content.replace("<??>", "");
101+
Some((new_content, Position::new(line as u32, column as u32)))
103102
}
104103

105104
pub fn check_completion(

0 commit comments

Comments
 (0)