Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document symbol container name #1234

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,15 +1156,26 @@ impl ListItem for lsp_types::DocumentSymbol {
}
}

fn prepend(
text: impl AsRef<str>,
optional_head: Option<&String>,
divisor: impl AsRef<str>,
) -> 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<QuickfixEntry> {
let start = self.location.range.start;

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,
col: Some(start.character + 1),
text: Some(self.name.clone()),
text: Some(text),
nr: None,
typ: None,
})
Expand All @@ -1174,12 +1185,13 @@ 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 text = prepend(&self.name, self.container_name.as_ref(), "::");
Ok(format!(
"{}:{}:{}:\t{}\t\t{:?}",
relpath.to_string_lossy(),
start.line + 1,
start.character + 1,
self.name,
text,
self.kind
))
}
Expand Down