Skip to main content

JSEDITORAPI_TS_EDITOR_API

Constant JSEDITORAPI_TS_EDITOR_API 

Source
pub const JSEDITORAPI_TS_EDITOR_API: &str = "/**\n * Main editor API interface\n */\ninterface EditorAPI {\n  /**\n   * Get the active buffer ID (0 if none)\n   */\n  getActiveBufferId(): number;\n\n  /**\n   * Get the active split ID\n   */\n  getActiveSplitId(): number;\n\n  /**\n   * List all open buffers - returns array of BufferInfo objects\n   */\n  listBuffers(): BufferInfo[];\n\n  debug(msg: string): void;\n\n  info(msg: string): void;\n\n  warn(msg: string): void;\n\n  error(msg: string): void;\n\n  setStatus(msg: string): void;\n\n  copyToClipboard(text: string): void;\n\n  setClipboard(text: string): void;\n\n  /**\n   * Register a command - reads plugin name from __pluginName__ global\n   * context is optional - can be omitted, null, undefined, or a string\n   */\n  registerCommand(name: string, description: string, handlerName: string, context?: unknown): boolean;\n\n  /**\n   * Unregister a command by name\n   */\n  unregisterCommand(name: string): boolean;\n\n  /**\n   * Set a context (for keybinding conditions)\n   */\n  setContext(name: string, active: boolean): boolean;\n\n  /**\n   * Execute a built-in action\n   */\n  executeAction(actionName: string): boolean;\n\n  /**\n   * Translate a string - reads plugin name from __pluginName__ global\n   * Args is optional - can be omitted, undefined, null, or an object\n   */\n  t(key: string, ...args: unknown[]): string;\n\n  /**\n   * Get cursor position in active buffer\n   */\n  getCursorPosition(): number;\n\n  /**\n   * Get file path for a buffer\n   */\n  getBufferPath(bufferId: number): string;\n\n  /**\n   * Get buffer length in bytes\n   */\n  getBufferLength(bufferId: number): number;\n\n  /**\n   * Check if buffer has unsaved changes\n   */\n  isBufferModified(bufferId: number): boolean;\n\n  /**\n   * Save a buffer to a specific file path\n   * Used by :w filename to save unnamed buffers or save-as\n   */\n  saveBufferToPath(bufferId: number, path: string): boolean;\n\n  /**\n   * Get buffer info by ID\n   */\n  getBufferInfo(bufferId: number): BufferInfo | null;\n\n  /**\n   * Get primary cursor info for active buffer\n   */\n  getPrimaryCursor(): unknown;\n\n  /**\n   * Get all cursors for active buffer\n   */\n  getAllCursors(): unknown;\n\n  /**\n   * Get all cursor positions as byte offsets\n   */\n  getAllCursorPositions(): unknown;\n\n  /**\n   * Get viewport info for active buffer\n   */\n  getViewport(): ViewportInfo | null;\n\n  /**\n   * Get the line number (0-indexed) of the primary cursor\n   */\n  getCursorLine(): number;\n\n  /**\n   * Get the byte offset of the start of a line (0-indexed line number)\n   * Returns null if the line number is out of range\n   */\n  getLineStartPosition(line: number): Promise<number | null>;\n\n  /**\n   * Find buffer by file path, returns buffer ID or 0 if not found\n   */\n  findBufferByPath(path: string): number;\n\n  /**\n   * Get diff between buffer content and last saved version\n   */\n  getBufferSavedDiff(bufferId: number): BufferSavedDiff | null;\n\n  /**\n   * Insert text at a position in a buffer\n   */\n  insertText(bufferId: number, position: number, text: string): boolean;\n\n  /**\n   * Delete a range from a buffer\n   */\n  deleteRange(bufferId: number, start: number, end: number): boolean;\n\n  /**\n   * Insert text at cursor position in active buffer\n   */\n  insertAtCursor(text: string): boolean;\n\n  /**\n   * Open a file, optionally at a specific line/column\n   */\n  openFile(path: string, line: number | null, column: number | null): boolean;\n\n  /**\n   * Open a file in a specific split\n   */\n  openFileInSplit(splitId: number, path: string, line: number, column: number): boolean;\n\n  /**\n   * Show a buffer in the current split\n   */\n  showBuffer(bufferId: number): boolean;\n\n  /**\n   * Close a buffer\n   */\n  closeBuffer(bufferId: number): boolean;\n\n  /**\n   * Subscribe to an editor event\n   */\n  on(eventName: string, handlerName: string): void;\n\n  /**\n   * Unsubscribe from an event\n   */\n  off(eventName: string, handlerName: string): void;\n\n  /**\n   * Get an environment variable\n   */\n  getEnv(name: string): string | null;\n\n  /**\n   * Get current working directory\n   */\n  getCwd(): string;\n\n  /**\n   * Join path components (variadic - accepts multiple string arguments)\n   * Always uses forward slashes for cross-platform consistency (like Node.js path.posix.join)\n   */\n  pathJoin(...parts: string[]): string;\n\n  /**\n   * Get directory name from path\n   */\n  pathDirname(path: string): string;\n\n  /**\n   * Get file name from path\n   */\n  pathBasename(path: string): string;\n\n  /**\n   * Get file extension\n   */\n  pathExtname(path: string): string;\n\n  /**\n   * Check if path is absolute\n   */\n  pathIsAbsolute(path: string): boolean;\n\n  /**\n   * Check if file exists\n   */\n  fileExists(path: string): boolean;\n\n  /**\n   * Read file contents\n   */\n  readFile(path: string): string | null;\n\n  /**\n   * Write file contents\n   */\n  writeFile(path: string, content: string): boolean;\n\n  /**\n   * Read directory contents (returns array of {name, is_file, is_dir})\n   */\n  readDir(path: string): DirEntry[];\n\n  /**\n   * Get current config as JS object\n   */\n  getConfig(): unknown;\n\n  /**\n   * Get user config as JS object\n   */\n  getUserConfig(): unknown;\n\n  /**\n   * Reload configuration from file\n   */\n  reloadConfig(): void;\n\n  /**\n   * Reload theme registry from disk\n   * Call this after installing theme packages or saving new themes\n   */\n  reloadThemes(): void;\n\n  /**\n   * Register a TextMate grammar file for a language\n   * The grammar will be pending until reload_grammars() is called\n   */\n  registerGrammar(language: string, grammarPath: string, extensions: string[]): boolean;\n\n  /**\n   * Register language configuration (comment prefix, indentation, formatter)\n   */\n  registerLanguageConfig(language: string, config: LanguagePackConfig): boolean;\n\n  /**\n   * Register an LSP server for a language\n   */\n  registerLspServer(language: string, config: LspServerPackConfig): boolean;\n\n  /**\n   * Reload the grammar registry to apply registered grammars\n   * Call this after registering one or more grammars\n   */\n  reloadGrammars(): void;\n\n  /**\n   * Get config directory path\n   */\n  getConfigDir(): string;\n\n  /**\n   * Get themes directory path\n   */\n  getThemesDir(): string;\n\n  /**\n   * Apply a theme by name\n   */\n  applyTheme(themeName: string): boolean;\n\n  /**\n   * Get theme schema as JS object\n   */\n  getThemeSchema(): unknown;\n\n  /**\n   * Get list of builtin themes as JS object\n   */\n  getBuiltinThemes(): unknown;\n\n  /**\n   * Delete a custom theme (alias for deleteThemeSync)\n   */\n  deleteTheme(name: string): boolean;\n\n  /**\n   * Get file stat information\n   */\n  fileStat(path: string): unknown;\n\n  /**\n   * Check if a background process is still running\n   */\n  isProcessRunning(ProcessId: number): boolean;\n\n  /**\n   * Kill a process by ID (alias for killBackgroundProcess)\n   */\n  killProcess(processId: number): boolean;\n\n  /**\n   * Translate a key for a specific plugin\n   */\n  pluginTranslate(pluginName: string, key: string, args?: Record<string, unknown>): string;\n\n  /**\n   * Create a composite buffer (async)\n   * \n   * Uses typed CreateCompositeBufferOptions - serde validates field names at runtime\n   * via `deny_unknown_fields` attribute\n   */\n  createCompositeBuffer(opts: CreateCompositeBufferOptions): Promise<number>;\n\n  /**\n   * Update alignment hunks for a composite buffer\n   * \n   * Uses typed Vec<CompositeHunk> - serde validates field names at runtime\n   */\n  updateCompositeAlignment(bufferId: number, hunks: CompositeHunk[]): boolean;\n\n  /**\n   * Close a composite buffer\n   */\n  closeCompositeBuffer(bufferId: number): boolean;\n\n  /**\n   * Request syntax highlights for a buffer range (async)\n   */\n  getHighlights(bufferId: number, start: number, end: number): Promise<TsHighlightSpan[]>;\n\n  /**\n   * Add an overlay with styling options\n   * \n   * Colors can be specified as RGB arrays `[r, g, b]` or theme key strings.\n   * Theme keys are resolved at render time, so overlays update with theme changes.\n   * \n   * Theme key examples: \"ui.status_bar_fg\", \"editor.selection_bg\", \"syntax.keyword\"\n   * \n   * Example usage in TypeScript:\n   * ```typescript\n   * editor.addOverlay(bufferId, \"my-namespace\", 0, 10, {\n   * fg: \"syntax.keyword\",           // theme key\n   * bg: [40, 40, 50],               // RGB array\n   * bold: true,\n   * });\n   * ```\n   */\n  addOverlay(bufferId: number, namespace: string, start: number, end: number, options: Record<string, unknown>): boolean;\n\n  /**\n   * Clear all overlays in a namespace\n   */\n  clearNamespace(bufferId: number, namespace: string): boolean;\n\n  /**\n   * Clear all overlays from a buffer\n   */\n  clearAllOverlays(bufferId: number): boolean;\n\n  /**\n   * Clear all overlays that overlap with a byte range\n   */\n  clearOverlaysInRange(bufferId: number, start: number, end: number): boolean;\n\n  /**\n   * Remove an overlay by its handle\n   */\n  removeOverlay(bufferId: number, handle: string): boolean;\n\n  /**\n   * Submit a view transform for a buffer/split\n   * \n   * Note: tokens should be ViewTokenWire[], layoutHints should be LayoutHints\n   * These use manual parsing due to complex enum handling\n   */\n  submitViewTransform(bufferId: number, splitId: number | null, start: number, end: number, tokens: Record<string, unknown>[], LayoutHints?: Record<string, unknown>): boolean;\n\n  /**\n   * Clear view transform for a buffer/split\n   */\n  clearViewTransform(bufferId: number, splitId: number | null): boolean;\n\n  /**\n   * Set file explorer decorations for a namespace\n   */\n  setFileExplorerDecorations(namespace: string, decorations: Record<string, unknown>[]): boolean;\n\n  /**\n   * Clear file explorer decorations for a namespace\n   */\n  clearFileExplorerDecorations(namespace: string): boolean;\n\n  /**\n   * Add virtual text (inline text that doesn\'t exist in the buffer)\n   */\n  addVirtualText(bufferId: number, virtualTextId: string, position: number, text: string, r: number, g: number, b: number, before: boolean, useBg: boolean): boolean;\n\n  /**\n   * Remove a virtual text by ID\n   */\n  removeVirtualText(bufferId: number, virtualTextId: string): boolean;\n\n  /**\n   * Remove virtual texts whose ID starts with the given prefix\n   */\n  removeVirtualTextsByPrefix(bufferId: number, prefix: string): boolean;\n\n  /**\n   * Clear all virtual texts from a buffer\n   */\n  clearVirtualTexts(bufferId: number): boolean;\n\n  /**\n   * Clear all virtual texts in a namespace\n   */\n  clearVirtualTextNamespace(bufferId: number, namespace: string): boolean;\n\n  /**\n   * Add a virtual line (full line above/below a position)\n   */\n  addVirtualLine(bufferId: number, position: number, text: string, fgR: number, fgG: number, fgB: number, bgR: number, bgG: number, bgB: number, above: boolean, namespace: string, priority: number): boolean;\n\n  /**\n   * Show a prompt and wait for user input (async)\n   * Returns the user input or null if cancelled\n   */\n  prompt(label: string, initialValue: string): Promise<string | null>;\n\n  /**\n   * Start an interactive prompt\n   */\n  startPrompt(label: string, promptType: string): boolean;\n\n  /**\n   * Start a prompt with initial value\n   */\n  startPromptWithInitial(label: string, promptType: string, initialValue: string): boolean;\n\n  /**\n   * Set suggestions for the current prompt\n   * \n   * Uses typed Vec<Suggestion> - serde validates field names at runtime\n   */\n  setPromptSuggestions(suggestions: Suggestion[]): boolean;\n\n  /**\n   * Define a buffer mode (takes bindings as array of [key, command] pairs)\n   */\n  defineMode(name: string, parent: string | null, bindingsArr: string[][], readOnly?: boolean): boolean;\n\n  /**\n   * Set the global editor mode\n   */\n  setEditorMode(mode: string | null): boolean;\n\n  /**\n   * Get the current editor mode\n   */\n  getEditorMode(): string | null;\n\n  /**\n   * Close a split\n   */\n  closeSplit(splitId: number): boolean;\n\n  /**\n   * Set the buffer displayed in a split\n   */\n  setSplitBuffer(splitId: number, bufferId: number): boolean;\n\n  /**\n   * Focus a specific split\n   */\n  focusSplit(splitId: number): boolean;\n\n  /**\n   * Set scroll position of a split\n   */\n  setSplitScroll(splitId: number, topByte: number): boolean;\n\n  /**\n   * Set the ratio of a split (0.0 to 1.0, 0.5 = equal)\n   */\n  setSplitRatio(splitId: number, ratio: number): boolean;\n\n  /**\n   * Distribute all splits evenly\n   */\n  distributeSplitsEvenly(): boolean;\n\n  /**\n   * Set cursor position in a buffer\n   */\n  setBufferCursor(bufferId: number, position: number): boolean;\n\n  /**\n   * Set a line indicator in the gutter\n   */\n  setLineIndicator(bufferId: number, line: number, namespace: string, symbol: string, r: number, g: number, b: number, priority: number): boolean;\n\n  /**\n   * Clear line indicators in a namespace\n   */\n  clearLineIndicators(bufferId: number, namespace: string): boolean;\n\n  /**\n   * Enable or disable line numbers for a buffer\n   */\n  setLineNumbers(bufferId: number, enabled: boolean): boolean;\n\n  /**\n   * Create a scroll sync group for anchor-based synchronized scrolling\n   */\n  createScrollSyncGroup(groupId: number, leftSplit: number, rightSplit: number): boolean;\n\n  /**\n   * Set sync anchors for a scroll sync group\n   */\n  setScrollSyncAnchors(groupId: number, anchors: number[][]): boolean;\n\n  /**\n   * Remove a scroll sync group\n   */\n  removeScrollSyncGroup(groupId: number): boolean;\n\n  /**\n   * Execute multiple actions in sequence\n   * \n   * Takes typed ActionSpec array - serde validates field names at runtime\n   */\n  executeActions(actions: ActionSpec[]): boolean;\n\n  /**\n   * Show an action popup\n   * \n   * Takes a typed ActionPopupOptions struct - serde validates field names at runtime\n   */\n  showActionPopup(opts: ActionPopupOptions): boolean;\n\n  /**\n   * Disable LSP for a specific language\n   */\n  disableLspForLanguage(language: string): boolean;\n\n  /**\n   * Set the workspace root URI for a specific language\'s LSP server\n   * This allows plugins to specify project roots (e.g., directory containing .csproj)\n   */\n  setLspRootUri(language: string, uri: string): boolean;\n\n  /**\n   * Get all diagnostics from LSP\n   */\n  getAllDiagnostics(): JsDiagnostic[];\n\n  /**\n   * Get registered event handlers for an event\n   */\n  getHandlers(eventName: string): string[];\n\n  /**\n   * Create a virtual buffer in current split (async, returns buffer and split IDs)\n   */\n  createVirtualBuffer(opts: CreateVirtualBufferOptions): Promise<VirtualBufferResult>;\n\n  /**\n   * Create a virtual buffer in a new split (async, returns buffer and split IDs)\n   */\n  createVirtualBufferInSplit(opts: CreateVirtualBufferInSplitOptions): Promise<VirtualBufferResult>;\n\n  /**\n   * Create a virtual buffer in an existing split (async, returns buffer and split IDs)\n   */\n  createVirtualBufferInExistingSplit(opts: CreateVirtualBufferInExistingSplitOptions): Promise<VirtualBufferResult>;\n\n  /**\n   * Set virtual buffer content (takes array of entry objects)\n   * \n   * Note: entries should be TextPropertyEntry[] - uses manual parsing for HashMap support\n   */\n  setVirtualBufferContent(bufferId: number, entriesArr: Record<string, unknown>[]): boolean;\n\n  /**\n   * Get text properties at cursor position (returns JS array)\n   */\n  getTextPropertiesAtCursor(bufferId: number): TextPropertiesAtCursor;\n\n  /**\n   * Spawn a process (async, returns request_id)\n   */\n  spawnProcess(command: string, args: string[], cwd?: string): ProcessHandle<SpawnResult>;\n\n  /**\n   * Wait for a process to complete and get its result (async)\n   */\n  spawnProcessWait(processId: number): Promise<SpawnResult>;\n\n  /**\n   * Get buffer text range (async, returns request_id)\n   */\n  getBufferText(bufferId: number, start: number, end: number): Promise<string>;\n\n  /**\n   * Delay/sleep (async, returns request_id)\n   */\n  delay(durationMs: number): Promise<void>;\n\n  /**\n   * Send LSP request (async, returns request_id)\n   */\n  sendLspRequest(language: string, method: string, params: Record<string, unknown> | null): Promise<unknown>;\n\n  /**\n   * Spawn a background process (async, returns request_id which is also process_id)\n   */\n  spawnBackgroundProcess(command: string, args: string[], cwd?: string): ProcessHandle<BackgroundProcessResult>;\n\n  /**\n   * Kill a background process\n   */\n  killBackgroundProcess(processId: number): boolean;\n\n  /**\n   * Force refresh of line display\n   */\n  refreshLines(bufferId: number): boolean;\n\n  /**\n   * Get the current locale\n   */\n  getCurrentLocale(): string;\n\n  /**\n   * Load a plugin from a file path (async)\n   */\n  loadPlugin(path: string): Promise<boolean>;\n\n  /**\n   * Unload a plugin by name (async)\n   */\n  unloadPlugin(name: string): Promise<boolean>;\n\n  /**\n   * Reload a plugin by name (async)\n   */\n  reloadPlugin(name: string): Promise<boolean>;\n\n  /**\n   * List all loaded plugins (async)\n   * Returns array of { name: string, path: string, enabled: boolean }\n   */\n  listPlugins(): Promise<Array<{name: string, path: string, enabled: boolean}>>;\n}\n";
Expand description

TypeScript EditorAPI interface (methods only)

Combine with preamble and ts-rs types to create fresh.d.ts