UNPKG

@posit-dev/positron

Version:

TypeScript definitions and runtime utilities for the Positron API

70 lines (59 loc) 2.36 kB
/// <reference path="./positron.d.ts" /> /// <reference path="./ui-comm.d.ts" /> /// <reference path="./positron.d.ts" /> /// <reference path="./ui-comm.d.ts" /> /// <reference path="./positron.d.ts" /> /// <reference path="./ui-comm.d.ts" /> /// <reference path="./positron.d.ts" /> /// <reference path="./ui-comm.d.ts" /> /// <reference path="./positron.d.ts" /> /// <reference path="./ui-comm.d.ts" /> /// <reference path="./positron.d.ts" /> /// <reference path="./ui-comm.d.ts" /> /// <reference path="./positron.d.ts" /> /// <reference path="./ui-comm.d.ts" /> /// <reference path="./positron.d.ts" /> /// <reference path="./ui-comm.d.ts" /> /// <reference path="./positron.d.ts" /> /// <reference path="./ui-comm.d.ts" /> /// <reference path="./positron.d.ts" /> /// <reference path="./ui-comm.d.ts" /> export { tryAcquirePositronApi, inPositron, type PositronApi } from './runtime'; export { previewUrl } from './preview'; export type * from 'positron'; declare global { /** * Global function that may be injected by Positron to acquire the Positron API. * * **Important**: This function is `undefined` when running in VS Code and only exists * when running in Positron. Always check for its existence before calling it. * * For safer access to the Positron API, consider using `tryAcquirePositronApi()` instead, * which handles the runtime detection automatically. * * @returns The Positron API object, or undefined if not available * * @example * ```typescript * // Safe usage with type checking (recommended) * if (typeof acquirePositronApi !== 'undefined') { * const positronApi = acquirePositronApi(); * if (positronApi) { * // Use positronApi... * positronApi.runtime.executeCode('python', 'print("Hello!")', true); * } * } * * // Alternative safe usage with optional chaining * const positronApi = globalThis.acquirePositronApi?.(); * if (positronApi) { * // Use positronApi... * } * * // For simpler code, consider using the wrapper function: * import { tryAcquirePositronApi } from '@posit-dev/positron'; * const positronApi = tryAcquirePositronApi(); * ``` */ const acquirePositronApi: (() => typeof import('positron') | undefined) | undefined; }