Skip to content

Commit 75cf4d2

Browse files
committed
fix: wrong hint location
Also polished Future crate
1 parent 83b05cc commit 75cf4d2

File tree

6 files changed

+28
-24
lines changed

6 files changed

+28
-24
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"type": "lldb",
6565
"request": "attach",
6666
"name": "debug lsp",
67-
"program": "plc",
67+
"pid": "${command:pickProcess}"
6868
},
6969
{
7070
"type": "lldb",

planglib/std/future/delay.pi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ impl Future<()> for Delay{
2222
thread::spawn(||=>{
2323
let sec = self.sec - (unixtime() - self.start);
2424
if sec <= 0 {
25-
wk.wake(wk.ch);
25+
wk.wake();
2626
return;
2727
}
2828
thread::sleep(sec);
29-
wk.wake(wk.ch);
29+
wk.wake();
3030
return;
3131
});
3232
return Pending{};

planglib/std/future/executor.pi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ impl Executor {
2121
while true {
2222
let work: |Waker|=>void = self.ch.recv();
2323
let waker = Waker{
24-
wake: |ch| => void {
25-
ch.send(work);
24+
wake: || => void {
25+
self.ch.send(work);
2626
return;
2727
},
28-
ch: self.ch,
2928
};
3029
work(waker);
3130
}

planglib/std/future/primitives.pi

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::chan;
22
pub struct Waker {
3-
pub wake:|*chan::Chan<|Waker|=>void>|=>void;
4-
pub ch:*chan::Chan<|Waker|=>void>;
3+
pub wake:||=>void;
54
}
65

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

4039
use std::io;
4140

41+
4242
impl <T|R> FutureExt<T|R> for Future<T> {
4343
fn continue_with(f:|T|=>Future<R>) Future<R> {
4444
let re = Pending{} as Poll<R>;
4545
let ff = FnFuture<R>{};
4646
ff.re = re;
4747
ff.f = |wk:Waker|=> {
48-
let re = self.poll(Waker{wake:|ch|=>{
48+
let re = self.poll(Waker{wake:||=>{
4949
let re = self.poll(Waker{}) as Ready<T>!;
50-
51-
ch.send(|_wk:Waker|=>{
52-
let re1 = f(re.v);
53-
let result = re1.poll(wk);
54-
ff.re = result;
55-
if result is Ready<R>{
56-
wk.wake(wk.ch);
57-
}
58-
return;
59-
});
60-
50+
let re1 = f(re.v);
51+
let result = re1.poll(wk);
52+
ff.re = result;
53+
if result is Ready<R>{
54+
wk.wake();
55+
}
6156
return;
62-
},ch:wk.ch});
57+
}});
6358
if re is Ready<T> {
6459
let re = f((re as Ready<T>!).v);
65-
return re.poll(wk);
60+
let result = re.poll(wk);
61+
ff.re = result;
62+
return result;
6663
}
6764
return Pending{} as Poll<R>;
6865
};

src/ast/ctx/lsp.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ impl Ctx<'_> {
120120
.push(range.to_diag_range(), type_index(tp), modifiers)
121121
}
122122
pub fn push_type_hints(&self, range: Range, pltype: Arc<RefCell<PLType>>) {
123-
if self.need_highlight.borrow().ne(&0) || self.in_macro {
123+
let ori_mod = unsafe { &*self.origin_mod as &crate::ast::plmod::Mod };
124+
if self.need_highlight.borrow().ne(&0) || self.in_macro || ori_mod.path != self.plmod.path {
124125
return;
125126
}
126127
let colon = InlayHintLabelPart {
@@ -151,7 +152,8 @@ impl Ctx<'_> {
151152
self.plmod.hints.borrow_mut().push(hint);
152153
}
153154
pub fn push_param_hint(&self, range: Range, name: Ustr) {
154-
if self.need_highlight.borrow().ne(&0) || self.in_macro {
155+
let ori_mod = unsafe { &*self.origin_mod as &crate::ast::plmod::Mod };
156+
if self.need_highlight.borrow().ne(&0) || self.in_macro || ori_mod.path != self.plmod.path {
155157
return;
156158
}
157159
let hint = InlayHint {

test/test/future_test.pi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ pub fn test_future() void {
1313
let ff1 = f.continue_with(|r:()| => {
1414
println!("Hello from future");
1515
return future::nothing_future();
16+
}).continue_with(|r:()| => {
17+
println!("continue Hello from future");
18+
return future::nothing_future();
1619
});
1720

1821
let f2:future::Future<()> = future::delay(1 as u64);
1922
let ff2 = f2.continue_with(|r:()| => {
2023
println!("Hello from future2");
2124
return future::nothing_future();
25+
}).continue_with(|r:()| => {
26+
println!("continue Hello from future2");
27+
return future::nothing_future();
2228
});
2329
exe.spawn(ff1);
2430
exe.spawn(ff2);

0 commit comments

Comments
 (0)