Skip to content
Merged
Show file tree
Hide file tree
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
52 changes: 39 additions & 13 deletions src/language_servers/ruby_lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,59 @@ impl RubyLsp {
}

pub fn label_for_completion(&self, completion: zed::lsp::Completion) -> Option<zed::CodeLabel> {
let highlight_name = match completion.kind? {
let zed::lsp::Completion {
label,
kind,
label_details,
..
} = completion;
let kind = kind?;

let highlight_scope = match kind {
zed::lsp::CompletionKind::Class | zed::lsp::CompletionKind::Module => "type",
zed::lsp::CompletionKind::Constant if label == "nil" => "constant.builtin",
zed::lsp::CompletionKind::Constant
if label.starts_with("__") && label.ends_with("__") =>
{
"constant.builtin"
}
zed::lsp::CompletionKind::Constant => "constant",
zed::lsp::CompletionKind::Method => "function.method",
zed::lsp::CompletionKind::Reference => "function.method",
zed::lsp::CompletionKind::Method
| zed::lsp::CompletionKind::Reference
| zed::lsp::CompletionKind::Function => "function.method",
zed::lsp::CompletionKind::Constructor => "function.method",
zed::lsp::CompletionKind::Keyword => "keyword",
zed::lsp::CompletionKind::Field if label.starts_with("@@") => "variable.special",
zed::lsp::CompletionKind::Field if label.starts_with('@') => "variable.special",
zed::lsp::CompletionKind::Field if label == "self" || label == "super" => {
"variable.special"
}
zed::lsp::CompletionKind::Variable => "variable",
zed::lsp::CompletionKind::Property => "property",
_ => return None,
};

let len = completion.label.len();
let label_len = label.len();
let mut spans = vec![zed::CodeLabelSpan::literal(
completion.label,
Some(highlight_name.to_string()),
label,
Some(highlight_scope.to_string()),
)];

if let Some(detail) = completion
.label_details
.and_then(|label_details| label_details.detail)
{
spans.push(zed::CodeLabelSpan::literal(" ", None));
spans.push(zed::CodeLabelSpan::literal(detail, None));
if let Some(label_details) = label_details {
if let Some(detail) = label_details.detail {
spans.push(zed::CodeLabelSpan::literal(detail, None));
}

if let Some(description) = label_details.description {
spans.push(zed::CodeLabelSpan::literal(" ", None));
spans.push(zed::CodeLabelSpan::literal(description, None));
}
}

Some(zed::CodeLabel {
code: Default::default(),
spans,
filter_range: (0..len).into(),
filter_range: (0..label_len).into(),
})
}

Expand Down
49 changes: 30 additions & 19 deletions src/language_servers/solargraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,45 @@ impl Solargraph {
}

pub fn label_for_completion(&self, completion: zed::lsp::Completion) -> Option<zed::CodeLabel> {
let highlight_name = match completion.kind? {
let zed::lsp::Completion {
label,
kind,
detail,
..
} = completion;
let kind = kind?;

let highlight_scope = match kind {
zed::lsp::CompletionKind::Class | zed::lsp::CompletionKind::Module => "type",
zed::lsp::CompletionKind::Constant if label == "nil" => "constant.builtin",
zed::lsp::CompletionKind::Constant
if label.starts_with("__") && label.ends_with("__") =>
{
"constant.builtin"
}
zed::lsp::CompletionKind::Constant => "constant",
zed::lsp::CompletionKind::Method => "function.method",
zed::lsp::CompletionKind::Keyword => {
if completion.label.starts_with(':') {
"string.special.symbol"
} else {
"keyword"
}
zed::lsp::CompletionKind::Method | zed::lsp::CompletionKind::Function => {
"function.method"
}
zed::lsp::CompletionKind::Variable => {
if completion.label.starts_with('@') {
"property"
} else {
return None;
}
zed::lsp::CompletionKind::Constructor => "function.method",
zed::lsp::CompletionKind::Keyword if label.starts_with(':') => "string.special.symbol",
zed::lsp::CompletionKind::Keyword => "keyword",
zed::lsp::CompletionKind::Field if label.starts_with("@@") => "variable.special",
zed::lsp::CompletionKind::Field if label.starts_with('@') => "variable.special",
zed::lsp::CompletionKind::Field if label == "self" || label == "super" => {
"variable.special"
}
zed::lsp::CompletionKind::Variable => "variable",
zed::lsp::CompletionKind::Property => "property",
_ => return None,
};

let len = completion.label.len();
let name_span =
zed::CodeLabelSpan::literal(completion.label, Some(highlight_name.to_string()));
let label_len = label.len();
let name_span = zed::CodeLabelSpan::literal(label, Some(highlight_scope.to_string()));

Some(zed::CodeLabel {
code: Default::default(),
spans: if let Some(detail) = completion.detail {
spans: if let Some(detail) = detail {
vec![
name_span,
zed::CodeLabelSpan::literal(" ", None),
Expand All @@ -56,7 +67,7 @@ impl Solargraph {
} else {
vec![name_span]
},
filter_range: (0..len).into(),
filter_range: (0..label_len).into(),
})
}

Expand Down