Skip to repository content325 lines · 7.9 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T02:55:25.559Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
blocking_io_on_foreground.rs
1// Tests for the `blocking_io_on_foreground` lint.
2
3#![allow(unused, let_underscore_lock)]
4
5extern crate gpui;
6
7use gpui::*;
8
9struct Editor;
10
11// ============================================================
12// SHOULD WARN — blocking IO in functions with GPUI context params
13// ============================================================
14
15// --- std::fs free functions ---
16
17fn read_config_with_app(cx: &mut App) {
18 let _ = std::fs::read_to_string("config.toml");
19}
20
21fn write_file_with_app(cx: &App) {
22 let _ = std::fs::write("out.txt", b"data");
23}
24
25fn read_with_window(window: &mut Window, cx: &mut App) {
26 let _ = std::fs::read("data.bin");
27}
28
29fn metadata_with_app(cx: &mut App) {
30 let _ = std::fs::metadata("file.txt");
31}
32
33fn create_dir_with_app(cx: &mut App) {
34 let _ = std::fs::create_dir_all("some/path");
35}
36
37fn remove_file_with_app(cx: &mut App) {
38 let _ = std::fs::remove_file("old.txt");
39}
40
41fn canonicalize_with_app(cx: &mut App) {
42 let _ = std::fs::canonicalize("./relative");
43}
44
45fn read_dir_with_app(cx: &mut App) {
46 let _ = std::fs::read_dir("some/dir");
47}
48
49fn read_link_with_app(cx: &mut App) {
50 let _ = std::fs::read_link("some/link");
51}
52
53fn symlink_metadata_with_app(cx: &mut App) {
54 let _ = std::fs::symlink_metadata("file.txt");
55}
56
57fn set_permissions_with_app(cx: &mut App) {
58 if let Ok(meta) = std::fs::metadata("file.txt") {
59 let _ = std::fs::set_permissions("file.txt", meta.permissions());
60 }
61}
62
63fn copy_with_app(cx: &mut App) {
64 let _ = std::fs::copy("a.txt", "b.txt");
65}
66
67fn rename_with_app(cx: &mut App) {
68 let _ = std::fs::rename("old.txt", "new.txt");
69}
70
71fn hard_link_with_app(cx: &mut App) {
72 let _ = std::fs::hard_link("original", "link");
73}
74
75fn create_dir_with_app_single(cx: &mut App) {
76 let _ = std::fs::create_dir("one_dir");
77}
78
79fn remove_dir_with_app(cx: &mut App) {
80 let _ = std::fs::remove_dir("empty_dir");
81}
82
83fn remove_dir_all_with_app(cx: &mut App) {
84 let _ = std::fs::remove_dir_all("dir_tree");
85}
86
87// --- std::fs::File associated functions ---
88
89fn file_open_with_app(cx: &mut App) {
90 let _ = std::fs::File::open("data.bin");
91}
92
93fn file_create_with_app(cx: &mut App) {
94 let _ = std::fs::File::create("out.bin");
95}
96
97fn file_create_new_with_app(cx: &mut App) {
98 let _ = std::fs::File::create_new("new.bin");
99}
100
101// --- std::fs::File instance methods ---
102
103fn file_sync_all_with_app(cx: &mut App) {
104 if let Ok(f) = std::fs::File::open("x") {
105 let _ = f.sync_all();
106 }
107}
108
109fn file_sync_data_with_app(cx: &mut App) {
110 if let Ok(f) = std::fs::File::open("x") {
111 let _ = f.sync_data();
112 }
113}
114
115fn file_set_len_with_app(cx: &mut App) {
116 if let Ok(f) = std::fs::File::open("x") {
117 let _ = f.set_len(0);
118 }
119}
120
121fn file_metadata_with_app(cx: &mut App) {
122 if let Ok(f) = std::fs::File::open("x") {
123 let _ = f.metadata();
124 }
125}
126
127fn file_try_clone_with_app(cx: &mut App) {
128 if let Ok(f) = std::fs::File::open("x") {
129 let _ = f.try_clone();
130 }
131}
132
133// --- std::thread ---
134
135fn sleep_with_context(cx: &mut Context<'_, Editor>) {
136 std::thread::sleep(std::time::Duration::from_millis(100));
137}
138
139// --- std::path::Path methods ---
140
141fn path_metadata_with_app(cx: &mut App) {
142 let _ = std::path::Path::new("file.txt").metadata();
143}
144
145fn path_symlink_metadata_with_app(cx: &mut App) {
146 let _ = std::path::Path::new("link").symlink_metadata();
147}
148
149fn path_read_link_with_app(cx: &mut App) {
150 let _ = std::path::Path::new("link").read_link();
151}
152
153fn path_read_dir_with_app(cx: &mut App) {
154 let _ = std::path::Path::new("dir").read_dir();
155}
156
157fn path_exists_with_app(cx: &mut App) {
158 let _ = std::path::Path::new("file.txt").exists();
159}
160
161fn path_try_exists_with_app(cx: &mut App) {
162 let _ = std::path::Path::new("file.txt").try_exists();
163}
164
165fn path_is_file_with_app(cx: &mut App) {
166 let _ = std::path::Path::new("file.txt").is_file();
167}
168
169fn path_is_dir_with_app(cx: &mut App) {
170 let _ = std::path::Path::new("dir").is_dir();
171}
172
173fn path_is_symlink_with_app(cx: &mut App) {
174 let _ = std::path::Path::new("link").is_symlink();
175}
176
177fn path_canonicalize_with_app(cx: &mut App) {
178 let _ = std::path::Path::new("./relative").canonicalize();
179}
180
181// PathBuf derefs to Path, so the same methods fire.
182fn pathbuf_exists_with_app(cx: &mut App) {
183 let _ = std::path::PathBuf::from("file.txt").exists();
184}
185
186// --- std::net ---
187
188fn tcp_listener_bind_with_app(cx: &mut App) {
189 let _ = std::net::TcpListener::bind("127.0.0.1:0");
190}
191
192fn tcp_stream_connect_with_app(cx: &mut App) {
193 let _ = std::net::TcpStream::connect("127.0.0.1:80");
194}
195
196fn tcp_stream_connect_timeout_with_app(cx: &mut App) {
197 let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 80));
198 let _ = std::net::TcpStream::connect_timeout(&addr, std::time::Duration::from_secs(1));
199}
200
201fn tcp_listener_accept_with_app(cx: &mut App) {
202 if let Ok(listener) = std::net::TcpListener::bind("127.0.0.1:0") {
203 let _ = listener.accept();
204 }
205}
206
207fn udp_socket_bind_with_app(cx: &mut App) {
208 let _ = std::net::UdpSocket::bind("127.0.0.1:0");
209}
210
211fn udp_socket_send_recv_with_app(cx: &mut App) {
212 if let Ok(socket) = std::net::UdpSocket::bind("127.0.0.1:0") {
213 let mut buf = [0u8; 64];
214 let _ = socket.recv_from(&mut buf);
215 }
216}
217
218// --- std::process ---
219
220fn command_output_with_app(cx: &mut App) {
221 let _ = std::process::Command::new("echo").output();
222}
223
224fn command_status_with_app(cx: &mut App) {
225 let _ = std::process::Command::new("echo").status();
226}
227
228fn command_spawn_with_app(cx: &mut App) {
229 let _ = std::process::Command::new("echo").spawn();
230}
231
232fn child_wait_with_app(cx: &mut App) {
233 if let Ok(mut child) = std::process::Command::new("echo").spawn() {
234 let _ = child.wait();
235 }
236}
237
238fn child_wait_with_output_with_app(cx: &mut App) {
239 if let Ok(child) = std::process::Command::new("echo").spawn() {
240 let _ = child.wait_with_output();
241 }
242}
243
244// --- std::sync ---
245
246fn mutex_lock_with_app(cx: &mut App) {
247 let m = std::sync::Mutex::new(42);
248 let _ = m.lock();
249}
250
251fn rwlock_read_with_app(cx: &mut App) {
252 let rw = std::sync::RwLock::new(42);
253 let _ = rw.read();
254}
255
256fn rwlock_write_with_app(cx: &mut App) {
257 let rw = std::sync::RwLock::new(42);
258 let _ = rw.write();
259}
260
261fn barrier_wait_with_app(cx: &mut App) {
262 let b = std::sync::Barrier::new(1);
263 b.wait();
264}
265
266fn receiver_recv_with_app(cx: &mut App) {
267 let (_tx, rx) = std::sync::mpsc::channel::<i32>();
268 let _ = rx.recv();
269}
270
271fn sync_sender_send_with_app(cx: &mut App) {
272 let (tx, _rx) = std::sync::mpsc::sync_channel::<i32>(1);
273 let _ = tx.send(42);
274}
275
276// --- Render impl ---
277
278struct BlockingRenderView;
279
280impl Render for BlockingRenderView {
281 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
282 let _ = std::fs::read_to_string("layout.toml");
283 ()
284 }
285}
286
287// ============================================================
288// SHOULD NOT WARN — no GPUI context, or inside closure
289// ============================================================
290
291// Plain function with no GPUI parameter.
292fn load_config_plain() -> String {
293 std::fs::read_to_string("config.toml").unwrap_or_default()
294}
295
296// Blocking IO inside a closure (could be passed to background_spawn).
297fn setup_with_closure(cx: &mut App) {
298 let _handler = || {
299 let _ = std::fs::read_to_string("config.toml");
300 };
301}
302
303// Blocking IO in a function with no GPUI types at all.
304fn standalone_sleep() {
305 std::thread::sleep(std::time::Duration::from_millis(10));
306}
307
308// Path methods with no GPUI parameter.
309fn path_exists_plain() -> bool {
310 std::path::Path::new("file.txt").exists()
311}
312
313// Net calls with no GPUI parameter.
314fn tcp_bind_plain() {
315 let _ = std::net::TcpListener::bind("127.0.0.1:0");
316}
317
318// Mutex lock with no GPUI parameter.
319fn mutex_lock_plain() {
320 let m = std::sync::Mutex::new(0);
321 let _ = m.lock();
322}
323
324fn main() {}
325