Skip to content

Commit eb879f9

Browse files
cheuk-fungautozimu
authored andcommitted
Fix error in FZFSinkLocation when filename contains ':'
In function languageClient_FZFSinkLocation, ':' is used to split the selected location to get tokens for [filename, line, character]. But if filename contains ':', the length of tokens will be greater than 3. This fix joins tokens[..(len - 2)] back with ':' to form the correct token vector [filename, line, character].
1 parent 0f4a1fc commit eb879f9

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

src/language_server_protocol.rs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl LanguageClient {
302302
self.apply_TextEdits(&uri.filepath()?, edits)?;
303303
}
304304
}
305-
self.vim()?.edit(&None, &filename)?;
305+
self.edit(&None, &filename)?;
306306
self.vim()?
307307
.cursor(position.line + 1, position.character + 1)?;
308308
debug!("End apply WorkspaceEdit");
@@ -436,7 +436,7 @@ impl LanguageClient {
436436
edits.sort_by_key(|edit| (edit.range.start.line, edit.range.start.character));
437437
edits.reverse();
438438

439-
self.vim()?.edit(&None, path)?;
439+
self.edit(&None, path)?;
440440

441441
let mut lines: Vec<String> = self.vim()?.rpcclient.call("getline", json!([1, '$']))?;
442442
let lines_len_prev = lines.len();
@@ -909,6 +909,16 @@ impl LanguageClient {
909909
Ok(())
910910
}
911911

912+
fn edit(&self, goto_cmd: &Option<String>, path: impl AsRef<Path>) -> Fallible<()> {
913+
let path = path.as_ref().to_string_lossy();
914+
if path.starts_with("jdt://") {
915+
self.java_classFileContents(&json!({ "gotoCmd": goto_cmd, "uri": path }))?;
916+
Ok(())
917+
} else {
918+
self.vim()?.edit(&goto_cmd, path.into_owned())
919+
}
920+
}
921+
912922
/////// LSP ///////
913923

914924
fn initialize(&self, params: &Value) -> Fallible<Value> {
@@ -1112,11 +1122,7 @@ impl LanguageClient {
11121122
1 => {
11131123
let loc = locations.get(0).ok_or_else(|| err_msg("Not found!"))?;
11141124
let path = loc.uri.filepath()?.to_string_lossy().into_owned();
1115-
if path.starts_with("jdt://") {
1116-
self.java_classFileContents(&json!({ "gotoCmd": goto_cmd, "uri": path }))?;
1117-
} else {
1118-
self.vim()?.edit(&goto_cmd, path)?;
1119-
}
1125+
self.edit(&goto_cmd, path)?;
11201126
self.vim()?
11211127
.cursor(loc.range.start.line + 1, loc.range.start.character + 1)?;
11221128
let cur_file: String = self.vim()?.eval("expand('%')")?;
@@ -2531,30 +2537,29 @@ impl LanguageClient {
25312537
.split('\t')
25322538
.next()
25332539
.ok_or_else(|| format_err!("Failed to parse: {:?}", lines))?;
2534-
let mut tokens: Vec<_> = location.split_terminator(':').collect();
2535-
tokens.reverse();
2536-
let filename: String = if tokens.len() > 2 {
2537-
let relpath = tokens
2538-
.pop()
2539-
.ok_or_else(|| format_err!("Failed to get file path! tokens: {:?}", tokens))?
2540-
.to_owned();
2541-
let cwd: String = self.vim()?.eval("getcwd()")?;
2542-
Path::new(&cwd).join(relpath).to_string_lossy().into_owned()
2540+
let tokens: Vec<_> = location.split_terminator(':').collect();
2541+
2542+
let (filename, mut tokens_iter): (String, _) = if tokens.len() > 2 {
2543+
let end_index = tokens.len() - 2;
2544+
let path = tokens[..end_index].join(":");
2545+
let rest_tokens_iter = tokens[end_index..].iter();
2546+
(path, rest_tokens_iter)
25432547
} else {
2544-
self.vim()?.get_filename(&params)?
2548+
(self.vim()?.get_filename(&params)?, tokens.iter())
25452549
};
2546-
let line = tokens
2547-
.pop()
2550+
2551+
let line = tokens_iter
2552+
.next()
25482553
.ok_or_else(|| format_err!("Failed to get line! tokens: {:?}", tokens))?
25492554
.to_int()?
25502555
- 1;
2551-
let character = tokens
2552-
.pop()
2556+
let character = tokens_iter
2557+
.next()
25532558
.ok_or_else(|| format_err!("Failed to get character! tokens: {:?}", tokens))?
25542559
.to_int()?
25552560
- 1;
25562561

2557-
self.vim()?.edit(&None, &filename)?;
2562+
self.edit(&None, &filename)?;
25582563
self.vim()?.cursor(line + 1, character + 1)?;
25592564

25602565
info!("End {}", NOTIFICATION__FZFSinkLocation);

0 commit comments

Comments
 (0)