mirror of
https://github.com/hexedtech/codemp.git
synced 2024-12-22 21:04:53 +01:00
Merge pull request #58 from hexedtech/py-ack-type-hints
Fix python glue: missing akc method, better constructors and type hints reflect the code better.
This commit is contained in:
commit
b398c01137
3 changed files with 50 additions and 60 deletions
19
dist/py/src/codemp/codemp.pyi
vendored
19
dist/py/src/codemp/codemp.pyi
vendored
|
@ -95,6 +95,8 @@ class TextChange:
|
|||
end: int
|
||||
content: str
|
||||
|
||||
def __new__(cls, *, start: int, end: int, content: str, **kwargs): ...
|
||||
|
||||
def is_delete(self) -> bool: ...
|
||||
def is_insert(self) -> bool: ...
|
||||
def is_empty(self) -> bool: ...
|
||||
|
@ -118,8 +120,8 @@ class BufferController:
|
|||
def content(self) -> Promise[str]: ...
|
||||
def ack(self, v: list[int]) -> None: ...
|
||||
def send(self, op: TextChange) -> None: ...
|
||||
def try_recv(self) -> Promise[Optional[TextChange]]: ...
|
||||
def recv(self) -> Promise[TextChange]: ...
|
||||
def try_recv(self) -> Promise[Optional[BufferUpdate]]: ...
|
||||
def recv(self) -> Promise[BufferUpdate]: ...
|
||||
def poll(self) -> Promise[None]: ...
|
||||
def callback(self,
|
||||
cb: Callable[[BufferController], None]) -> None: ...
|
||||
|
@ -131,10 +133,19 @@ class Selection:
|
|||
"""
|
||||
An Editor agnostic cursor position representation
|
||||
"""
|
||||
start: Tuple[int, int]
|
||||
end: Tuple[int, int]
|
||||
start_row: int
|
||||
start_col: int
|
||||
end_row: int
|
||||
end_col: int
|
||||
buffer: str
|
||||
|
||||
def __new__(cls, *
|
||||
start_row: int,
|
||||
start_col: int,
|
||||
end_row: int,
|
||||
end_col: int,
|
||||
buffer: str, **kwargs): ...
|
||||
|
||||
class Cursor:
|
||||
"""
|
||||
A remote cursor event
|
||||
|
|
|
@ -71,6 +71,11 @@ impl BufferController {
|
|||
a_sync_allow_threads!(py, this.content().await)
|
||||
}
|
||||
|
||||
#[pyo3(name = "ack")]
|
||||
fn pyack(&self, py: Python, v: Vec<i64>) -> () {
|
||||
self.ack(v)
|
||||
}
|
||||
|
||||
#[pyo3(name = "send")]
|
||||
fn pysend(&self, _py: Python, op: TextChange) -> PyResult<()> {
|
||||
let this = self.clone();
|
||||
|
|
|
@ -227,39 +227,16 @@ impl Cursor {
|
|||
#[pymethods]
|
||||
impl Selection {
|
||||
#[new]
|
||||
#[pyo3(signature = (**kwds))]
|
||||
pub fn py_new(kwds: Option<&Bound<'_, PyDict>>) -> PyResult<Self> {
|
||||
#[pyo3(signature = (*, start_row, start_col, end_row, end_col, buffer, **kwds))]
|
||||
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 {
|
||||
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 {
|
||||
start_row,
|
||||
start_col,
|
||||
|
@ -268,7 +245,13 @@ impl Selection {
|
|||
buffer,
|
||||
})
|
||||
} else {
|
||||
Ok(Self::default())
|
||||
Ok(Self {
|
||||
start_row,
|
||||
start_col,
|
||||
end_row,
|
||||
end_col,
|
||||
buffer,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,34 +270,25 @@ impl BufferUpdate {
|
|||
#[pymethods]
|
||||
impl TextChange {
|
||||
#[new]
|
||||
#[pyo3(signature = (**kwds))]
|
||||
pub fn py_new(kwds: Option<&Bound<'_, PyDict>>) -> PyResult<Self> {
|
||||
#[pyo3(signature = (*, start, end, content, **kwds))]
|
||||
pub fn py_new(
|
||||
start: u32,
|
||||
end: u32,
|
||||
content: String,
|
||||
kwds: Option<&Bound<'_, PyDict>>,
|
||||
) -> PyResult<Self> {
|
||||
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 {
|
||||
start_idx,
|
||||
end_idx,
|
||||
start_idx: start,
|
||||
end_idx: end,
|
||||
content,
|
||||
})
|
||||
} else {
|
||||
Ok(Self::default())
|
||||
Ok(Self {
|
||||
start_idx: start,
|
||||
end_idx: end,
|
||||
content,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue