From cd4a3c84b9cb38dffab2c5ac2fb126c9b5391a92 Mon Sep 17 00:00:00 2001 From: ANtlord Date: Sat, 18 Sep 2021 21:57:53 +0300 Subject: [PATCH 1/3] Container name is shown in document symbols --- src/types.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/types.rs b/src/types.rs index 1eb39548d..36792ca9d 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1159,12 +1159,13 @@ impl ListItem for lsp_types::DocumentSymbol { impl ListItem for SymbolInformation { fn quickfix_item(&self, _: &LanguageClient) -> Result { let start = self.location.range.start; - + let container_name = self.container_name.clone().unwrap_or_default(); + let text = [self.name.clone(), container_name].join("::"); Ok(QuickfixEntry { filename: self.location.uri.filepath()?.to_string_lossy().into_owned(), lnum: start.line + 1, col: Some(start.character + 1), - text: Some(self.name.clone()), + text: Some(text), nr: None, typ: None, }) @@ -1174,12 +1175,14 @@ impl ListItem for SymbolInformation { let filename = self.location.uri.filepath()?; let relpath = diff_paths(&filename, Path::new(cwd)).unwrap_or(filename); let start = self.location.range.start; + let container_name = self.container_name.clone().unwrap_or_default(); + let text = [self.name.clone(), container_name].join("::"); Ok(format!( "{}:{}:{}:\t{}\t\t{:?}", relpath.to_string_lossy(), start.line + 1, start.character + 1, - self.name, + text, self.kind )) } From d7a0bc2635d6ce1fcbef80df104cce2d7e1df75f Mon Sep 17 00:00:00 2001 From: ANtlord Date: Sat, 18 Sep 2021 22:01:37 +0300 Subject: [PATCH 2/3] container name and symbol name are swapped. --- src/types.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types.rs b/src/types.rs index 36792ca9d..9a0c24069 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1160,7 +1160,7 @@ impl ListItem for SymbolInformation { fn quickfix_item(&self, _: &LanguageClient) -> Result { let start = self.location.range.start; let container_name = self.container_name.clone().unwrap_or_default(); - let text = [self.name.clone(), container_name].join("::"); + let text = [container_name, self.name.clone()].join("::"); Ok(QuickfixEntry { filename: self.location.uri.filepath()?.to_string_lossy().into_owned(), lnum: start.line + 1, @@ -1176,7 +1176,7 @@ impl ListItem for SymbolInformation { let relpath = diff_paths(&filename, Path::new(cwd)).unwrap_or(filename); let start = self.location.range.start; let container_name = self.container_name.clone().unwrap_or_default(); - let text = [self.name.clone(), container_name].join("::"); + let text = [container_name, self.name.clone()].join("::"); Ok(format!( "{}:{}:{}:\t{}\t\t{:?}", relpath.to_string_lossy(), From 8fe5f6b7c9ca6e9646bbe868198765d220ed52cb Mon Sep 17 00:00:00 2001 From: ANtlord Date: Sat, 18 Sep 2021 22:59:28 +0300 Subject: [PATCH 3/3] Text building is moved to a dedicated method. --- src/types.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/types.rs b/src/types.rs index 9a0c24069..537873517 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1156,11 +1156,21 @@ impl ListItem for lsp_types::DocumentSymbol { } } +fn prepend( + text: impl AsRef, + optional_head: Option<&String>, + divisor: impl AsRef, +) -> String { + return optional_head.filter(|x| x.trim() != "").map_or_else( + || text.as_ref().to_string(), + |v| format!("{}{}{}", v, divisor.as_ref(), text.as_ref()), + ); +} + impl ListItem for SymbolInformation { fn quickfix_item(&self, _: &LanguageClient) -> Result { let start = self.location.range.start; - let container_name = self.container_name.clone().unwrap_or_default(); - let text = [container_name, self.name.clone()].join("::"); + let text = prepend(&self.name, self.container_name.as_ref(), "::"); Ok(QuickfixEntry { filename: self.location.uri.filepath()?.to_string_lossy().into_owned(), lnum: start.line + 1, @@ -1175,8 +1185,7 @@ impl ListItem for SymbolInformation { let filename = self.location.uri.filepath()?; let relpath = diff_paths(&filename, Path::new(cwd)).unwrap_or(filename); let start = self.location.range.start; - let container_name = self.container_name.clone().unwrap_or_default(); - let text = [container_name, self.name.clone()].join("::"); + let text = prepend(&self.name, self.container_name.as_ref(), "::"); Ok(format!( "{}:{}:{}:\t{}\t\t{:?}", relpath.to_string_lossy(),