Skip to content

Commit

Permalink
fix: wrong hint location
Browse files Browse the repository at this point in the history
Also polished Future crate
  • Loading branch information
Chronostasys committed Aug 6, 2024
1 parent 83b05cc commit 75cf4d2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"type": "lldb",
"request": "attach",
"name": "debug lsp",
"program": "plc",
"pid": "${command:pickProcess}"
},
{
"type": "lldb",
Expand Down
4 changes: 2 additions & 2 deletions planglib/std/future/delay.pi
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Future<()> for Delay{
thread::spawn(||=>{
let sec = self.sec - (unixtime() - self.start);
if sec <= 0 {
wk.wake(wk.ch);
wk.wake();
return;
}
thread::sleep(sec);
wk.wake(wk.ch);
wk.wake();
return;
});
return Pending{};
Expand Down
5 changes: 2 additions & 3 deletions planglib/std/future/executor.pi
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ impl Executor {
while true {
let work: |Waker|=>void = self.ch.recv();
let waker = Waker{
wake: |ch| => void {
ch.send(work);
wake: || => void {
self.ch.send(work);
return;
},
ch: self.ch,
};
work(waker);
}
Expand Down
29 changes: 13 additions & 16 deletions planglib/std/future/primitives.pi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::chan;
pub struct Waker {
pub wake:|*chan::Chan<|Waker|=>void>|=>void;
pub ch:*chan::Chan<|Waker|=>void>;
pub wake:||=>void;
}

pub struct Pending {}
Expand Down Expand Up @@ -39,30 +38,28 @@ impl <T> Future<T> for FnFuture<T> {

use std::io;


impl <T|R> FutureExt<T|R> for Future<T> {
fn continue_with(f:|T|=>Future<R>) Future<R> {
let re = Pending{} as Poll<R>;
let ff = FnFuture<R>{};
ff.re = re;
ff.f = |wk:Waker|=> {
let re = self.poll(Waker{wake:|ch|=>{
let re = self.poll(Waker{wake:||=>{
let re = self.poll(Waker{}) as Ready<T>!;

ch.send(|_wk:Waker|=>{
let re1 = f(re.v);
let result = re1.poll(wk);
ff.re = result;
if result is Ready<R>{
wk.wake(wk.ch);
}
return;
});

let re1 = f(re.v);
let result = re1.poll(wk);
ff.re = result;
if result is Ready<R>{
wk.wake();
}
return;
},ch:wk.ch});
}});
if re is Ready<T> {
let re = f((re as Ready<T>!).v);
return re.poll(wk);
let result = re.poll(wk);
ff.re = result;
return result;
}
return Pending{} as Poll<R>;
};
Expand Down
6 changes: 4 additions & 2 deletions src/ast/ctx/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ impl Ctx<'_> {
.push(range.to_diag_range(), type_index(tp), modifiers)
}
pub fn push_type_hints(&self, range: Range, pltype: Arc<RefCell<PLType>>) {
if self.need_highlight.borrow().ne(&0) || self.in_macro {
let ori_mod = unsafe { &*self.origin_mod as &crate::ast::plmod::Mod };
if self.need_highlight.borrow().ne(&0) || self.in_macro || ori_mod.path != self.plmod.path {
return;
}
let colon = InlayHintLabelPart {
Expand Down Expand Up @@ -151,7 +152,8 @@ impl Ctx<'_> {
self.plmod.hints.borrow_mut().push(hint);
}
pub fn push_param_hint(&self, range: Range, name: Ustr) {
if self.need_highlight.borrow().ne(&0) || self.in_macro {
let ori_mod = unsafe { &*self.origin_mod as &crate::ast::plmod::Mod };
if self.need_highlight.borrow().ne(&0) || self.in_macro || ori_mod.path != self.plmod.path {
return;
}
let hint = InlayHint {
Expand Down
6 changes: 6 additions & 0 deletions test/test/future_test.pi
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ pub fn test_future() void {
let ff1 = f.continue_with(|r:()| => {
println!("Hello from future");
return future::nothing_future();
}).continue_with(|r:()| => {
println!("continue Hello from future");
return future::nothing_future();
});

let f2:future::Future<()> = future::delay(1 as u64);
let ff2 = f2.continue_with(|r:()| => {
println!("Hello from future2");
return future::nothing_future();
}).continue_with(|r:()| => {
println!("continue Hello from future2");
return future::nothing_future();
});
exe.spawn(ff1);
exe.spawn(ff2);
Expand Down

0 comments on commit 75cf4d2

Please sign in to comment.