Skip to content

Commit 53dbccf

Browse files
committed
refactor: Expose timeout setting to user
1 parent 11a5381 commit 53dbccf

File tree

3 files changed

+56
-28
lines changed

3 files changed

+56
-28
lines changed

crates/completest-nu/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use std::ffi::OsString;
2626
use std::path::Path;
2727
use std::path::PathBuf;
2828
use std::sync::Arc;
29+
use std::time::Duration;
2930

3031
use nu_cli::NuCompleter;
3132
use nu_command::add_shell_command_context;
@@ -106,7 +107,12 @@ impl NuRuntime {
106107
}
107108

108109
/// Get the output from typing `input` into the shell
109-
pub fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
110+
pub fn complete(
111+
&mut self,
112+
input: &str,
113+
term: &Term,
114+
timeout: Duration,
115+
) -> std::io::Result<String> {
110116
use std::fmt::Write as _;
111117

112118
let input = input.split_once('\t').unwrap_or((input, "")).0;
@@ -163,8 +169,8 @@ impl Runtime for NuRuntime {
163169
self.register(name, content)
164170
}
165171

166-
fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
167-
self.complete(input, term)
172+
fn complete(&mut self, input: &str, term: &Term, timeout: Duration) -> std::io::Result<String> {
173+
self.complete(input, term, timeout)
168174
}
169175
}
170176

crates/completest-pty/src/lib.rs

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl RuntimeBuilder for ZshRuntimeBuilder {
6363
pub struct ZshRuntime {
6464
path: OsString,
6565
home: PathBuf,
66-
timeout: Duration,
66+
_timeout: Duration,
6767
}
6868

6969
impl ZshRuntime {
@@ -93,7 +93,7 @@ PROMPT='%% '
9393
Ok(Self {
9494
path,
9595
home,
96-
timeout: Duration::from_millis(100),
96+
_timeout: Duration::from_millis(100),
9797
})
9898
}
9999

@@ -110,15 +110,20 @@ PROMPT='%% '
110110
}
111111

112112
/// Get the output from typing `input` into the shell
113-
pub fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
113+
pub fn complete(
114+
&mut self,
115+
input: &str,
116+
term: &Term,
117+
timeout: Duration,
118+
) -> std::io::Result<String> {
114119
let mut command = Command::new("zsh");
115120
command.arg("--noglobalrcs");
116121
command
117122
.env("PATH", &self.path)
118123
.env("TERM", "xterm")
119124
.env("ZDOTDIR", &self.home);
120125
let echo = false;
121-
comptest(command, echo, input, term, self.timeout)
126+
comptest(command, echo, input, term, timeout)
122127
}
123128
}
124129

@@ -131,8 +136,8 @@ impl Runtime for ZshRuntime {
131136
self.register(name, content)
132137
}
133138

134-
fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
135-
self.complete(input, term)
139+
fn complete(&mut self, input: &str, term: &Term, timeout: Duration) -> std::io::Result<String> {
140+
self.complete(input, term, timeout)
136141
}
137142
}
138143

@@ -164,7 +169,7 @@ pub struct BashRuntime {
164169
path: OsString,
165170
home: PathBuf,
166171
config: PathBuf,
167-
timeout: Duration,
172+
_timeout: Duration,
168173
}
169174

170175
impl BashRuntime {
@@ -198,7 +203,7 @@ PS1='% '
198203
path,
199204
home,
200205
config: config_path,
201-
timeout: Duration::from_millis(50),
206+
_timeout: Duration::from_millis(50),
202207
})
203208
}
204209

@@ -217,7 +222,12 @@ PS1='% '
217222
}
218223

219224
/// Get the output from typing `input` into the shell
220-
pub fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
225+
pub fn complete(
226+
&mut self,
227+
input: &str,
228+
term: &Term,
229+
timeout: Duration,
230+
) -> std::io::Result<String> {
221231
let mut command = Command::new("bash");
222232
let inputrc_path = self.home.join(".inputrc");
223233
command
@@ -226,7 +236,7 @@ PS1='% '
226236
.env("INPUTRC", &inputrc_path)
227237
.args([OsStr::new("--rcfile"), self.config.as_os_str()]);
228238
let echo = !input.contains("\t\t");
229-
comptest(command, echo, input, term, self.timeout)
239+
comptest(command, echo, input, term, timeout)
230240
}
231241
}
232242

@@ -239,8 +249,8 @@ impl Runtime for BashRuntime {
239249
self.register(name, content)
240250
}
241251

242-
fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
243-
self.complete(input, term)
252+
fn complete(&mut self, input: &str, term: &Term, timeout: Duration) -> std::io::Result<String> {
253+
self.complete(input, term, timeout)
244254
}
245255
}
246256

@@ -271,7 +281,7 @@ impl RuntimeBuilder for FishRuntimeBuilder {
271281
pub struct FishRuntime {
272282
path: OsString,
273283
home: PathBuf,
274-
timeout: Duration,
284+
_timeout: Duration,
275285
}
276286

277287
impl FishRuntime {
@@ -303,7 +313,7 @@ end;
303313
Ok(Self {
304314
path,
305315
home,
306-
timeout: Duration::from_millis(50),
316+
_timeout: Duration::from_millis(50),
307317
})
308318
}
309319

@@ -320,15 +330,20 @@ end;
320330
}
321331

322332
/// Get the output from typing `input` into the shell
323-
pub fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
333+
pub fn complete(
334+
&mut self,
335+
input: &str,
336+
term: &Term,
337+
timeout: Duration,
338+
) -> std::io::Result<String> {
324339
let mut command = Command::new("fish");
325340
command
326341
.env("PATH", &self.path)
327342
// fish requires TERM to be set.
328343
.env("TERM", "xterm")
329344
.env("XDG_CONFIG_HOME", &self.home);
330345
let echo = false;
331-
comptest(command, echo, input, term, self.timeout)
346+
comptest(command, echo, input, term, timeout)
332347
}
333348
}
334349

@@ -341,8 +356,8 @@ impl Runtime for FishRuntime {
341356
self.register(name, content)
342357
}
343358

344-
fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
345-
self.complete(input, term)
359+
fn complete(&mut self, input: &str, term: &Term, timeout: Duration) -> std::io::Result<String> {
360+
self.complete(input, term, timeout)
346361
}
347362
}
348363

@@ -374,7 +389,7 @@ pub struct ElvishRuntime {
374389
path: OsString,
375390
home: PathBuf,
376391
config: PathBuf,
377-
timeout: Duration,
392+
_timeout: Duration,
378393
}
379394

380395
impl ElvishRuntime {
@@ -403,7 +418,7 @@ set edit:prompt = (constantly \"% \")
403418
path,
404419
home,
405420
config: config_path,
406-
timeout: Duration::from_millis(50),
421+
_timeout: Duration::from_millis(50),
407422
})
408423
}
409424

@@ -422,13 +437,18 @@ set edit:prompt = (constantly \"% \")
422437
}
423438

424439
/// Get the output from typing `input` into the shell
425-
pub fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
440+
pub fn complete(
441+
&mut self,
442+
input: &str,
443+
term: &Term,
444+
timeout: Duration,
445+
) -> std::io::Result<String> {
426446
let mut command = Command::new("elvish");
427447
command
428448
.env("PATH", &self.path)
429449
.env("XDG_CONFIG_HOME", &self.home);
430450
let echo = false;
431-
comptest(command, echo, input, term, self.timeout)
451+
comptest(command, echo, input, term, timeout)
432452
}
433453
}
434454

@@ -441,8 +461,8 @@ impl Runtime for ElvishRuntime {
441461
self.register(name, content)
442462
}
443463

444-
fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
445-
self.complete(input, term)
464+
fn complete(&mut self, input: &str, term: &Term, timeout: Duration) -> std::io::Result<String> {
465+
self.complete(input, term, timeout)
446466
}
447467
}
448468

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#![warn(clippy::print_stderr)]
99
#![warn(clippy::print_stdout)]
1010

11+
use std::time::Duration;
12+
1113
/// Terminal that shell's will run completions in
1214
#[derive(Debug)]
1315
pub struct Term {
@@ -78,5 +80,5 @@ pub trait Runtime: std::fmt::Debug {
7880
fn register(&mut self, name: &str, content: &str) -> std::io::Result<()>;
7981

8082
/// Get the output from typing `input` into the shell
81-
fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String>;
83+
fn complete(&mut self, input: &str, term: &Term, timout: Duration) -> std::io::Result<String>;
8284
}

0 commit comments

Comments
 (0)