Skip to content

Commit 54a2995

Browse files
committed
Don't use capabilities for test mode detection
1 parent 46fe238 commit 54a2995

File tree

8 files changed

+32
-23
lines changed

8 files changed

+32
-23
lines changed

crates/ty/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,10 @@ impl MainLoop {
269269
// Spawn a new task that checks the project. This needs to be done in a separate thread
270270
// to prevent blocking the main loop here.
271271
rayon::spawn(move || {
272-
let reporter = IndicatifReporter::from(self.printer);
272+
let mut reporter = IndicatifReporter::from(self.printer);
273+
let bar = reporter.bar.clone();
274+
273275
match salsa::Cancelled::catch(|| {
274-
let mut reporter = reporter.clone();
275276
db.check_with_reporter(&mut reporter);
276277
reporter.collector.into_sorted(&db)
277278
}) {
@@ -282,7 +283,7 @@ impl MainLoop {
282283
.unwrap();
283284
}
284285
Err(cancelled) => {
285-
reporter.bar.finish_and_clear();
286+
bar.finish_and_clear();
286287
tracing::debug!("Check has been cancelled: {cancelled:?}");
287288
}
288289
}
@@ -392,7 +393,6 @@ impl MainLoop {
392393
}
393394

394395
/// A progress reporter for `ty check`.
395-
#[derive(Clone)]
396396
struct IndicatifReporter {
397397
collector: CollectReporter,
398398

crates/ty_server/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn run_server() -> anyhow::Result<()> {
4747
// This is to complement the `LSPSystem` if the document is not available in the index.
4848
let fallback_system = Arc::new(OsSystem::new(cwd));
4949

50-
let server_result = Server::new(worker_threads, connection, fallback_system, true)
50+
let server_result = Server::new(worker_threads, connection, fallback_system, false)
5151
.context("Failed to start server")?
5252
.run();
5353

crates/ty_server/src/server.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ pub use api::{PartialWorkspaceProgress, PartialWorkspaceProgressParams};
3333

3434
pub struct Server {
3535
connection: Connection,
36-
client_capabilities: ClientCapabilities,
3736
worker_threads: NonZeroUsize,
3837
main_loop_receiver: MainLoopReceiver,
3938
main_loop_sender: MainLoopSender,
@@ -45,7 +44,7 @@ impl Server {
4544
worker_threads: NonZeroUsize,
4645
connection: Connection,
4746
native_system: Arc<dyn System + 'static + Send + Sync + RefUnwindSafe>,
48-
initialize_logging: bool,
47+
in_test: bool,
4948
) -> crate::Result<Self> {
5049
let (id, init_value) = connection.initialize_start()?;
5150
let init_params: InitializeParams = serde_json::from_value(init_value)?;
@@ -82,7 +81,7 @@ impl Server {
8281
let (main_loop_sender, main_loop_receiver) = crossbeam::channel::bounded(32);
8382
let client = Client::new(main_loop_sender.clone(), connection.sender.clone());
8483

85-
if initialize_logging {
84+
if !in_test {
8685
crate::logging::init_logging(
8786
global_options.tracing.log_level.unwrap_or_default(),
8887
global_options.tracing.log_file.as_deref(),
@@ -161,8 +160,8 @@ impl Server {
161160
global_options,
162161
workspaces,
163162
native_system,
163+
in_test,
164164
)?,
165-
client_capabilities,
166165
})
167166
}
168167

crates/ty_server/src/server/api/requests/workspace_diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'a> ResponseWriter<'a> {
203203
first: true,
204204
client: client.clone(),
205205
token,
206-
is_test: snapshot.resolved_client_capabilities().is_test_server(),
206+
is_test: snapshot.in_test(),
207207
last_flush: Instant::now(),
208208
batched: Vec::new(),
209209
unchanged: Vec::with_capacity(previous_result_ids.len()),

crates/ty_server/src/server/main_loop.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,9 @@ impl Server {
227227
);
228228

229229
let fs_watcher = self
230-
.client_capabilities
231-
.workspace
232-
.as_ref()
233-
.and_then(|workspace| workspace.did_change_watched_files?.dynamic_registration)
234-
.unwrap_or_default();
230+
.session
231+
.client_capabilities()
232+
.supports_did_change_watched_files_dynamic_registration();
235233

236234
if fs_watcher {
237235
let registration = lsp_types::Registration {

crates/ty_server/src/session.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ pub(crate) struct Session {
7777
/// Has the client requested the server to shutdown.
7878
shutdown_requested: bool,
7979

80+
/// Is the connected client a `TestServer` instance.
81+
in_test: bool,
82+
8083
deferred_messages: VecDeque<Message>,
8184
}
8285

@@ -113,6 +116,7 @@ impl Session {
113116
global_options: GlobalOptions,
114117
workspace_folders: Vec<(Url, ClientOptions)>,
115118
native_system: Arc<dyn System + 'static + Send + Sync + RefUnwindSafe>,
119+
in_test: bool,
116120
) -> crate::Result<Self> {
117121
let index = Arc::new(Index::new(global_options.into_settings()));
118122

@@ -132,6 +136,7 @@ impl Session {
132136
resolved_client_capabilities: ResolvedClientCapabilities::new(client_capabilities),
133137
request_queue: RequestQueue::new(),
134138
shutdown_requested: false,
139+
in_test,
135140
})
136141
}
137142

@@ -458,6 +463,7 @@ impl Session {
458463
.collect(),
459464
index: self.index.clone().unwrap(),
460465
position_encoding: self.position_encoding,
466+
in_test: self.in_test,
461467
resolved_client_capabilities: self.resolved_client_capabilities,
462468
}
463469
}
@@ -649,6 +655,7 @@ pub(crate) struct SessionSnapshot {
649655
index: Arc<Index>,
650656
position_encoding: PositionEncoding,
651657
resolved_client_capabilities: ResolvedClientCapabilities,
658+
in_test: bool,
652659

653660
/// IMPORTANT: It's important that the databases come last, or at least,
654661
/// after any `Arc` that we try to extract or mutate in-place using `Arc::into_inner`
@@ -678,6 +685,10 @@ impl SessionSnapshot {
678685
pub(crate) fn resolved_client_capabilities(&self) -> ResolvedClientCapabilities {
679686
self.resolved_client_capabilities
680687
}
688+
689+
pub(crate) const fn in_test(&self) -> bool {
690+
self.in_test
691+
}
681692
}
682693

683694
#[derive(Debug, Default)]

crates/ty_server/src/session/capabilities.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ bitflags::bitflags! {
1818
const SIGNATURE_ACTIVE_PARAMETER_SUPPORT = 1 << 9;
1919
const HIERARCHICAL_DOCUMENT_SYMBOL_SUPPORT = 1 << 10;
2020
const WORK_DONE_PROGRESS = 1 << 11;
21-
const TEST_SERVER = 1 << 12;
21+
const DID_CHANGE_WATCHED_FILES_DYNAMIC_REGISTRATION= 1 << 12;
2222
}
2323
}
2424

@@ -83,8 +83,9 @@ impl ResolvedClientCapabilities {
8383
self.contains(Self::WORK_DONE_PROGRESS)
8484
}
8585

86-
pub(crate) const fn is_test_server(self) -> bool {
87-
self.contains(Self::TEST_SERVER)
86+
/// Returns `true` if the client supports dynamic registration for watched files changes.
87+
pub(crate) const fn supports_did_change_watched_files_dynamic_registration(self) -> bool {
88+
self.contains(Self::DID_CHANGE_WATCHED_FILES_DYNAMIC_REGISTRATION)
8889
}
8990

9091
pub(super) fn new(client_capabilities: &ClientCapabilities) -> Self {
@@ -212,12 +213,12 @@ impl ResolvedClientCapabilities {
212213
}
213214

214215
if client_capabilities
215-
.experimental
216+
.workspace
216217
.as_ref()
217-
.and_then(|experimental| experimental.get("ty_test_server"))
218-
.is_some()
218+
.and_then(|workspace| workspace.did_change_watched_files?.dynamic_registration)
219+
.unwrap_or_default()
219220
{
220-
flags |= Self::TEST_SERVER;
221+
flags |= Self::DID_CHANGE_WATCHED_FILES_DYNAMIC_REGISTRATION;
221222
}
222223

223224
flags

crates/ty_server/tests/e2e/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl TestServer {
174174
let worker_threads = NonZeroUsize::new(1).unwrap();
175175
let test_system = Arc::new(TestSystem::new(os_system));
176176

177-
match Server::new(worker_threads, server_connection, test_system, false) {
177+
match Server::new(worker_threads, server_connection, test_system, true) {
178178
Ok(server) => {
179179
if let Err(err) = server.run() {
180180
panic!("Server stopped with error: {err:?}");

0 commit comments

Comments
 (0)