sketch.rs

 1
 2use zed_plugin::RopeRef;
 3
 4
 5// Host
 6struct Handles {
 7    items: Vec<Box<dyn Any>>,
 8}
 9
10struct Rope;
11
12impl Link for Rope {
13    fn link(linker: &mut Linker) -> Result<()> {
14        linker.add(|this: &mut Rope| {
15            
16        });
17        linker.func_wrap("env", "len", |handles, arg| {
18            let rope = handles.downcast::<Rope>(arg.0);
19            let rope = Arc::from_raw(ptr);
20            let result = rope.len();
21            Arc::leak(rope);
22            result
23        });
24    }
25    
26    fn to_handle(self) -> Handle<Rope> {
27        todo!()
28    }
29}
30
31// -- Host
32
33pub fn edit_rope(&mut self) {
34    let rope: &mut Rope = self......rope();
35    let handle: RopeRef = self.runtime.to_handle(rope);
36    self.runtime.call("edit_rope", handle);
37}
38
39// Guest
40
41extern "C" long rope__len(u32 handle);
42
43struct RopeRef(u32);
44
45impl RopeRef {
46    fn len(&self) -> usize {
47        rope__len(self.0);
48    }
49}
50
51pub fn edit_rope(rope: RopeRef) {
52    rope.len()
53}
54
55// Host side ---
56
57pub struct Rope { .. }
58
59RopeRef(u32);
60
61impl Link for RopeRef {
62    pub fn init(&mut something) {
63        something.add("length", |rope| )
64    }
65}
66
67// ---
68
69extern "C" {
70    pub fn length(item: u32) -> u32;
71}
72
73struct RopeRef {
74    handle: u32,
75}
76
77pub fn length(ref: RopeRef) -> u32 {
78    ref.length()
79}
80
81// Host side
82
83#[plugin_interface]
84trait LspAdapter {
85    name() -> &'static str;
86}
87
88// Guest side