You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
dumbpilot/src/common.ts

76 lines
1.7 KiB

import { mkdirSync } from 'fs';
import * as vscode from 'vscode';
// common data structures and functions
export type FetchErrorCause = {
errno: number;
code: string;
syscall: string;
address: string;
port: number;
};
// a summary of the received data
export type ResponseData = {
content: string;
tokens: number;
time: number;
};
// Show a message notification with a set timeout
export async function showMessageWithTimeout(message: string, timeout: number): Promise<void> {
void vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: message,
cancellable: false,
},
(progress, token) => {
token.onCancellationRequested(() => {});
// This is magic I don't understand
const p = new Promise<void>((resolve) => {
setTimeout(resolve, timeout);
});
return p;
}
);
}
// show a message on the status bar until the promise is resolved
export async function showPendingStatusBar(
message: string,
operation: Promise<any>
): Promise<void> {
void vscode.window
.withProgress(
{
location: vscode.ProgressLocation.Window,
title: message,
},
() => operation
)
.then(
(aok) => {},
(err) => {}
);
// we already resolve the operation elsewhere
}
let st_msg: vscode.StatusBarItem | undefined;
export function updateStatusBarMessage(text: string) {
if (!st_msg) {
st_msg = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, -100);
}
const run_color = new vscode.ThemeColor('statusBarItem.warningBackground');
if (text.length > 0) {
st_msg.backgroundColor = run_color;
st_msg.text = '$(megaphone) ' + text.trim();
st_msg.show();
} else {
st_msg.hide();
}
}