mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 07:14:50 +01:00
chore: removed prelude imports and fixed glue exports
This commit is contained in:
parent
b46914528a
commit
2d20887509
5 changed files with 27 additions and 22 deletions
3
dist/js/package.json
vendored
3
dist/js/package.json
vendored
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"name": "@codemp/codemp",
|
||||
"version": "0.0.1",
|
||||
|
||||
"dependencies": {
|
||||
"@napi-rs/cli": "^2.18.0",
|
||||
"npx": "^10.2.2"
|
||||
|
|
|
@ -2,11 +2,12 @@ use napi::threadsafe_function::{ErrorStrategy::Fatal, ThreadSafeCallContext, Thr
|
|||
use napi_derive::napi;
|
||||
use crate::api::TextChange;
|
||||
use crate::api::Controller;
|
||||
use crate::prelude::*;
|
||||
use crate::buffer::controller::BufferController;
|
||||
|
||||
|
||||
#[napi]
|
||||
impl CodempBufferController {
|
||||
#[napi(ts_args_type = "fun: (event: JsTextChange) => void")]
|
||||
impl BufferController {
|
||||
#[napi(ts_args_type = "fun: (event: TextChange) => void")]
|
||||
pub fn callback(&self, fun: napi::JsFunction) -> napi::Result<()>{
|
||||
let tsfn : ThreadsafeFunction<crate::api::TextChange, Fatal> =
|
||||
fun.create_threadsafe_function(0,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use napi_derive::napi;
|
||||
use crate::prelude::*;
|
||||
use crate::{Client, Workspace};
|
||||
|
||||
#[napi]
|
||||
/// connect to codemp servers and return a client session
|
||||
pub async fn connect(addr: Option<String>, username: String, password: String) -> napi::Result<CodempClient>{
|
||||
pub async fn connect(addr: Option<String>, username: String, password: String) -> napi::Result<crate::Client>{
|
||||
let client = crate::Client::new(addr.as_deref().unwrap_or("http://codemp.alemi.dev:50053"), username, password)
|
||||
.await?;
|
||||
|
||||
|
@ -11,16 +11,16 @@ pub async fn connect(addr: Option<String>, username: String, password: String) -
|
|||
}
|
||||
|
||||
#[napi]
|
||||
impl CodempClient {
|
||||
impl Client {
|
||||
#[napi(js_name = "join_workspace")]
|
||||
/// join workspace with given id (will start its cursor controller)
|
||||
pub async fn js_join_workspace(&self, workspace: String) -> napi::Result<CodempWorkspace> {
|
||||
pub async fn js_join_workspace(&self, workspace: String) -> napi::Result<Workspace> {
|
||||
Ok(self.join_workspace(workspace).await?)
|
||||
}
|
||||
|
||||
#[napi(js_name = "get_workspace")]
|
||||
/// get workspace with given id, if it exists
|
||||
pub fn js_get_workspace(&self, workspace: String) -> Option<CodempWorkspace> {
|
||||
pub fn js_get_workspace(&self, workspace: String) -> Option<Workspace> {
|
||||
self.get_workspace(&workspace)
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ impl CodempClient {
|
|||
}
|
||||
|
||||
#[napi(js_name = "active_workspaces")]
|
||||
/// get list of all active workspaces
|
||||
pub fn js_active_workspaces(&self) -> Vec<String> {
|
||||
self.active_workspaces()
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use napi_derive::napi;
|
||||
use napi::threadsafe_function::{ThreadsafeFunction, ThreadSafeCallContext, ThreadsafeFunctionCallMode, ErrorStrategy};
|
||||
use crate::api::Controller;
|
||||
use crate::prelude::*;
|
||||
use crate::cursor::controller::CursorController;
|
||||
|
||||
|
||||
#[napi(object, js_name = "Cursor")]
|
||||
|
@ -15,9 +15,9 @@ pub struct JsCursor {
|
|||
pub user: Option<String>,
|
||||
}
|
||||
|
||||
impl From<JsCursor> for CodempCursor {
|
||||
impl From<JsCursor> for crate::api::Cursor {
|
||||
fn from(value: JsCursor) -> Self {
|
||||
CodempCursor {
|
||||
crate::api::Cursor {
|
||||
start : (value.start_row, value.start_col),
|
||||
end: (value.end_row, value.end_col),
|
||||
buffer: value.buffer,
|
||||
|
@ -25,8 +25,8 @@ impl From<JsCursor> for CodempCursor {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl From<CodempCursor> for JsCursor {
|
||||
fn from(value: CodempCursor) -> Self {
|
||||
impl From<crate::api::Cursor> for JsCursor {
|
||||
fn from(value: crate::api::Cursor) -> Self {
|
||||
JsCursor {
|
||||
start_row : value.start.0,
|
||||
start_col : value.start.1,
|
||||
|
@ -41,8 +41,8 @@ impl From<CodempCursor> for JsCursor {
|
|||
|
||||
|
||||
#[napi]
|
||||
impl CodempCursorController {
|
||||
#[napi(ts_args_type = "fun: (event: JsCursorEvent) => void")]
|
||||
impl CursorController {
|
||||
#[napi(ts_args_type = "fun: (event: Cursor) => void")]
|
||||
pub fn callback(&self, fun: napi::JsFunction) -> napi::Result<()>{
|
||||
let tsfn : ThreadsafeFunction<JsCursor, ErrorStrategy::Fatal> =
|
||||
fun.create_threadsafe_function(0,
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use napi_derive::napi;
|
||||
use crate::prelude::*;
|
||||
use crate::Workspace;
|
||||
use crate::buffer::controller::BufferController;
|
||||
use crate::cursor::controller::CursorController;
|
||||
|
||||
|
||||
#[napi]
|
||||
impl CodempWorkspace {
|
||||
impl Workspace {
|
||||
#[napi(js_name = "id")]
|
||||
pub fn js_id(&self) -> String {
|
||||
self.id()
|
||||
|
@ -17,12 +17,12 @@ impl CodempWorkspace {
|
|||
}
|
||||
|
||||
#[napi(js_name = "cursor")]
|
||||
pub fn js_cursor(&self) -> CodempCursorController {
|
||||
pub fn js_cursor(&self) -> CursorController {
|
||||
self.cursor()
|
||||
}
|
||||
|
||||
#[napi(js_name = "buffer_by_name")]
|
||||
pub fn js_buffer_by_name(&self, path: String) -> Option<CodempBufferController> {
|
||||
pub fn js_buffer_by_name(&self, path: String) -> Option<BufferController> {
|
||||
self.buffer_by_name(&path)
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ impl CodempWorkspace {
|
|||
}
|
||||
|
||||
#[napi(js_name = "attach")]
|
||||
pub async fn js_attach(&self, path: String) -> napi::Result<CodempBufferController> {
|
||||
pub async fn js_attach(&self, path: String) -> napi::Result<BufferController> {
|
||||
Ok(self.attach(&path).await?)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue