fix: missing ack method in python glue. Fixed python constructors for TextChange

and Selection. fixed code hints.
This commit is contained in:
cschen 2024-10-26 19:05:42 +02:00
parent 6a8fb38930
commit 3956d4a27d
3 changed files with 49 additions and 58 deletions

View file

@ -95,6 +95,8 @@ class TextChange:
end: int end: int
content: str content: str
def __new__(cls, *, start: int, end: int, content: str, **kwargs): ...
def is_delete(self) -> bool: ... def is_delete(self) -> bool: ...
def is_insert(self) -> bool: ... def is_insert(self) -> bool: ...
def is_empty(self) -> bool: ... def is_empty(self) -> bool: ...
@ -118,8 +120,8 @@ class BufferController:
def content(self) -> Promise[str]: ... def content(self) -> Promise[str]: ...
def ack(self, v: list[int]) -> None: ... def ack(self, v: list[int]) -> None: ...
def send(self, op: TextChange) -> None: ... def send(self, op: TextChange) -> None: ...
def try_recv(self) -> Promise[Optional[TextChange]]: ... def try_recv(self) -> Promise[Optional[BufferUpdate]]: ...
def recv(self) -> Promise[TextChange]: ... def recv(self) -> Promise[BufferUpdate]: ...
def poll(self) -> Promise[None]: ... def poll(self) -> Promise[None]: ...
def callback(self, def callback(self,
cb: Callable[[BufferController], None]) -> None: ... cb: Callable[[BufferController], None]) -> None: ...
@ -131,10 +133,19 @@ class Selection:
""" """
An Editor agnostic cursor position representation An Editor agnostic cursor position representation
""" """
start: Tuple[int, int] start_row: int
end: Tuple[int, int] start_col: int
end_row: int
end_col: int
buffer: str buffer: str
def __new__(cls, *
start_row: int,
start_col: int,
end_row: int,
end_col: int,
buffer: str, **kwargs): ...
class Cursor: class Cursor:
""" """
A remote cursor event A remote cursor event

View file

@ -71,6 +71,12 @@ impl BufferController {
a_sync_allow_threads!(py, this.content().await) a_sync_allow_threads!(py, this.content().await)
} }
#[pyo3(name = "ack")]
fn pyack(&self, py: Python, v: Vec<u64>) -> PyResult<()> {
let this = self.clone();
a_sync_allow_threads!(py, this.ack(v))
}
#[pyo3(name = "send")] #[pyo3(name = "send")]
fn pysend(&self, _py: Python, op: TextChange) -> PyResult<()> { fn pysend(&self, _py: Python, op: TextChange) -> PyResult<()> {
let this = self.clone(); let this = self.clone();

View file

@ -227,39 +227,16 @@ impl Cursor {
#[pymethods] #[pymethods]
impl Selection { impl Selection {
#[new] #[new]
#[pyo3(signature = (**kwds))] #[pyo3(signature = (*, start_row, start_col, end_row, end_col, buffer, **kwds))]
pub fn py_new(kwds: Option<&Bound<'_, PyDict>>) -> PyResult<Self> { pub fn py_new(
start_row: i32,
start_col: i32,
end_row: i32,
end_col: i32,
buffer: String,
kwds: Option<&Bound<'_, PyDict>>,
) -> PyResult<Self> {
if let Some(kwds) = kwds { if let Some(kwds) = kwds {
let start_row = if let Some(e) = kwds.get_item("start_row")? {
e.extract()?
} else {
0
};
let start_col = if let Some(e) = kwds.get_item("start_col")? {
e.extract()?
} else {
0
};
let end_row = if let Some(e) = kwds.get_item("end_row")? {
e.extract()?
} else {
0
};
let end_col = if let Some(e) = kwds.get_item("end_col")? {
e.extract()?
} else {
0
};
let buffer = if let Some(e) = kwds.get_item("buffer")? {
e.extract()?
} else {
String::default()
};
Ok(Self { Ok(Self {
start_row, start_row,
start_col, start_col,
@ -268,7 +245,13 @@ impl Selection {
buffer, buffer,
}) })
} else { } else {
Ok(Self::default()) Ok(Self {
start_row,
start_col,
end_row,
end_col,
buffer,
})
} }
} }
@ -287,34 +270,25 @@ impl BufferUpdate {
#[pymethods] #[pymethods]
impl TextChange { impl TextChange {
#[new] #[new]
#[pyo3(signature = (**kwds))] #[pyo3(signature = (*, start, end, content, **kwds))]
pub fn py_new(kwds: Option<&Bound<'_, PyDict>>) -> PyResult<Self> { pub fn py_new(
start: u32,
end: u32,
content: String,
kwds: Option<&Bound<'_, PyDict>>,
) -> PyResult<Self> {
if let Some(kwds) = kwds { if let Some(kwds) = kwds {
let start_idx = if let Some(e) = kwds.get_item("start")? {
e.extract()?
} else {
0
};
let end_idx = if let Some(e) = kwds.get_item("end")? {
e.extract()?
} else {
0
};
let content = if let Some(e) = kwds.get_item("content")? {
e.extract()?
} else {
String::default()
};
Ok(Self { Ok(Self {
start_idx, start_idx,
end_idx, end_idx,
content, content,
}) })
} else { } else {
Ok(Self::default()) Ok(Self {
start_idx,
end_idx,
content,
})
} }
} }