mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 15:24:48 +01:00
fix(python): fixed the type hints, adapted glue to latest workspace, uniformed names in the glue
chore: forgot a file
This commit is contained in:
parent
53cd0068b5
commit
264dd319d3
4 changed files with 53 additions and 49 deletions
53
dist/py/codemp.pyi
vendored
53
dist/py/codemp.pyi
vendored
|
@ -1,65 +1,66 @@
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
def init_logger(debug: bool | None) -> PyLogger: ...
|
|
||||||
|
|
||||||
def codemp_init() -> Client: ...
|
|
||||||
|
|
||||||
class PyLogger:
|
class PyLogger:
|
||||||
async def message(self) -> str | None: ...
|
def __init__(self, debug) -> None: ...
|
||||||
|
async def listen(self) -> str | None: ...
|
||||||
|
|
||||||
|
|
||||||
class CodempTextChange:
|
class TextChange:
|
||||||
start_incl: int
|
start: int
|
||||||
end_excl: int
|
end: int
|
||||||
content: str
|
content: str
|
||||||
|
|
||||||
def is_deletion(self) -> bool: ...
|
def is_deletion(self) -> bool: ...
|
||||||
def is_addition(self) -> bool: ...
|
def is_addition(self) -> bool: ...
|
||||||
def is_empty(self) -> bool: ...
|
def is_empty(self) -> bool: ...
|
||||||
def apply(self, txt: str) -> str: ...
|
def apply(self, txt: str) -> str: ...
|
||||||
def from_diff(self, before: str, after: str) -> CodempTextChange: ...
|
def from_diff(self, before: str, after: str) -> TextChange: ...
|
||||||
def index_to_rowcol(self, txt: str, index: int) -> Tuple[int, int]: ...
|
def index_to_rowcol(self, txt: str, index: int) -> Tuple[int, int]: ...
|
||||||
|
|
||||||
|
|
||||||
class CodempBufferController:
|
class BufferController:
|
||||||
def content(self) -> str: ...
|
def content(self) -> str: ...
|
||||||
def send(self, start: int, end: int, txt: str) -> None: ...
|
def send(self, start: int, end: int, txt: str) -> None: ...
|
||||||
async def try_recv(self) -> CodempTextChange | None: ...
|
async def try_recv(self) -> TextChange | None: ...
|
||||||
async def recv(self) -> CodempTextChange: ...
|
async def recv(self) -> TextChange: ...
|
||||||
async def poll(self) -> None: ...
|
async def poll(self) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
class CodempCursor:
|
|
||||||
|
class Cursor:
|
||||||
start: Tuple[int, int]
|
start: Tuple[int, int]
|
||||||
end: Tuple[int, int]
|
end: Tuple[int, int]
|
||||||
buffer: str
|
buffer: str
|
||||||
user: str # can be an empty string
|
user: str # can be an empty string
|
||||||
|
|
||||||
|
|
||||||
class CodempCursorController:
|
class CursorController:
|
||||||
def send(self, path: str, start: Tuple[int, int], end: Tuple[int, int]) -> None: ...
|
def send(self, path: str, start: Tuple[int, int], end: Tuple[int, int]) -> None: ...
|
||||||
def try_recv(self) -> CodempCursor | None: ...
|
def try_recv(self) -> Cursor | None: ...
|
||||||
async def recv(self) -> CodempCursor: ...
|
async def recv(self) -> Cursor: ...
|
||||||
async def poll(self) -> None: ...
|
async def poll(self) -> None: ...
|
||||||
|
def stop(self) -> bool: ...
|
||||||
|
|
||||||
|
|
||||||
class CodempWorkspace:
|
class Workspace:
|
||||||
async def create(self, path: str) -> None: ...
|
async def create(self, path: str) -> None: ...
|
||||||
async def attach(self, path: str) -> CodempBufferController: ...
|
async def attach(self, path: str) -> BufferController: ...
|
||||||
|
def detach(self, path: str) -> bool: ...
|
||||||
async def fetch_buffers(self) -> None: ...
|
async def fetch_buffers(self) -> None: ...
|
||||||
async def fetch_users(self) -> None: ...
|
async def fetch_users(self) -> None: ...
|
||||||
async def list_buffer_users(self, path: str) -> list[str]: ...
|
async def list_buffer_users(self, path: str) -> list[str]: ...
|
||||||
async def delete(self, path: str) -> None: ...
|
async def delete(self, path: str) -> None: ...
|
||||||
def id(self) -> str: ...
|
def id(self) -> str: ...
|
||||||
def cursor(self) -> CodempCursorController: ...
|
def cursor(self) -> CursorController: ...
|
||||||
def buffer_by_name(self, path: str) -> CodempBufferController: ...
|
def buffer_by_name(self, path: str) -> BufferController | None: ...
|
||||||
|
def buffer_list(self) -> list[str]: ...
|
||||||
def filetree(self) -> list[str]: ...
|
def filetree(self) -> list[str]: ...
|
||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
def __init__(self) -> None: ...
|
def __init__(self, host: str, username: str, password: str) -> None: ...
|
||||||
async def connect(self, host: str) -> None: ...
|
async def join_workspace(self, workspace: str) -> Workspace: ...
|
||||||
async def login(self, user: str, password: str, workspace: str | None) -> None: ...
|
def leave_workspace(self, workspace: str) -> bool: ...
|
||||||
async def join_workspace(self, workspace: str) -> CodempWorkspace: ...
|
def get_workspace(self, id: str) -> Workspace: ...
|
||||||
async def get_workspace(self, id: str) -> CodempWorkspace: ...
|
def active_workspaces(self) -> list[str]: ...
|
||||||
async def user_id(self) -> str: ...
|
def user_id(self) -> str: ...
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::workspace::Workspace;
|
use crate::workspace::Workspace;
|
||||||
use crate::Client;
|
use crate::Client;
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::types::{PyBool, PyList, PyString};
|
|
||||||
|
|
||||||
// #[pyfunction]
|
// #[pyfunction]
|
||||||
// pub fn codemp_init<'a>(py: Python<'a>) -> PyResult<Py<Client>> {
|
// pub fn codemp_init<'a>(py: Python<'a>) -> PyResult<Py<Client>> {
|
||||||
|
@ -28,8 +27,8 @@ impl Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pyo3(name = "leave_workspace")]
|
#[pyo3(name = "leave_workspace")]
|
||||||
fn pyleave_workspace<'p>(&'p self, py: Python<'p>, id: String) -> &PyBool {
|
fn pyleave_workspace(&self, id: String) -> bool {
|
||||||
PyBool::new(py, self.leave_workspace(id.as_str()))
|
self.leave_workspace(id.as_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
// join a workspace
|
// join a workspace
|
||||||
|
@ -42,12 +41,12 @@ impl Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pyo3(name = "active_workspaces")]
|
#[pyo3(name = "active_workspaces")]
|
||||||
fn pyactive_workspaces<'p>(&'p self, py: Python<'p>) -> &PyList {
|
fn pyactive_workspaces(&self) -> Vec<String> {
|
||||||
PyList::new(py, self.active_workspaces())
|
self.active_workspaces()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pyo3(name = "user_id")]
|
#[pyo3(name = "user_id")]
|
||||||
fn pyuser_id<'p>(&'p self, py: Python<'p>) -> &PyString {
|
fn pyuser_id(&self) -> String {
|
||||||
PyString::new(py, self.user_id().to_string().as_str())
|
self.user_id().to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,10 @@ pub mod workspace;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::Cursor, api::TextChange, buffer::Controller as BufferController,
|
api::{Cursor, TextChange},
|
||||||
cursor::Controller as CursorController, Client, Workspace,
|
buffer::Controller as BufferController,
|
||||||
|
cursor::Controller as CursorController,
|
||||||
|
Client, Workspace,
|
||||||
};
|
};
|
||||||
use pyo3::exceptions::{PyConnectionError, PyRuntimeError, PySystemError};
|
use pyo3::exceptions::{PyConnectionError, PyRuntimeError, PySystemError};
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
|
@ -88,14 +90,16 @@ impl PyLogger {
|
||||||
|
|
||||||
#[pymodule]
|
#[pymodule]
|
||||||
fn codemp(_py: Python, m: &PyModule) -> PyResult<()> {
|
fn codemp(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||||
m.add_class::<Client>()?;
|
|
||||||
m.add_class::<PyLogger>()?;
|
m.add_class::<PyLogger>()?;
|
||||||
m.add_class::<Workspace>()?;
|
|
||||||
m.add_class::<CursorController>()?;
|
m.add_class::<TextChange>()?;
|
||||||
m.add_class::<BufferController>()?;
|
m.add_class::<BufferController>()?;
|
||||||
|
|
||||||
m.add_class::<Cursor>()?;
|
m.add_class::<Cursor>()?;
|
||||||
m.add_class::<TextChange>()?;
|
m.add_class::<CursorController>()?;
|
||||||
|
|
||||||
|
m.add_class::<Workspace>()?;
|
||||||
|
m.add_class::<Client>()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use crate::buffer::Controller as CodempBufferController;
|
use crate::buffer::Controller as BufferController;
|
||||||
use crate::cursor::Controller as CodempCursorController;
|
use crate::cursor::Controller as CursorController;
|
||||||
use crate::workspace::Workspace as CodempWorkspace;
|
use crate::workspace::Workspace;
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::types::PyString;
|
use pyo3::types::PyString;
|
||||||
|
|
||||||
#[pymethods]
|
#[pymethods]
|
||||||
impl CodempWorkspace {
|
impl Workspace {
|
||||||
// join a workspace
|
// join a workspace
|
||||||
#[pyo3(name = "create")]
|
#[pyo3(name = "create")]
|
||||||
fn pycreate<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<&'p PyAny> {
|
fn pycreate<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<&'p PyAny> {
|
||||||
|
@ -21,7 +21,7 @@ impl CodempWorkspace {
|
||||||
let ws = self.clone();
|
let ws = self.clone();
|
||||||
|
|
||||||
pyo3_asyncio::tokio::future_into_py(py, async move {
|
pyo3_asyncio::tokio::future_into_py(py, async move {
|
||||||
let buffctl: CodempBufferController = ws.attach(path.as_str()).await?;
|
let buffctl: BufferController = ws.attach(path.as_str()).await?;
|
||||||
Python::with_gil(|py| Py::new(py, buffctl))
|
Python::with_gil(|py| Py::new(py, buffctl))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,9 @@ impl CodempWorkspace {
|
||||||
#[pyo3(name = "detach")]
|
#[pyo3(name = "detach")]
|
||||||
fn pydetach(&self, path: String) -> bool {
|
fn pydetach(&self, path: String) -> bool {
|
||||||
match self.detach(path.as_str()) {
|
match self.detach(path.as_str()) {
|
||||||
crate::workspace::DetachResult::NotAttached => false,
|
crate::workspace::worker::DetachResult::NotAttached => false,
|
||||||
crate::workspace::DetachResult::Detaching => true,
|
crate::workspace::worker::DetachResult::Detaching => true,
|
||||||
crate::workspace::DetachResult::AlreadyDetached => true,
|
crate::workspace::worker::DetachResult::AlreadyDetached => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ impl CodempWorkspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pyo3(name = "cursor")]
|
#[pyo3(name = "cursor")]
|
||||||
fn pycursor(&self, py: Python<'_>) -> PyResult<Py<CodempCursorController>> {
|
fn pycursor(&self, py: Python<'_>) -> PyResult<Py<CursorController>> {
|
||||||
Py::new(py, self.cursor())
|
Py::new(py, self.cursor())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ impl CodempWorkspace {
|
||||||
&self,
|
&self,
|
||||||
py: Python<'_>,
|
py: Python<'_>,
|
||||||
path: String,
|
path: String,
|
||||||
) -> PyResult<Option<Py<CodempBufferController>>> {
|
) -> PyResult<Option<Py<BufferController>>> {
|
||||||
let Some(bufctl) = self.buffer_by_name(path.as_str()) else {
|
let Some(bufctl) = self.buffer_by_name(path.as_str()) else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue