-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrollers.rs
More file actions
158 lines (137 loc) · 3.61 KB
/
Copy pathcontrollers.rs
File metadata and controls
158 lines (137 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
use crate::prelude::*;
use pyo3::prelude::*;
use pyo3::exceptions::PyValueError;
use super::Promise;
use super::a_sync_detach;
// need to do manually since Controller is a trait implementation
#[pymethods]
impl CodempCursorController {
#[pyo3(name = "workspace_id")]
fn pyworkspace_id(&self) -> CodempWorkspaceIdentifier {
self.workspace_id().clone()
}
#[pyo3(name = "send")]
fn pysend(&self, _py: Python, pos: CodempCursorUpdate) -> PyResult<()> {
self.send(pos)?;
Ok(())
}
#[pyo3(name = "try_recv")]
fn pytry_recv(&self, py: Python) -> PyResult<Promise> {
let this = self.clone();
a_sync_detach!(py, this.try_recv().await)
}
#[pyo3(name = "recv")]
fn pyrecv(&self, py: Python) -> PyResult<Promise> {
let this = self.clone();
a_sync_detach!(py, this.recv().await)
}
#[pyo3(name = "poll")]
fn pypoll(&self, py: Python) -> PyResult<Promise> {
let this = self.clone();
a_sync_detach!(py, this.poll().await)
}
#[pyo3(name = "callback")]
fn pycallback(&self, py: Python, cb: Py<PyAny>) -> PyResult<()> {
if !cb.bind_borrowed(py).is_callable() {
return Err(PyValueError::new_err("The object passed must be callable."));
}
self.callback(move |ctl| {
Python::attach(|py| {
// TODO what to do with this error?
let _ = cb.call1(py, (ctl,));
})
});
Ok(())
}
#[pyo3(name = "clear_callback")]
fn pyclear_callback(&self) {
self.clear_callback();
}
}
// need to do manually since Controller is a trait implementation
#[pymethods]
impl CodempBufferController {
#[pyo3(name = "path")]
fn pypath(&self) -> String {
self.path().to_string()
}
#[pyo3(name = "workspace_id")]
fn pyworkspace_id(&self) -> CodempWorkspaceIdentifier {
self.workspace_id().clone()
}
#[pyo3(name = "content")]
fn pycontent(&self, py: Python) -> PyResult<Promise> {
let this = self.clone();
a_sync_detach!(py, this.content().await)
}
#[pyo3(name = "ack")]
fn pyack(&self, v: Vec<i64>) {
self.ack(v)
}
#[pyo3(name = "send")]
fn pysend(&self, op: CodempTextChange) -> PyResult<()> {
let this = self.clone();
this.send(op)?;
Ok(())
}
#[pyo3(name = "try_recv")]
fn pytry_recv(&self, py: Python) -> PyResult<Promise> {
let this = self.clone();
a_sync_detach!(py, this.try_recv().await)
}
#[pyo3(name = "recv")]
fn pyrecv(&self, py: Python) -> PyResult<Promise> {
let this = self.clone();
a_sync_detach!(py, this.recv().await)
}
#[pyo3(name = "poll")]
fn pypoll(&self, py: Python) -> PyResult<Promise> {
let this = self.clone();
a_sync_detach!(py, this.poll().await)
}
#[pyo3(name = "callback")]
fn pycallback(&self, py: Python, cb: Py<PyAny>) -> PyResult<()> {
if !cb.bind_borrowed(py).is_callable() {
return Err(PyValueError::new_err("The object passed must be callable."));
}
self.callback(move |ctl| {
Python::attach(|py| {
// TODO what to do with this error?
let _ = cb.call1(py, (ctl,));
})
});
Ok(())
}
#[pyo3(name = "clear_callback")]
fn pyclear_callback(&self) {
self.clear_callback();
}
}
// // We have to write this manually since
// // cursor.user has type Option which cannot be translated
// // automatically
// #[pymethods]
// impl CodempCursorUpdate {
// #[getter(start)]
// fn pystart(&self) -> Vec<(i32, i32)> {
// self.cursor
// .iter()
// .map(|s| (s.start_row, s.start_col))
// .collect()
// }
//
// #[getter(end)]
// fn pyend(&self) -> Vec<(i32, i32)> {
// self.sel.iter().map(|s| (s.end_row, s.end_col)).collect()
// }
//
// #[getter(buffer)]
// fn pybuffer(&self) -> String {
// self.buffer.clone()
// }
//
// // #[getter(user)]
// // fn pyuser(&self) -> Option<String> {
// // Some(self.user.clone())
// // }
// }