mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 07:14:50 +01:00
Merge pull request #11 from hexedtech/add-version
feat: add version function to the client.
This commit is contained in:
commit
224350cdb6
11 changed files with 63 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -33,3 +33,4 @@ dist/java/bin/
|
||||||
dist/java/gradle/
|
dist/java/gradle/
|
||||||
dist/java/gradlew
|
dist/java/gradlew
|
||||||
dist/java/gradlew.bat
|
dist/java/gradlew.bat
|
||||||
|
dist/java/.factorypath
|
||||||
|
|
8
dist/java/src/mp/code/Extensions.java
vendored
8
dist/java/src/mp/code/Extensions.java
vendored
|
@ -12,7 +12,13 @@ public final class Extensions {
|
||||||
static final Cleaner CLEANER = Cleaner.create();
|
static final Cleaner CLEANER = Cleaner.create();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hashes the given {@link String} using CodeMP's hashing algorithm (xxh3).
|
* Returns the version of the Rust crate as a String.
|
||||||
|
* @return the current version
|
||||||
|
*/
|
||||||
|
public static native String version();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hashes the given String using CodeMP's hashing algorithm (xxh3).
|
||||||
* @param input the string to hash
|
* @param input the string to hash
|
||||||
* @return the hash
|
* @return the hash
|
||||||
*/
|
*/
|
||||||
|
|
10
dist/java/src/mp/code/Workspace.java
vendored
10
dist/java/src/mp/code/Workspace.java
vendored
|
@ -80,6 +80,16 @@ public final class Workspace {
|
||||||
return active_buffers(this.ptr);
|
return active_buffers(this.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static native String[] user_list(long self);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the users currently in the workspace.
|
||||||
|
* @return an array containing the names of the users in the workspace
|
||||||
|
*/
|
||||||
|
public String[] userList() {
|
||||||
|
return user_list(this.ptr);
|
||||||
|
}
|
||||||
|
|
||||||
private static native void create_buffer(long self, String path) throws ConnectionRemoteException;
|
private static native void create_buffer(long self, String path) throws ConnectionRemoteException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
12
dist/lua/annotations.lua
vendored
12
dist/lua/annotations.lua
vendored
|
@ -222,7 +222,7 @@ function Workspace:get_buffer(path) end
|
||||||
function Workspace:attach(path) end
|
function Workspace:attach(path) end
|
||||||
|
|
||||||
---@param path string relative path ("name") of buffer to detach from
|
---@param path string relative path ("name") of buffer to detach from
|
||||||
---@return boolean
|
---@return boolean success
|
||||||
---detach from an active buffer, closing all streams. returns false if buffer was no longer active
|
---detach from an active buffer, closing all streams. returns false if buffer was no longer active
|
||||||
function Workspace:detach(path) end
|
function Workspace:detach(path) end
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ function BufferController:recv() end
|
||||||
---block until next text change without returning it
|
---block until next text change without returning it
|
||||||
function BufferController:poll() end
|
function BufferController:poll() end
|
||||||
|
|
||||||
---@return boolean
|
---@return boolean success
|
||||||
---stop buffer worker and disconnect, returns false if was already stopped
|
---stop buffer worker and disconnect, returns false if was already stopped
|
||||||
function BufferController:stop() end
|
function BufferController:stop() end
|
||||||
|
|
||||||
|
@ -354,7 +354,7 @@ function CursorController:recv() end
|
||||||
---block until next cursor event without returning it
|
---block until next cursor event without returning it
|
||||||
function CursorController:poll() end
|
function CursorController:poll() end
|
||||||
|
|
||||||
---@return boolean
|
---@return boolean success
|
||||||
---stop cursor worker and disconnect, returns false if was already stopped
|
---stop cursor worker and disconnect, returns false if was already stopped
|
||||||
function CursorController:stop() end
|
function CursorController:stop() end
|
||||||
|
|
||||||
|
@ -396,6 +396,10 @@ function Codemp.poll_callback() end
|
||||||
---use xxh3 hash, returns an i64 from any string
|
---use xxh3 hash, returns an i64 from any string
|
||||||
function Codemp.hash(data) end
|
function Codemp.hash(data) end
|
||||||
|
|
||||||
|
---@return string
|
||||||
|
---get current library version as string, in semver format
|
||||||
|
function Codemp.version() end
|
||||||
|
|
||||||
---@class (exact) RuntimeDriver
|
---@class (exact) RuntimeDriver
|
||||||
local RuntimeDriver = {}
|
local RuntimeDriver = {}
|
||||||
|
|
||||||
|
@ -411,6 +415,6 @@ function Codemp.setup_driver(block) end
|
||||||
|
|
||||||
---@param printer? string | fun(string) | nil log sink used for printing, if string will go to file, otherwise use given function
|
---@param printer? string | fun(string) | nil log sink used for printing, if string will go to file, otherwise use given function
|
||||||
---@param debug? boolean show more verbose debug logs, default false
|
---@param debug? boolean show more verbose debug logs, default false
|
||||||
---@return boolean true if logger was setup correctly, false otherwise
|
---@return boolean success if logger was setup correctly, false otherwise
|
||||||
---setup a global logger for codemp, note that can only be done once
|
---setup a global logger for codemp, note that can only be done once
|
||||||
function Codemp.setup_tracing(printer, debug) end
|
function Codemp.setup_tracing(printer, debug) end
|
||||||
|
|
2
dist/lua/codemp-0.7.0-1.rockspec
vendored
2
dist/lua/codemp-0.7.0-1.rockspec
vendored
|
@ -31,6 +31,6 @@ build = {
|
||||||
modules = { "codemp" },
|
modules = { "codemp" },
|
||||||
target_path = "../..",
|
target_path = "../..",
|
||||||
include = {
|
include = {
|
||||||
["codemp-annotations.lua"] = "dist/lua/annotations.lua",
|
["dist/lua/annotations.lua"] = "codemp-annotations.lua",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
use jni_toolbox::jni;
|
use jni_toolbox::jni;
|
||||||
|
|
||||||
|
/// Gets the current version of the Rust crate.
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
#[jni(package = "mp.code", class = "Extensions")]
|
||||||
|
fn version() -> String {
|
||||||
|
crate::version()
|
||||||
|
}
|
||||||
|
|
||||||
/// Calculate the XXH3 hash for a given String.
|
/// Calculate the XXH3 hash for a given String.
|
||||||
#[jni(package = "mp.code", class = "Extensions")]
|
#[jni(package = "mp.code", class = "Extensions")]
|
||||||
fn hash(content: String) -> i64 {
|
fn hash(content: String) -> i64 {
|
||||||
|
|
|
@ -31,6 +31,12 @@ fn active_buffers(workspace: &mut Workspace) -> Vec<String> {
|
||||||
workspace.buffer_list()
|
workspace.buffer_list()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets a list of the active buffers.
|
||||||
|
#[jni(package = "mp.code", class = "Workspace")]
|
||||||
|
fn user_list(workspace: &mut Workspace) -> Vec<String> {
|
||||||
|
workspace.user_list()
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new buffer.
|
/// Create a new buffer.
|
||||||
#[jni(package = "mp.code", class = "Workspace")]
|
#[jni(package = "mp.code", class = "Workspace")]
|
||||||
fn create_buffer(workspace: &mut Workspace, path: String) -> Result<(), RemoteError> {
|
fn create_buffer(workspace: &mut Workspace, path: String) -> Result<(), RemoteError> {
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
use napi_derive::napi;
|
use napi_derive::napi;
|
||||||
use crate::ext::hash;
|
|
||||||
|
|
||||||
|
|
||||||
#[napi(js_name = "hash")]
|
#[napi(js_name = "hash")]
|
||||||
pub fn js_hash(str : String) -> napi::Result<i64>{
|
pub fn js_hash(str : String) -> napi::Result<i64>{
|
||||||
Ok(hash(str))
|
Ok(crate::ext::hash(str))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[napi(js_name = "version")]
|
||||||
|
pub fn js_version(str : String) -> napi::Result<String>{
|
||||||
|
Ok(crate::version())
|
||||||
}
|
}
|
|
@ -27,6 +27,10 @@ fn entrypoint(lua: &Lua) -> LuaResult<LuaTable> {
|
||||||
Ok(crate::ext::hash(txt))
|
Ok(crate::ext::hash(txt))
|
||||||
)?)?;
|
)?)?;
|
||||||
|
|
||||||
|
exports.set("version", lua.create_function(|_, ()|
|
||||||
|
Ok(crate::version())
|
||||||
|
)?)?;
|
||||||
|
|
||||||
// runtime
|
// runtime
|
||||||
exports.set("setup_driver", lua.create_function(ext::a_sync::setup_driver)?)?;
|
exports.set("setup_driver", lua.create_function(ext::a_sync::setup_driver)?)?;
|
||||||
exports.set("poll_callback", lua.create_function(|lua, ()| {
|
exports.set("poll_callback", lua.create_function(|lua, ()| {
|
||||||
|
|
|
@ -132,6 +132,11 @@ impl Driver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pyfunction]
|
||||||
|
fn version() -> String {
|
||||||
|
crate::version()
|
||||||
|
}
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
fn init() -> PyResult<Driver> {
|
fn init() -> PyResult<Driver> {
|
||||||
let (rt_stop_tx, mut rt_stop_rx) = oneshot::channel::<()>();
|
let (rt_stop_tx, mut rt_stop_rx) = oneshot::channel::<()>();
|
||||||
|
@ -257,6 +262,7 @@ impl IntoPy<PyObject> for crate::api::User {
|
||||||
|
|
||||||
#[pymodule]
|
#[pymodule]
|
||||||
fn codemp(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
fn codemp(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
||||||
|
m.add_function(wrap_pyfunction!(version, m)?)?;
|
||||||
m.add_function(wrap_pyfunction!(init, m)?)?;
|
m.add_function(wrap_pyfunction!(init, m)?)?;
|
||||||
m.add_function(wrap_pyfunction!(get_default_config, m)?)?;
|
m.add_function(wrap_pyfunction!(get_default_config, m)?)?;
|
||||||
m.add_function(wrap_pyfunction!(connect, m)?)?;
|
m.add_function(wrap_pyfunction!(connect, m)?)?;
|
||||||
|
|
|
@ -121,3 +121,8 @@ pub mod ffi;
|
||||||
|
|
||||||
/// internal network services and interceptors
|
/// internal network services and interceptors
|
||||||
pub(crate) mod network;
|
pub(crate) mod network;
|
||||||
|
|
||||||
|
/// Get the current version of the client
|
||||||
|
pub fn version() -> String {
|
||||||
|
env!("CARGO_PKG_VERSION").to_owned()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue