Improve outline fonts and colors (#63325)
Closes https://github.com/zed-industries/zed/issues/58580 * Outline modal and panel now use buffer fonts for the contents: <img width="1728" height="1117" alt="modal" src="https://github.com/user-attachments/assets/5e0ef6e3-be39-4949-bc32-7087a51a02ec" /> <img width="1728" height="1092" alt="panel" src="https://github.com/user-attachments/assets/5cf9edbf-5ff3-402d-a2ca-bc915bd10e8e" /> * Gutter colors are now fall-backed to tree-sitter better, if no semantic tokens could be retrieved due to multi buffer shenanigans: <img width="1728" height="426" alt="gutter" src="https://github.com/user-attachments/assets/a175b2c8-843e-4632-b030-3edfbd350982" /> Release Notes: - Improved outline fonts and colors
This commit is contained in:
1 parent
2ada348466
commit
8a54abc4b9
8 files changed
+177
-60
No files matched your search
@@ -6,7 +6,7 @@ use futures::future::join_all;
|
||||
use gpui::{App, Context, HighlightStyle, Task};
|
||||
use itertools::Itertools as _;
|
||||
use language::language_settings::LanguageSettings;
|
||||
use language::{Buffer, OutlineItem};
|
||||
use language::{Buffer, OutlineItem, highlight_ranges_from_text};
|
||||
use multi_buffer::{
|
||||
Anchor, AnchorRangeExt as _, MultiBufferOffset, MultiBufferRow, MultiBufferSnapshot,
|
||||
ToOffset as _,
|
||||
@@ -219,12 +219,20 @@ impl Editor {
|
||||
let display_snapshot =
|
||||
editor.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
let mut highlighted_results = results;
|
||||
for items in highlighted_results.values_mut() {
|
||||
for (buffer_id, items) in highlighted_results.iter_mut() {
|
||||
let language = editor
|
||||
.buffer
|
||||
.read(cx)
|
||||
.buffer(*buffer_id)
|
||||
.and_then(|buffer| buffer.read(cx).language().cloned());
|
||||
for item in items {
|
||||
if let Some(highlights) =
|
||||
highlights_from_buffer(&display_snapshot, &item, &syntax)
|
||||
{
|
||||
item.highlight_ranges = highlights;
|
||||
} else if let Some(language) = &language {
|
||||
item.highlight_ranges =
|
||||
highlight_ranges_from_text(&item.text, language, &syntax);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,6 +342,7 @@ mod tests {
|
||||
|
||||
use futures::StreamExt as _;
|
||||
use gpui::{App, TestAppContext};
|
||||
use language::highlight_ranges_from_text;
|
||||
use multi_buffer::ToPoint;
|
||||
use settings::{DocumentSymbols, SettingsStore};
|
||||
use text::Point;
|
||||
@@ -813,6 +822,82 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_lsp_document_symbols_fall_back_to_reparsed_text_highlights(
|
||||
cx: &mut TestAppContext,
|
||||
) {
|
||||
use ui::ActiveTheme as _;
|
||||
|
||||
init_test(cx, |_| {});
|
||||
|
||||
update_test_language_settings(cx, &|settings| {
|
||||
settings.defaults.document_symbols = Some(DocumentSymbols::On);
|
||||
});
|
||||
|
||||
let mut cx = EditorLspTestContext::new_rust(
|
||||
lsp::ServerCapabilities {
|
||||
document_symbol_provider: Some(lsp::OneOf::Left(true)),
|
||||
..lsp::ServerCapabilities::default()
|
||||
},
|
||||
cx,
|
||||
)
|
||||
.await;
|
||||
cx.update_editor(|editor, _window, cx| {
|
||||
editor
|
||||
.project
|
||||
.as_ref()
|
||||
.expect("editor should have a project")
|
||||
.read(cx)
|
||||
.languages()
|
||||
.set_theme(cx.theme().clone());
|
||||
});
|
||||
let mut symbol_request = cx
|
||||
.set_request_handler::<lsp::request::DocumentSymbolRequest, _, _>(
|
||||
move |_, _, _| async move {
|
||||
Ok(Some(lsp::DocumentSymbolResponse::Nested(vec![
|
||||
nested_symbol(
|
||||
"impl ZzzMissing",
|
||||
lsp::SymbolKind::OBJECT,
|
||||
lsp_range(0, 0, 0, 12),
|
||||
lsp_range(0, 3, 0, 7),
|
||||
Vec::new(),
|
||||
),
|
||||
])))
|
||||
},
|
||||
);
|
||||
|
||||
cx.set_state("fn teˇst() {}\n");
|
||||
assert!(symbol_request.next().await.is_some());
|
||||
cx.run_until_parked();
|
||||
|
||||
cx.update_editor(|editor, _window, cx| {
|
||||
let (_, symbols) = editor
|
||||
.outline_symbols_at_cursor
|
||||
.as_ref()
|
||||
.expect("Should have outline symbols");
|
||||
assert_eq!(symbols.len(), 1);
|
||||
let symbol = &symbols[0];
|
||||
assert_eq!(symbol.text, "impl ZzzMissing");
|
||||
|
||||
let language = editor
|
||||
.buffer
|
||||
.read(cx)
|
||||
.as_singleton()
|
||||
.expect("singleton buffer")
|
||||
.read(cx)
|
||||
.language()
|
||||
.cloned()
|
||||
.expect("buffer language");
|
||||
let expected = highlight_ranges_from_text(&symbol.text, &language, cx.theme().syntax());
|
||||
assert_eq!(
|
||||
expected.first().map(|(range, _)| range.clone()),
|
||||
Some(0..4),
|
||||
"reparsing the symbol text should highlight the `impl` keyword"
|
||||
);
|
||||
assert_eq!(symbol.highlight_ranges, expected);
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_lsp_document_symbols_empty_response(cx: &mut TestAppContext) {
|
||||
init_test(cx, |_| {});
|
||||
|
||||
Reference in new issue
Block a user