Compare commits
14 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1c79b17168 | ||
![]() |
e13cbc5230 | ||
![]() |
4dfe245e0e | ||
![]() |
6c44fc59b7 | ||
![]() |
93498cac24 | ||
![]() |
af8903b310 | ||
![]() |
ba3ce6e18d | ||
![]() |
bd716f758d | ||
![]() |
df882e260a | ||
![]() |
c28af10a7c | ||
![]() |
cc2a803103 | ||
![]() |
5509c8c9ff | ||
![]() |
5121702e6c | ||
![]() |
3930f3bf14 |
13 changed files with 461 additions and 133 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -9339,7 +9339,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "zed"
|
||||
version = "0.94.0"
|
||||
version = "0.94.4"
|
||||
dependencies = [
|
||||
"activity_indicator",
|
||||
"ai",
|
||||
|
|
|
@ -147,8 +147,9 @@ impl AssistantPanel {
|
|||
.await
|
||||
.log_err()
|
||||
.unwrap_or_default();
|
||||
this.update(&mut cx, |this, _| {
|
||||
this.saved_conversations = saved_conversations
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.saved_conversations = saved_conversations;
|
||||
cx.notify();
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ use gpui::{
|
|||
};
|
||||
use indoc::indoc;
|
||||
use language::{
|
||||
language_settings::{AllLanguageSettings, Formatter, InlayHintKind, InlayHintSettings},
|
||||
language_settings::{AllLanguageSettings, Formatter, InlayHintSettings},
|
||||
tree_sitter_rust, Anchor, Diagnostic, DiagnosticEntry, FakeLspAdapter, Language,
|
||||
LanguageConfig, OffsetRangeExt, Point, Rope,
|
||||
};
|
||||
|
@ -7843,7 +7843,6 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
|||
});
|
||||
});
|
||||
});
|
||||
let allowed_hint_kinds = HashSet::from_iter([None, Some(InlayHintKind::Type)]);
|
||||
|
||||
let mut language = Language::new(
|
||||
LanguageConfig {
|
||||
|
@ -7955,10 +7954,6 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
|||
"Host should get its first hints when opens an editor"
|
||||
);
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(
|
||||
inlay_cache.allowed_hint_kinds, allowed_hint_kinds,
|
||||
"Cache should use editor settings to get the allowed hint kinds"
|
||||
);
|
||||
assert_eq!(
|
||||
inlay_cache.version, edits_made,
|
||||
"Host editor update the cache version after every cache/view change",
|
||||
|
@ -7982,10 +7977,6 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
|||
"Client should get its first hints when opens an editor"
|
||||
);
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(
|
||||
inlay_cache.allowed_hint_kinds, allowed_hint_kinds,
|
||||
"Cache should use editor settings to get the allowed hint kinds"
|
||||
);
|
||||
assert_eq!(
|
||||
inlay_cache.version, edits_made,
|
||||
"Guest editor update the cache version after every cache/view change"
|
||||
|
@ -8007,10 +7998,6 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
|||
"Host should get hints from the 1st edit and 1st LSP query"
|
||||
);
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(
|
||||
inlay_cache.allowed_hint_kinds, allowed_hint_kinds,
|
||||
"Inlay kinds settings never change during the test"
|
||||
);
|
||||
assert_eq!(inlay_cache.version, edits_made);
|
||||
});
|
||||
editor_b.update(cx_b, |editor, _| {
|
||||
|
@ -8025,10 +8012,6 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
|||
"Guest should get hints the 1st edit and 2nd LSP query"
|
||||
);
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(
|
||||
inlay_cache.allowed_hint_kinds, allowed_hint_kinds,
|
||||
"Inlay kinds settings never change during the test"
|
||||
);
|
||||
assert_eq!(inlay_cache.version, edits_made);
|
||||
});
|
||||
|
||||
|
@ -8054,10 +8037,6 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
|||
4th query was made by guest (but not applied) due to cache invalidation logic"
|
||||
);
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(
|
||||
inlay_cache.allowed_hint_kinds, allowed_hint_kinds,
|
||||
"Inlay kinds settings never change during the test"
|
||||
);
|
||||
assert_eq!(inlay_cache.version, edits_made);
|
||||
});
|
||||
editor_b.update(cx_b, |editor, _| {
|
||||
|
@ -8074,10 +8053,6 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
|||
"Guest should get hints from 3rd edit, 6th LSP query"
|
||||
);
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(
|
||||
inlay_cache.allowed_hint_kinds, allowed_hint_kinds,
|
||||
"Inlay kinds settings never change during the test"
|
||||
);
|
||||
assert_eq!(inlay_cache.version, edits_made);
|
||||
});
|
||||
|
||||
|
@ -8103,10 +8078,6 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
|||
"Host should react to /refresh LSP request and get new hints from 7th LSP query"
|
||||
);
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(
|
||||
inlay_cache.allowed_hint_kinds, allowed_hint_kinds,
|
||||
"Inlay kinds settings never change during the test"
|
||||
);
|
||||
assert_eq!(
|
||||
inlay_cache.version, edits_made,
|
||||
"Host should accepted all edits and bump its cache version every time"
|
||||
|
@ -8128,10 +8099,6 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
|||
"Guest should get a /refresh LSP request propagated by host and get new hints from 8th LSP query"
|
||||
);
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(
|
||||
inlay_cache.allowed_hint_kinds, allowed_hint_kinds,
|
||||
"Inlay kinds settings never change during the test"
|
||||
);
|
||||
assert_eq!(
|
||||
inlay_cache.version,
|
||||
edits_made,
|
||||
|
@ -8164,9 +8131,9 @@ async fn test_inlay_hint_refresh_is_forwarded(
|
|||
store.update_user_settings::<AllLanguageSettings>(cx, |settings| {
|
||||
settings.defaults.inlay_hints = Some(InlayHintSettings {
|
||||
enabled: false,
|
||||
show_type_hints: true,
|
||||
show_type_hints: false,
|
||||
show_parameter_hints: false,
|
||||
show_other_hints: true,
|
||||
show_other_hints: false,
|
||||
})
|
||||
});
|
||||
});
|
||||
|
@ -8177,13 +8144,12 @@ async fn test_inlay_hint_refresh_is_forwarded(
|
|||
settings.defaults.inlay_hints = Some(InlayHintSettings {
|
||||
enabled: true,
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: false,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
let allowed_hint_kinds = HashSet::from_iter([None, Some(InlayHintKind::Type)]);
|
||||
|
||||
let mut language = Language::new(
|
||||
LanguageConfig {
|
||||
|
@ -8299,10 +8265,6 @@ async fn test_inlay_hint_refresh_is_forwarded(
|
|||
"Host should get no hints due to them turned off"
|
||||
);
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(
|
||||
inlay_cache.allowed_hint_kinds, allowed_hint_kinds,
|
||||
"Host should have allowed hint kinds set despite hints are off"
|
||||
);
|
||||
assert_eq!(
|
||||
inlay_cache.version, 0,
|
||||
"Host should not increment its cache version due to no changes",
|
||||
|
@ -8318,10 +8280,6 @@ async fn test_inlay_hint_refresh_is_forwarded(
|
|||
"Client should get its first hints when opens an editor"
|
||||
);
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(
|
||||
inlay_cache.allowed_hint_kinds, allowed_hint_kinds,
|
||||
"Cache should use editor settings to get the allowed hint kinds"
|
||||
);
|
||||
assert_eq!(
|
||||
inlay_cache.version, edits_made,
|
||||
"Guest editor update the cache version after every cache/view change"
|
||||
|
@ -8339,7 +8297,6 @@ async fn test_inlay_hint_refresh_is_forwarded(
|
|||
"Host should get nop hints due to them turned off, even after the /refresh"
|
||||
);
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(
|
||||
inlay_cache.version, 0,
|
||||
"Host should not increment its cache version due to no changes",
|
||||
|
@ -8355,10 +8312,6 @@ async fn test_inlay_hint_refresh_is_forwarded(
|
|||
"Guest should get a /refresh LSP request propagated by host despite host hints are off"
|
||||
);
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(
|
||||
inlay_cache.allowed_hint_kinds, allowed_hint_kinds,
|
||||
"Inlay kinds settings never change during the test"
|
||||
);
|
||||
assert_eq!(
|
||||
inlay_cache.version, edits_made,
|
||||
"Guest should accepted all edits and bump its cache version every time"
|
||||
|
|
|
@ -22,7 +22,10 @@ use language::{
|
|||
BracketPairConfig, FakeLspAdapter, LanguageConfig, LanguageRegistry, Point,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use project::project_settings::{LspSettings, ProjectSettings};
|
||||
use project::FakeFs;
|
||||
use std::sync::atomic;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::{cell::RefCell, future::Future, rc::Rc, time::Instant};
|
||||
use unindent::Unindent;
|
||||
use util::{
|
||||
|
@ -1796,7 +1799,7 @@ async fn test_newline_comments(cx: &mut gpui::TestAppContext) {
|
|||
"});
|
||||
}
|
||||
// Ensure that comment continuations can be disabled.
|
||||
update_test_settings(cx, |settings| {
|
||||
update_test_language_settings(cx, |settings| {
|
||||
settings.defaults.extend_comment_on_newline = Some(false);
|
||||
});
|
||||
let mut cx = EditorTestContext::new(cx).await;
|
||||
|
@ -4546,7 +4549,7 @@ async fn test_document_format_during_save(cx: &mut gpui::TestAppContext) {
|
|||
assert!(!cx.read(|cx| editor.is_dirty(cx)));
|
||||
|
||||
// Set rust language override and assert overridden tabsize is sent to language server
|
||||
update_test_settings(cx, |settings| {
|
||||
update_test_language_settings(cx, |settings| {
|
||||
settings.languages.insert(
|
||||
"Rust".into(),
|
||||
LanguageSettingsContent {
|
||||
|
@ -4660,7 +4663,7 @@ async fn test_range_format_during_save(cx: &mut gpui::TestAppContext) {
|
|||
assert!(!cx.read(|cx| editor.is_dirty(cx)));
|
||||
|
||||
// Set rust language override and assert overridden tabsize is sent to language server
|
||||
update_test_settings(cx, |settings| {
|
||||
update_test_language_settings(cx, |settings| {
|
||||
settings.languages.insert(
|
||||
"Rust".into(),
|
||||
LanguageSettingsContent {
|
||||
|
@ -7084,6 +7087,142 @@ async fn test_on_type_formatting_not_triggered(cx: &mut gpui::TestAppContext) {
|
|||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_language_server_restart_due_to_settings_change(cx: &mut gpui::TestAppContext) {
|
||||
init_test(cx, |_| {});
|
||||
|
||||
let language_name: Arc<str> = "Rust".into();
|
||||
let mut language = Language::new(
|
||||
LanguageConfig {
|
||||
name: Arc::clone(&language_name),
|
||||
path_suffixes: vec!["rs".to_string()],
|
||||
..Default::default()
|
||||
},
|
||||
Some(tree_sitter_rust::language()),
|
||||
);
|
||||
|
||||
let server_restarts = Arc::new(AtomicUsize::new(0));
|
||||
let closure_restarts = Arc::clone(&server_restarts);
|
||||
let language_server_name = "test language server";
|
||||
let mut fake_servers = language
|
||||
.set_fake_lsp_adapter(Arc::new(FakeLspAdapter {
|
||||
name: language_server_name,
|
||||
initialization_options: Some(json!({
|
||||
"testOptionValue": true
|
||||
})),
|
||||
initializer: Some(Box::new(move |fake_server| {
|
||||
let task_restarts = Arc::clone(&closure_restarts);
|
||||
fake_server.handle_request::<lsp::request::Shutdown, _, _>(move |_, _| {
|
||||
task_restarts.fetch_add(1, atomic::Ordering::Release);
|
||||
futures::future::ready(Ok(()))
|
||||
});
|
||||
})),
|
||||
..Default::default()
|
||||
}))
|
||||
.await;
|
||||
|
||||
let fs = FakeFs::new(cx.background());
|
||||
fs.insert_tree(
|
||||
"/a",
|
||||
json!({
|
||||
"main.rs": "fn main() { let a = 5; }",
|
||||
"other.rs": "// Test file",
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
let project = Project::test(fs, ["/a".as_ref()], cx).await;
|
||||
project.update(cx, |project, _| project.languages().add(Arc::new(language)));
|
||||
let (_, _workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let _buffer = project
|
||||
.update(cx, |project, cx| {
|
||||
project.open_local_buffer("/a/main.rs", cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let _fake_server = fake_servers.next().await.unwrap();
|
||||
update_test_language_settings(cx, |language_settings| {
|
||||
language_settings.languages.insert(
|
||||
Arc::clone(&language_name),
|
||||
LanguageSettingsContent {
|
||||
tab_size: NonZeroU32::new(8),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
});
|
||||
cx.foreground().run_until_parked();
|
||||
assert_eq!(
|
||||
server_restarts.load(atomic::Ordering::Acquire),
|
||||
0,
|
||||
"Should not restart LSP server on an unrelated change"
|
||||
);
|
||||
|
||||
update_test_project_settings(cx, |project_settings| {
|
||||
project_settings.lsp.insert(
|
||||
"Some other server name".into(),
|
||||
LspSettings {
|
||||
initialization_options: Some(json!({
|
||||
"some other init value": false
|
||||
})),
|
||||
},
|
||||
);
|
||||
});
|
||||
cx.foreground().run_until_parked();
|
||||
assert_eq!(
|
||||
server_restarts.load(atomic::Ordering::Acquire),
|
||||
0,
|
||||
"Should not restart LSP server on an unrelated LSP settings change"
|
||||
);
|
||||
|
||||
update_test_project_settings(cx, |project_settings| {
|
||||
project_settings.lsp.insert(
|
||||
language_server_name.into(),
|
||||
LspSettings {
|
||||
initialization_options: Some(json!({
|
||||
"anotherInitValue": false
|
||||
})),
|
||||
},
|
||||
);
|
||||
});
|
||||
cx.foreground().run_until_parked();
|
||||
assert_eq!(
|
||||
server_restarts.load(atomic::Ordering::Acquire),
|
||||
1,
|
||||
"Should restart LSP server on a related LSP settings change"
|
||||
);
|
||||
|
||||
update_test_project_settings(cx, |project_settings| {
|
||||
project_settings.lsp.insert(
|
||||
language_server_name.into(),
|
||||
LspSettings {
|
||||
initialization_options: Some(json!({
|
||||
"anotherInitValue": false
|
||||
})),
|
||||
},
|
||||
);
|
||||
});
|
||||
cx.foreground().run_until_parked();
|
||||
assert_eq!(
|
||||
server_restarts.load(atomic::Ordering::Acquire),
|
||||
1,
|
||||
"Should not restart LSP server on a related LSP settings change that is the same"
|
||||
);
|
||||
|
||||
update_test_project_settings(cx, |project_settings| {
|
||||
project_settings.lsp.insert(
|
||||
language_server_name.into(),
|
||||
LspSettings {
|
||||
initialization_options: None,
|
||||
},
|
||||
);
|
||||
});
|
||||
cx.foreground().run_until_parked();
|
||||
assert_eq!(
|
||||
server_restarts.load(atomic::Ordering::Acquire),
|
||||
2,
|
||||
"Should restart LSP server on another related LSP settings change"
|
||||
);
|
||||
}
|
||||
|
||||
fn empty_range(row: usize, column: usize) -> Range<DisplayPoint> {
|
||||
let point = DisplayPoint::new(row as u32, column as u32);
|
||||
point..point
|
||||
|
@ -7203,7 +7342,7 @@ fn handle_copilot_completion_request(
|
|||
});
|
||||
}
|
||||
|
||||
pub(crate) fn update_test_settings(
|
||||
pub(crate) fn update_test_language_settings(
|
||||
cx: &mut TestAppContext,
|
||||
f: impl Fn(&mut AllLanguageSettingsContent),
|
||||
) {
|
||||
|
@ -7214,6 +7353,17 @@ pub(crate) fn update_test_settings(
|
|||
});
|
||||
}
|
||||
|
||||
pub(crate) fn update_test_project_settings(
|
||||
cx: &mut TestAppContext,
|
||||
f: impl Fn(&mut ProjectSettings),
|
||||
) {
|
||||
cx.update(|cx| {
|
||||
cx.update_global::<SettingsStore, _, _>(|store, cx| {
|
||||
store.update_user_settings::<ProjectSettings>(cx, f);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn init_test(cx: &mut TestAppContext, f: fn(&mut AllLanguageSettingsContent)) {
|
||||
cx.foreground().forbid_parking();
|
||||
|
||||
|
@ -7227,5 +7377,5 @@ pub(crate) fn init_test(cx: &mut TestAppContext, f: fn(&mut AllLanguageSettingsC
|
|||
crate::init(cx);
|
||||
});
|
||||
|
||||
update_test_settings(cx, f);
|
||||
update_test_language_settings(cx, f);
|
||||
}
|
||||
|
|
|
@ -2845,7 +2845,7 @@ mod tests {
|
|||
use super::*;
|
||||
use crate::{
|
||||
display_map::{BlockDisposition, BlockProperties},
|
||||
editor_tests::{init_test, update_test_settings},
|
||||
editor_tests::{init_test, update_test_language_settings},
|
||||
Editor, MultiBuffer,
|
||||
};
|
||||
use gpui::TestAppContext;
|
||||
|
@ -3042,7 +3042,7 @@ mod tests {
|
|||
let resize_step = 10.0;
|
||||
let mut editor_width = 200.0;
|
||||
while editor_width <= 1000.0 {
|
||||
update_test_settings(cx, |s| {
|
||||
update_test_language_settings(cx, |s| {
|
||||
s.defaults.tab_size = NonZeroU32::new(tab_size);
|
||||
s.defaults.show_whitespaces = Some(ShowWhitespaceSetting::All);
|
||||
s.defaults.preferred_line_length = Some(editor_width as u32);
|
||||
|
|
|
@ -833,7 +833,7 @@ mod tests {
|
|||
use crate::{
|
||||
scroll::{autoscroll::Autoscroll, scroll_amount::ScrollAmount},
|
||||
serde_json::json,
|
||||
ExcerptRange, InlayHintSettings,
|
||||
ExcerptRange,
|
||||
};
|
||||
use futures::StreamExt;
|
||||
use gpui::{executor::Deterministic, TestAppContext, ViewHandle};
|
||||
|
@ -847,7 +847,7 @@ mod tests {
|
|||
use text::Point;
|
||||
use workspace::Workspace;
|
||||
|
||||
use crate::editor_tests::update_test_settings;
|
||||
use crate::editor_tests::update_test_language_settings;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -975,14 +975,124 @@ mod tests {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_no_hint_updates_for_unrelated_language_files(cx: &mut gpui::TestAppContext) {
|
||||
let allowed_hint_kinds = HashSet::from_iter([None, Some(InlayHintKind::Type)]);
|
||||
async fn test_cache_update_on_lsp_completion_tasks(cx: &mut gpui::TestAppContext) {
|
||||
init_test(cx, |settings| {
|
||||
settings.defaults.inlay_hints = Some(InlayHintSettings {
|
||||
enabled: true,
|
||||
show_type_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Type)),
|
||||
show_parameter_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Parameter)),
|
||||
show_other_hints: allowed_hint_kinds.contains(&None),
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
})
|
||||
});
|
||||
|
||||
let (file_with_hints, editor, fake_server) = prepare_test_objects(cx).await;
|
||||
let lsp_request_count = Arc::new(AtomicU32::new(0));
|
||||
fake_server
|
||||
.handle_request::<lsp::request::InlayHintRequest, _, _>(move |params, _| {
|
||||
let task_lsp_request_count = Arc::clone(&lsp_request_count);
|
||||
async move {
|
||||
assert_eq!(
|
||||
params.text_document.uri,
|
||||
lsp::Url::from_file_path(file_with_hints).unwrap(),
|
||||
);
|
||||
let current_call_id =
|
||||
Arc::clone(&task_lsp_request_count).fetch_add(1, Ordering::SeqCst);
|
||||
Ok(Some(vec![lsp::InlayHint {
|
||||
position: lsp::Position::new(0, current_call_id),
|
||||
label: lsp::InlayHintLabel::String(current_call_id.to_string()),
|
||||
kind: None,
|
||||
text_edits: None,
|
||||
tooltip: None,
|
||||
padding_left: None,
|
||||
padding_right: None,
|
||||
data: None,
|
||||
}]))
|
||||
}
|
||||
})
|
||||
.next()
|
||||
.await;
|
||||
cx.foreground().run_until_parked();
|
||||
|
||||
let mut edits_made = 1;
|
||||
editor.update(cx, |editor, cx| {
|
||||
let expected_layers = vec!["0".to_string()];
|
||||
assert_eq!(
|
||||
expected_layers,
|
||||
cached_hint_labels(editor),
|
||||
"Should get its first hints when opening the editor"
|
||||
);
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(
|
||||
inlay_cache.version, edits_made,
|
||||
"The editor update the cache version after every cache/view change"
|
||||
);
|
||||
});
|
||||
|
||||
let progress_token = "test_progress_token";
|
||||
fake_server
|
||||
.request::<lsp::request::WorkDoneProgressCreate>(lsp::WorkDoneProgressCreateParams {
|
||||
token: lsp::ProgressToken::String(progress_token.to_string()),
|
||||
})
|
||||
.await
|
||||
.expect("work done progress create request failed");
|
||||
cx.foreground().run_until_parked();
|
||||
fake_server.notify::<lsp::notification::Progress>(lsp::ProgressParams {
|
||||
token: lsp::ProgressToken::String(progress_token.to_string()),
|
||||
value: lsp::ProgressParamsValue::WorkDone(lsp::WorkDoneProgress::Begin(
|
||||
lsp::WorkDoneProgressBegin::default(),
|
||||
)),
|
||||
});
|
||||
cx.foreground().run_until_parked();
|
||||
|
||||
editor.update(cx, |editor, cx| {
|
||||
let expected_layers = vec!["0".to_string()];
|
||||
assert_eq!(
|
||||
expected_layers,
|
||||
cached_hint_labels(editor),
|
||||
"Should not update hints while the work task is running"
|
||||
);
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(
|
||||
inlay_cache.version, edits_made,
|
||||
"Should not update the cache while the work task is running"
|
||||
);
|
||||
});
|
||||
|
||||
fake_server.notify::<lsp::notification::Progress>(lsp::ProgressParams {
|
||||
token: lsp::ProgressToken::String(progress_token.to_string()),
|
||||
value: lsp::ProgressParamsValue::WorkDone(lsp::WorkDoneProgress::End(
|
||||
lsp::WorkDoneProgressEnd::default(),
|
||||
)),
|
||||
});
|
||||
cx.foreground().run_until_parked();
|
||||
|
||||
edits_made += 1;
|
||||
editor.update(cx, |editor, cx| {
|
||||
let expected_layers = vec!["1".to_string()];
|
||||
assert_eq!(
|
||||
expected_layers,
|
||||
cached_hint_labels(editor),
|
||||
"New hints should be queried after the work task is done"
|
||||
);
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(
|
||||
inlay_cache.version, edits_made,
|
||||
"Cache version should udpate once after the work task is done"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_no_hint_updates_for_unrelated_language_files(cx: &mut gpui::TestAppContext) {
|
||||
init_test(cx, |settings| {
|
||||
settings.defaults.inlay_hints = Some(InlayHintSettings {
|
||||
enabled: true,
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -1085,10 +1195,6 @@ mod tests {
|
|||
);
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(
|
||||
inlay_cache.allowed_hint_kinds, allowed_hint_kinds,
|
||||
"Cache should use editor settings to get the allowed hint kinds"
|
||||
);
|
||||
assert_eq!(
|
||||
inlay_cache.version, 1,
|
||||
"Rust editor update the cache version after every cache/view change"
|
||||
|
@ -1147,7 +1253,6 @@ mod tests {
|
|||
);
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(inlay_cache.version, 1);
|
||||
});
|
||||
|
||||
|
@ -1165,7 +1270,6 @@ mod tests {
|
|||
);
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(
|
||||
inlay_cache.version, 2,
|
||||
"Every time hint cache changes, cache version should be incremented"
|
||||
|
@ -1180,7 +1284,6 @@ mod tests {
|
|||
);
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(inlay_cache.version, 1);
|
||||
});
|
||||
|
||||
|
@ -1198,7 +1301,6 @@ mod tests {
|
|||
);
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(inlay_cache.version, 2);
|
||||
});
|
||||
rs_editor.update(cx, |editor, cx| {
|
||||
|
@ -1210,7 +1312,6 @@ mod tests {
|
|||
);
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(inlay_cache.version, 2);
|
||||
});
|
||||
}
|
||||
|
@ -1333,7 +1434,6 @@ mod tests {
|
|||
visible_hint_labels(editor, cx)
|
||||
);
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(
|
||||
inlay_cache.version, edits_made,
|
||||
"Should not update cache version due to new loaded hints being the same"
|
||||
|
@ -1376,7 +1476,7 @@ mod tests {
|
|||
),
|
||||
] {
|
||||
edits_made += 1;
|
||||
update_test_settings(cx, |settings| {
|
||||
update_test_language_settings(cx, |settings| {
|
||||
settings.defaults.inlay_hints = Some(InlayHintSettings {
|
||||
enabled: true,
|
||||
show_type_hints: new_allowed_hint_kinds.contains(&Some(InlayHintKind::Type)),
|
||||
|
@ -1420,7 +1520,7 @@ mod tests {
|
|||
|
||||
edits_made += 1;
|
||||
let another_allowed_hint_kinds = HashSet::from_iter([Some(InlayHintKind::Type)]);
|
||||
update_test_settings(cx, |settings| {
|
||||
update_test_language_settings(cx, |settings| {
|
||||
settings.defaults.inlay_hints = Some(InlayHintSettings {
|
||||
enabled: false,
|
||||
show_type_hints: another_allowed_hint_kinds.contains(&Some(InlayHintKind::Type)),
|
||||
|
@ -1469,7 +1569,6 @@ mod tests {
|
|||
assert!(cached_hint_labels(editor).is_empty());
|
||||
assert!(visible_hint_labels(editor, cx).is_empty());
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, another_allowed_hint_kinds);
|
||||
assert_eq!(
|
||||
inlay_cache.version, edits_made,
|
||||
"The editor should not update the cache version after /refresh query without updates"
|
||||
|
@ -1478,7 +1577,7 @@ mod tests {
|
|||
|
||||
let final_allowed_hint_kinds = HashSet::from_iter([Some(InlayHintKind::Parameter)]);
|
||||
edits_made += 1;
|
||||
update_test_settings(cx, |settings| {
|
||||
update_test_language_settings(cx, |settings| {
|
||||
settings.defaults.inlay_hints = Some(InlayHintSettings {
|
||||
enabled: true,
|
||||
show_type_hints: final_allowed_hint_kinds.contains(&Some(InlayHintKind::Type)),
|
||||
|
@ -1543,20 +1642,18 @@ mod tests {
|
|||
visible_hint_labels(editor, cx),
|
||||
);
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, final_allowed_hint_kinds);
|
||||
assert_eq!(inlay_cache.version, edits_made);
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_hint_request_cancellation(cx: &mut gpui::TestAppContext) {
|
||||
let allowed_hint_kinds = HashSet::from_iter([None]);
|
||||
init_test(cx, |settings| {
|
||||
settings.defaults.inlay_hints = Some(InlayHintSettings {
|
||||
enabled: true,
|
||||
show_type_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Type)),
|
||||
show_parameter_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Parameter)),
|
||||
show_other_hints: allowed_hint_kinds.contains(&None),
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -1624,7 +1721,6 @@ mod tests {
|
|||
);
|
||||
assert_eq!(expected_hints, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(
|
||||
inlay_cache.version, 1,
|
||||
"Only one update should be registered in the cache after all cancellations"
|
||||
|
@ -1671,7 +1767,6 @@ mod tests {
|
|||
);
|
||||
assert_eq!(expected_hints, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(
|
||||
inlay_cache.version, 2,
|
||||
"Should update the cache version once more, for the new change"
|
||||
|
@ -1681,13 +1776,12 @@ mod tests {
|
|||
|
||||
#[gpui::test]
|
||||
async fn test_large_buffer_inlay_requests_split(cx: &mut gpui::TestAppContext) {
|
||||
let allowed_hint_kinds = HashSet::from_iter([None, Some(InlayHintKind::Type)]);
|
||||
init_test(cx, |settings| {
|
||||
settings.defaults.inlay_hints = Some(InlayHintSettings {
|
||||
enabled: true,
|
||||
show_type_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Type)),
|
||||
show_parameter_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Parameter)),
|
||||
show_other_hints: allowed_hint_kinds.contains(&None),
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -1793,7 +1887,6 @@ mod tests {
|
|||
);
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(
|
||||
inlay_cache.version, 2,
|
||||
"Both LSP queries should've bumped the cache version"
|
||||
|
@ -1826,7 +1919,6 @@ mod tests {
|
|||
"Should have hints from the new LSP response after edit");
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(inlay_cache.version, 5, "Should update the cache for every LSP response with hints added");
|
||||
});
|
||||
}
|
||||
|
@ -1836,13 +1928,12 @@ mod tests {
|
|||
deterministic: Arc<Deterministic>,
|
||||
cx: &mut gpui::TestAppContext,
|
||||
) {
|
||||
let allowed_hint_kinds = HashSet::from_iter([None, Some(InlayHintKind::Type)]);
|
||||
init_test(cx, |settings| {
|
||||
settings.defaults.inlay_hints = Some(InlayHintSettings {
|
||||
enabled: true,
|
||||
show_type_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Type)),
|
||||
show_parameter_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Parameter)),
|
||||
show_other_hints: allowed_hint_kinds.contains(&None),
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -2048,7 +2139,6 @@ mod tests {
|
|||
);
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(inlay_cache.version, 4, "Every visible excerpt hints should bump the verison");
|
||||
});
|
||||
|
||||
|
@ -2080,7 +2170,6 @@ mod tests {
|
|||
"With more scrolls of the multibuffer, more hints should be added into the cache and nothing invalidated without edits");
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(inlay_cache.version, 9);
|
||||
});
|
||||
|
||||
|
@ -2109,7 +2198,6 @@ mod tests {
|
|||
"After multibuffer was scrolled to the end, all hints for all excerpts should be fetched");
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(inlay_cache.version, 12);
|
||||
});
|
||||
|
||||
|
@ -2138,7 +2226,6 @@ mod tests {
|
|||
"After multibuffer was scrolled to the end, further scrolls up should not bring more hints");
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(inlay_cache.version, 12, "No updates should happen during scrolling already scolled buffer");
|
||||
});
|
||||
|
||||
|
@ -2165,7 +2252,6 @@ mod tests {
|
|||
unedited (2nd) buffer should have the same hint");
|
||||
assert_eq!(expected_layers, visible_hint_labels(editor, cx));
|
||||
let inlay_cache = editor.inlay_hint_cache();
|
||||
assert_eq!(inlay_cache.allowed_hint_kinds, allowed_hint_kinds);
|
||||
assert_eq!(inlay_cache.version, 16);
|
||||
});
|
||||
}
|
||||
|
@ -2183,7 +2269,7 @@ unedited (2nd) buffer should have the same hint");
|
|||
crate::init(cx);
|
||||
});
|
||||
|
||||
update_test_settings(cx, f);
|
||||
update_test_language_settings(cx, f);
|
||||
}
|
||||
|
||||
async fn prepare_test_objects(
|
||||
|
|
|
@ -263,13 +263,13 @@ pub fn find_preceding_boundary(
|
|||
|
||||
if let Some((prev_ch, prev_point)) = prev {
|
||||
if is_boundary(ch, prev_ch) {
|
||||
return prev_point;
|
||||
return map.clip_point(prev_point, Bias::Left);
|
||||
}
|
||||
}
|
||||
|
||||
prev = Some((ch, point));
|
||||
}
|
||||
DisplayPoint::zero()
|
||||
map.clip_point(DisplayPoint::zero(), Bias::Left)
|
||||
}
|
||||
|
||||
/// Scans for a boundary preceding the given start point `from` until a boundary is found, indicated by the
|
||||
|
@ -292,7 +292,7 @@ pub fn find_preceding_boundary_in_line(
|
|||
for (ch, point) in map.reverse_chars_at(from) {
|
||||
if let Some((prev_ch, prev_point)) = prev {
|
||||
if is_boundary(ch, prev_ch) {
|
||||
return prev_point;
|
||||
return map.clip_point(prev_point, Bias::Left);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,7 +303,7 @@ pub fn find_preceding_boundary_in_line(
|
|||
prev = Some((ch, point));
|
||||
}
|
||||
|
||||
prev.map(|(_, point)| point).unwrap_or(from)
|
||||
map.clip_point(prev.map(|(_, point)| point).unwrap_or(from), Bias::Left)
|
||||
}
|
||||
|
||||
/// Scans for a boundary following the given start point until a boundary is found, indicated by the
|
||||
|
@ -406,8 +406,12 @@ pub fn split_display_range_by_lines(
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{test::marked_display_snapshot, Buffer, DisplayMap, ExcerptRange, MultiBuffer};
|
||||
use crate::{
|
||||
display_map::Inlay, test::marked_display_snapshot, Buffer, DisplayMap, ExcerptRange,
|
||||
InlayId, MultiBuffer,
|
||||
};
|
||||
use settings::SettingsStore;
|
||||
use util::post_inc;
|
||||
|
||||
#[gpui::test]
|
||||
fn test_previous_word_start(cx: &mut gpui::AppContext) {
|
||||
|
@ -505,6 +509,80 @@ mod tests {
|
|||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_find_preceding_boundary_with_inlays(cx: &mut gpui::AppContext) {
|
||||
init_test(cx);
|
||||
|
||||
let input_text = "abcdefghijklmnopqrstuvwxys";
|
||||
let family_id = cx
|
||||
.font_cache()
|
||||
.load_family(&["Helvetica"], &Default::default())
|
||||
.unwrap();
|
||||
let font_id = cx
|
||||
.font_cache()
|
||||
.select_font(family_id, &Default::default())
|
||||
.unwrap();
|
||||
let font_size = 14.0;
|
||||
let buffer = MultiBuffer::build_simple(input_text, cx);
|
||||
let buffer_snapshot = buffer.read(cx).snapshot(cx);
|
||||
let display_map =
|
||||
cx.add_model(|cx| DisplayMap::new(buffer, font_id, font_size, None, 1, 1, cx));
|
||||
|
||||
// add all kinds of inlays between two word boundaries: we should be able to cross them all, when looking for another boundary
|
||||
let mut id = 0;
|
||||
let inlays = (0..buffer_snapshot.len())
|
||||
.map(|offset| {
|
||||
[
|
||||
Inlay {
|
||||
id: InlayId::Suggestion(post_inc(&mut id)),
|
||||
position: buffer_snapshot.anchor_at(offset, Bias::Left),
|
||||
text: format!("test").into(),
|
||||
},
|
||||
Inlay {
|
||||
id: InlayId::Suggestion(post_inc(&mut id)),
|
||||
position: buffer_snapshot.anchor_at(offset, Bias::Right),
|
||||
text: format!("test").into(),
|
||||
},
|
||||
Inlay {
|
||||
id: InlayId::Hint(post_inc(&mut id)),
|
||||
position: buffer_snapshot.anchor_at(offset, Bias::Left),
|
||||
text: format!("test").into(),
|
||||
},
|
||||
Inlay {
|
||||
id: InlayId::Hint(post_inc(&mut id)),
|
||||
position: buffer_snapshot.anchor_at(offset, Bias::Right),
|
||||
text: format!("test").into(),
|
||||
},
|
||||
]
|
||||
})
|
||||
.flatten()
|
||||
.collect();
|
||||
let snapshot = display_map.update(cx, |map, cx| {
|
||||
map.splice_inlays(Vec::new(), inlays, cx);
|
||||
map.snapshot(cx)
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
find_preceding_boundary(
|
||||
&snapshot,
|
||||
buffer_snapshot.len().to_display_point(&snapshot),
|
||||
|left, _| left == 'a',
|
||||
),
|
||||
0.to_display_point(&snapshot),
|
||||
"Should not stop at inlays when looking for boundaries"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
find_preceding_boundary_in_line(
|
||||
&snapshot,
|
||||
buffer_snapshot.len().to_display_point(&snapshot),
|
||||
|left, _| left == 'a',
|
||||
),
|
||||
0.to_display_point(&snapshot),
|
||||
"Should not stop at inlays when looking for boundaries in line"
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_next_word_end(cx: &mut gpui::AppContext) {
|
||||
init_test(cx);
|
||||
|
|
|
@ -90,7 +90,8 @@ pub struct LanguageServerName(pub Arc<str>);
|
|||
/// once at startup, and caches the results.
|
||||
pub struct CachedLspAdapter {
|
||||
pub name: LanguageServerName,
|
||||
pub initialization_options: Option<Value>,
|
||||
initialization_options: Option<Value>,
|
||||
initialization_overrides: Mutex<Option<Value>>,
|
||||
pub disk_based_diagnostic_sources: Vec<String>,
|
||||
pub disk_based_diagnostics_progress_token: Option<String>,
|
||||
pub language_ids: HashMap<String, String>,
|
||||
|
@ -109,6 +110,7 @@ impl CachedLspAdapter {
|
|||
Arc::new(CachedLspAdapter {
|
||||
name,
|
||||
initialization_options,
|
||||
initialization_overrides: Mutex::new(None),
|
||||
disk_based_diagnostic_sources,
|
||||
disk_based_diagnostics_progress_token,
|
||||
language_ids,
|
||||
|
@ -208,6 +210,30 @@ impl CachedLspAdapter {
|
|||
) -> Option<CodeLabel> {
|
||||
self.adapter.label_for_symbol(name, kind, language).await
|
||||
}
|
||||
|
||||
pub fn update_initialization_overrides(&self, new: Option<&Value>) -> bool {
|
||||
let mut current = self.initialization_overrides.lock();
|
||||
if current.as_ref() != new {
|
||||
*current = new.cloned();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn initialization_options(&self) -> Option<Value> {
|
||||
let initialization_options = self.initialization_options.as_ref();
|
||||
let override_options = self.initialization_overrides.lock().clone();
|
||||
match (initialization_options, override_options) {
|
||||
(None, override_options) => override_options,
|
||||
(initialization_options, None) => initialization_options.cloned(),
|
||||
(Some(initialization_options), Some(override_options)) => {
|
||||
let mut initialization_options = initialization_options.clone();
|
||||
merge_json_value_into(override_options, &mut initialization_options);
|
||||
Some(initialization_options)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait LspAdapterDelegate: Send + Sync {
|
||||
|
@ -427,6 +453,7 @@ fn deserialize_regex<'de, D: Deserializer<'de>>(d: D) -> Result<Option<Regex>, D
|
|||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub struct FakeLspAdapter {
|
||||
pub name: &'static str,
|
||||
pub initialization_options: Option<Value>,
|
||||
pub capabilities: lsp::ServerCapabilities,
|
||||
pub initializer: Option<Box<dyn 'static + Send + Sync + Fn(&mut lsp::FakeLanguageServer)>>,
|
||||
pub disk_based_diagnostics_progress_token: Option<String>,
|
||||
|
@ -1637,6 +1664,7 @@ impl Default for FakeLspAdapter {
|
|||
capabilities: lsp::LanguageServer::full_capabilities(),
|
||||
initializer: None,
|
||||
disk_based_diagnostics_progress_token: None,
|
||||
initialization_options: None,
|
||||
disk_based_diagnostics_sources: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
@ -1686,6 +1714,10 @@ impl LspAdapter for Arc<FakeLspAdapter> {
|
|||
async fn disk_based_diagnostics_progress_token(&self) -> Option<String> {
|
||||
self.disk_based_diagnostics_progress_token.clone()
|
||||
}
|
||||
|
||||
async fn initialization_options(&self) -> Option<Value> {
|
||||
self.initialization_options.clone()
|
||||
}
|
||||
}
|
||||
|
||||
fn get_capture_indices(query: &Query, captures: &mut [(&str, &mut Option<u32>)]) {
|
||||
|
|
|
@ -1822,11 +1822,21 @@ impl LspCommand for InlayHints {
|
|||
async fn response_from_lsp(
|
||||
self,
|
||||
message: Option<Vec<lsp::InlayHint>>,
|
||||
_: ModelHandle<Project>,
|
||||
project: ModelHandle<Project>,
|
||||
buffer: ModelHandle<Buffer>,
|
||||
_: LanguageServerId,
|
||||
cx: AsyncAppContext,
|
||||
server_id: LanguageServerId,
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<Vec<InlayHint>> {
|
||||
let (lsp_adapter, _) = language_server_for_buffer(&project, &buffer, server_id, &mut cx)?;
|
||||
// `typescript-language-server` adds padding to the left for type hints, turning
|
||||
// `const foo: boolean` into `const foo : boolean` which looks odd.
|
||||
// `rust-analyzer` does not have the padding for this case, and we have to accomodate both.
|
||||
//
|
||||
// We could trim the whole string, but being pessimistic on par with the situation above,
|
||||
// there might be a hint with multiple whitespaces at the end(s) which we need to display properly.
|
||||
// Hence let's use a heuristic first to handle the most awkward case and look for more.
|
||||
let force_no_type_left_padding =
|
||||
lsp_adapter.name.0.as_ref() == "typescript-language-server";
|
||||
cx.read(|cx| {
|
||||
let origin_buffer = buffer.read(cx);
|
||||
Ok(message
|
||||
|
@ -1840,6 +1850,12 @@ impl LspCommand for InlayHints {
|
|||
});
|
||||
let position = origin_buffer
|
||||
.clip_point_utf16(point_from_lsp(lsp_hint.position), Bias::Left);
|
||||
let padding_left =
|
||||
if force_no_type_left_padding && kind == Some(InlayHintKind::Type) {
|
||||
false
|
||||
} else {
|
||||
lsp_hint.padding_left.unwrap_or(false)
|
||||
};
|
||||
InlayHint {
|
||||
buffer_id: origin_buffer.remote_id(),
|
||||
position: if kind == Some(InlayHintKind::Parameter) {
|
||||
|
@ -1847,7 +1863,7 @@ impl LspCommand for InlayHints {
|
|||
} else {
|
||||
origin_buffer.anchor_after(position)
|
||||
},
|
||||
padding_left: lsp_hint.padding_left.unwrap_or(false),
|
||||
padding_left,
|
||||
padding_right: lsp_hint.padding_right.unwrap_or(false),
|
||||
label: match lsp_hint.label {
|
||||
lsp::InlayHintLabel::String(s) => InlayHintLabel::String(s),
|
||||
|
|
|
@ -78,8 +78,8 @@ use std::{
|
|||
use terminals::Terminals;
|
||||
use text::Anchor;
|
||||
use util::{
|
||||
debug_panic, defer, http::HttpClient, merge_json_value_into,
|
||||
paths::LOCAL_SETTINGS_RELATIVE_PATH, post_inc, ResultExt, TryFutureExt as _,
|
||||
debug_panic, defer, http::HttpClient, paths::LOCAL_SETTINGS_RELATIVE_PATH, post_inc, ResultExt,
|
||||
TryFutureExt as _,
|
||||
};
|
||||
|
||||
pub use fs::*;
|
||||
|
@ -777,20 +777,32 @@ impl Project {
|
|||
}
|
||||
|
||||
let mut language_servers_to_stop = Vec::new();
|
||||
let mut language_servers_to_restart = Vec::new();
|
||||
let languages = self.languages.to_vec();
|
||||
let project_settings = settings::get::<ProjectSettings>(cx).clone();
|
||||
for (worktree_id, started_lsp_name) in self.language_server_ids.keys() {
|
||||
let language = languages.iter().find(|l| {
|
||||
l.lsp_adapters()
|
||||
let language = languages.iter().find_map(|l| {
|
||||
let adapter = l
|
||||
.lsp_adapters()
|
||||
.iter()
|
||||
.any(|adapter| &adapter.name == started_lsp_name)
|
||||
.find(|adapter| &adapter.name == started_lsp_name)?;
|
||||
Some((l, adapter))
|
||||
});
|
||||
if let Some(language) = language {
|
||||
if let Some((language, adapter)) = language {
|
||||
let worktree = self.worktree_for_id(*worktree_id, cx);
|
||||
let file = worktree.and_then(|tree| {
|
||||
let file = worktree.as_ref().and_then(|tree| {
|
||||
tree.update(cx, |tree, cx| tree.root_file(cx).map(|f| f as _))
|
||||
});
|
||||
if !language_settings(Some(language), file.as_ref(), cx).enable_language_server {
|
||||
language_servers_to_stop.push((*worktree_id, started_lsp_name.clone()));
|
||||
} else if let Some(worktree) = worktree {
|
||||
let new_lsp_settings = project_settings
|
||||
.lsp
|
||||
.get(&adapter.name.0)
|
||||
.and_then(|s| s.initialization_options.as_ref());
|
||||
if adapter.update_initialization_overrides(new_lsp_settings) {
|
||||
language_servers_to_restart.push((worktree, Arc::clone(language)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -807,6 +819,11 @@ impl Project {
|
|||
self.start_language_servers(&worktree, worktree_path, language, cx);
|
||||
}
|
||||
|
||||
// Restart all language servers with changed initialization options.
|
||||
for (worktree, language) in language_servers_to_restart {
|
||||
self.restart_language_servers(worktree, language, cx);
|
||||
}
|
||||
|
||||
if !self.copilot_enabled && Copilot::global(cx).is_some() {
|
||||
self.copilot_enabled = true;
|
||||
for buffer in self.opened_buffers.values() {
|
||||
|
@ -2528,20 +2545,13 @@ impl Project {
|
|||
let project_settings = settings::get::<ProjectSettings>(cx);
|
||||
let lsp = project_settings.lsp.get(&adapter.name.0);
|
||||
let override_options = lsp.map(|s| s.initialization_options.clone()).flatten();
|
||||
|
||||
let mut initialization_options = adapter.initialization_options.clone();
|
||||
match (&mut initialization_options, override_options) {
|
||||
(Some(initialization_options), Some(override_options)) => {
|
||||
merge_json_value_into(override_options, initialization_options);
|
||||
}
|
||||
(None, override_options) => initialization_options = override_options,
|
||||
_ => {}
|
||||
}
|
||||
adapter.update_initialization_overrides(override_options.as_ref());
|
||||
|
||||
let server_id = pending_server.server_id;
|
||||
let container_dir = pending_server.container_dir.clone();
|
||||
let state = LanguageServerState::Starting({
|
||||
let adapter = adapter.clone();
|
||||
let initialization_options = adapter.initialization_options();
|
||||
let server_name = adapter.name.0.clone();
|
||||
let languages = self.languages.clone();
|
||||
let language = language.clone();
|
||||
|
@ -3397,6 +3407,7 @@ impl Project {
|
|||
cx: &mut ModelContext<Self>,
|
||||
) {
|
||||
if let Some(status) = self.language_server_statuses.get_mut(&language_server_id) {
|
||||
cx.emit(Event::RefreshInlays);
|
||||
status.pending_work.remove(&token);
|
||||
cx.notify();
|
||||
}
|
||||
|
|
|
@ -4809,6 +4809,7 @@ mod tests {
|
|||
theme::init((), cx);
|
||||
language::init(cx);
|
||||
crate::init_settings(cx);
|
||||
Project::init_settings(cx);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ authors = ["Nathan Sobo <nathansobo@gmail.com>"]
|
|||
description = "The fast, collaborative code editor."
|
||||
edition = "2021"
|
||||
name = "zed"
|
||||
version = "0.94.0"
|
||||
version = "0.94.4"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
|
|
|
@ -1 +1 @@
|
|||
dev
|
||||
stable
|
Loading…
Add table
Add a link
Reference in a new issue