Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* draft first pass of undo * hack mix to get project to compile with rust * hack nif to try to get tests to pass * save WiP of undo manager * revert mix to original repo * get undo code to compile * undo manager compiling checkpoint * prove passable tests with incremental strategy * add undo * save WiP of undo with origin * fix NIF param context * test undo * use yrs undo correctly * extend capability beyond Yex.Text to Yex.Map and Yex.Array * make undo threadsafe * add origin awareness tests to map and array * resolved, apparently, thread safety by changing test setup * ensure thread safety * refactor to use shared implementation for new * unify NIF interface * implement stop_capture, expand_scope, and exclude_origin * clean up obviated parallel "new" functions * add observers and ability to add/get metadata from stack items * manage undo observer state in GenServer * remove debug * add clear * add undo manager with options * add options timeout test * mirror yjs examples for clarity for satoren * Update lib/server/undo_server_observer_behaviour.ex Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * move server tests to correct test folder * refactor undo_server as simplified observer_server * remove bad undo observer scheme * draft first pass of undo * hack mix to get project to compile with rust * hack nif to try to get tests to pass * save WiP of undo manager * revert mix to original repo * get undo code to compile * undo manager compiling checkpoint * prove passable tests with incremental strategy * add undo * save WiP of undo with origin * fix NIF param context * test undo * use yrs undo correctly * extend capability beyond Yex.Text to Yex.Map and Yex.Array * make undo threadsafe * add origin awareness tests to map and array * resolved, apparently, thread safety by changing test setup * ensure thread safety * refactor to use shared implementation for new * unify NIF interface * implement stop_capture, expand_scope, and exclude_origin * clean up obviated parallel "new" functions * add observers and ability to add/get metadata from stack items * manage undo observer state in GenServer * remove debug * add clear * add undo manager with options * add options timeout test * mirror yjs examples for clarity for satoren * Update lib/server/undo_server_observer_behaviour.ex Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * move server tests to correct test folder * refactor undo_server as simplified observer_server * remove bad undo observer scheme * put undo in correct fmt position * remove unused atoms previously supporting undo observers * fmt undo * format elixir code * format changes to nif * adopt byzantine structure to try to help coveralls see we are indeed covered * format undo test * worsen code structure to put up with coveralls not seeing inside pattern matches * test embedded objects * format * remove pattern matching * improve order * add xml tests * use NifUntaggedEnum * fmt properly * suffice coderabbit refactor suggestion Refactor suggestion Ensure consistent return types for new/2 and new_with_options/3. Currently, new_with_options/3 uses unwrap_manager_result/1 to directly return either the manager struct or an error, whereas new/2 calls new_with_options/3 without wrapping the result. This can lead to inconsistent error handling and unexpected behaviors. For clarity and better error handling, consider modifying both functions to return {:ok, manager} on success or {:error, reason} on failure. This aligns with Elixir conventions and makes error handling more predictable for the caller. Apply this diff to adjust the return values: def new(doc, scope) when is_struct(scope) do - new_with_options(doc, scope, %Options{}) + case new_with_options(doc, scope, %Options{}) do + {:ok, manager} -> {:ok, manager} + error -> error + end end def new_with_options(doc, scope, %Options{} = options) do doc |> Yex.Nif.undo_manager_new_with_options(scope, options) - |> unwrap_manager_result() + |> case do + {:ok, manager} -> {:ok, manager} + error -> error + end end * suffice coderabbit potential issue Handle potential errors when creating an UndoManager. In the create_undo_manager_with_options function, the use of unwrap() can cause a panic if an error occurs while getting the branch reference. It is safer to handle the error properly to prevent unexpected crashes. * suffice coderabbit unsafe transmute usage issue Avoid unsafe transmute usage and improper Env lifetime extension. Using unsafe { std::mem::transmute(env) } to extend the lifetime of Env to static is unsafe and can lead to undefined behavior. The Env should not outlive the NIF call. * remove unused functions * make purpose more clear * make purpose more clear * remove test replaced by guards * fix nits * fmt * improve coverage * simplify * satisfy coveralls demand for coverage * improve comments * replace try with case pattern match for better style * remove unsued crate * remove unsued atoms * clarify comments in tests * clarify tests * clarify purpose of origins in test --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Loading branch information