I thought I'd share this :)

Just a small example script that is possible to run in leojs, (with also 
having the vscode API available in g.app.vscode)

Incredibly, when executing the script, the global objects you'd expect to 
see in javascript ,(console, fetch, ect...) are available, as shown below!

Hoping to release a beta before the autumn starts!
Félix

@language javascript
const vscode = g.app.vscode;
g.es("hahahaha");
// 'await' for doCommandByName required only if other code in script is 
'awaited'.
await c.doCommandByName('insert-headline-time');

const userInput = await vscode.window.showInputBox({
placeHolder: 'Enter something', // Placeholder text in the input box
prompt: 'Please enter some text:', // Prompt message above the input box
});
if (userInput === undefined) {
g.es('User canceled the input.');
} else {
g.es('User input:', userInput);
}
try {
const apiUrl = 'https://jsonplaceholder.typicode.com/users';
const response = await fetch(apiUrl);
g.es("about to call");
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
g.es("got it!!", JSON.stringify(data));
} catch (error) {
g.es("oh no!");
console.error('Fetch error:', error);
}

On Sunday, September 3, 2023 at 3:02:54 PM UTC-4 Félix wrote:

> Thanks to you both!! 
>
> g.app.vscode also felt right to me, so I'm glad this is a shared view!
>
> Félix
>
> On Sunday, September 3, 2023 at 7:10:10 AM UTC-4 Edward K. Ream wrote:
>
>> On Sat, Sep 2, 2023 at 8:49 PM Félix <felix...@gmail.com> wrote:
>>
>>> Not sure what to decide for this so I thought of doing this quick 
>>> survey! :)
>>>
>>> When running scripts, (CTRL+B) Leo offers the g, c and p variables. I 
>>> obviously want to expose the vscode API from it's base object "vscode".
>>>
>>> Should it be top-level along with c, g and p? or, be located at:
>>>
>>> g.vscode
>>>
>>> or 
>>>
>>> g.app.vscode
>>>
>>
>> Interesting question. All three choices, vscode, g.vscode and 
>> g.app.vscode are feasible.
>>
>> g.vscode seems like the worst choice.
>>
>> I tend to agree with Thomas. g.app.vscode is most explicit. Furthermore, 
>> g.app is likely the best place for a "pointer" to vscode.
>>
>> A default/automatic binding to vscode doesn't seem like it would be all 
>> that useful. Any code can bind vscode to g.app.vscode easily enough. I 
>> might change my mind if you envision scenarios in which there are *lots* 
>> of usages of g.app.vscode.
>>
>> Edward
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/d2c14762-f894-4879-897c-6313c7ffb92bn%40googlegroups.com.

Reply via email to