mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-21 23:04:49 +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
|
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
|
||||||
|
|
|
@ -71,6 +71,11 @@ 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<i64>) -> () {
|
||||||
|
self.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();
|
||||||
|
|
|
@ -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: start,
|
||||||
end_idx,
|
end_idx: end,
|
||||||
content,
|
content,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Ok(Self::default())
|
Ok(Self {
|
||||||
|
start_idx: start,
|
||||||
|
end_idx: end,
|
||||||
|
content,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue