@@ -18,10 +18,15 @@ export async function selectRunnable(
18
18
prevRunnable ?: RunnableQuickPick ,
19
19
debuggeeOnly = false ,
20
20
showButtons : boolean = true ,
21
+ mode ?: "cursor" ,
21
22
) : Promise < RunnableQuickPick | undefined > {
22
23
const editor = ctx . activeRustEditor ?? ctx . activeCargoTomlEditor ;
23
24
if ( ! editor ) return ;
24
25
26
+ if ( mode === "cursor" ) {
27
+ return selectRunnableAtCursor ( ctx , editor , prevRunnable ) ;
28
+ }
29
+
25
30
// show a placeholder while we get the runnables from the server
26
31
const quickPick = vscode . window . createQuickPick ( ) ;
27
32
quickPick . title = "Select Runnable" ;
@@ -54,6 +59,58 @@ export async function selectRunnable(
54
59
) ;
55
60
}
56
61
62
+ async function selectRunnableAtCursor (
63
+ ctx : CtxInit ,
64
+ editor : RustEditor ,
65
+ prevRunnable ?: RunnableQuickPick ,
66
+ ) : Promise < RunnableQuickPick | undefined > {
67
+ const runnableQuickPicks = await getRunnables ( ctx . client , editor , prevRunnable , false ) ;
68
+ let runnableQuickPickAtCursor = null ;
69
+ const cursorPosition = ctx . client . code2ProtocolConverter . asPosition ( editor . selection . active ) ;
70
+ for ( const runnableQuickPick of runnableQuickPicks ) {
71
+ if ( ! runnableQuickPick . runnable . location ?. targetRange ) {
72
+ continue ;
73
+ }
74
+ const runnableQuickPickRange = runnableQuickPick . runnable . location . targetRange ;
75
+ if (
76
+ runnableQuickPickAtCursor ?. runnable ?. location ?. targetRange != null &&
77
+ rangeContainsOtherRange (
78
+ runnableQuickPickRange ,
79
+ runnableQuickPickAtCursor . runnable . location . targetRange ,
80
+ )
81
+ ) {
82
+ continue ;
83
+ }
84
+ if ( rangeContainsPosition ( runnableQuickPickRange , cursorPosition ) ) {
85
+ runnableQuickPickAtCursor = runnableQuickPick ;
86
+ }
87
+ }
88
+ if ( runnableQuickPickAtCursor == null ) {
89
+ return ;
90
+ }
91
+ return Promise . resolve ( runnableQuickPickAtCursor ) ;
92
+ }
93
+
94
+ function rangeContainsPosition ( range : lc . Range , position : lc . Position ) : boolean {
95
+ return (
96
+ ( position . line > range . start . line ||
97
+ ( position . line === range . start . line && position . character >= range . start . character ) ) &&
98
+ ( position . line < range . end . line ||
99
+ ( position . line === range . end . line && position . character <= range . end . character ) )
100
+ ) ;
101
+ }
102
+
103
+ function rangeContainsOtherRange ( range : lc . Range , otherRange : lc . Range ) {
104
+ return (
105
+ ( range . start . line < otherRange . start . line ||
106
+ ( range . start . line === otherRange . start . line &&
107
+ range . start . character <= otherRange . start . character ) ) &&
108
+ ( range . end . line > otherRange . end . line ||
109
+ ( range . end . line === otherRange . end . line &&
110
+ range . end . character >= otherRange . end . character ) )
111
+ ) ;
112
+ }
113
+
57
114
export class RunnableQuickPick implements vscode . QuickPickItem {
58
115
public label : string ;
59
116
public description ?: string | undefined ;
0 commit comments