WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 7e53851

Browse files
authored
improve typings and add module documentation for extensions (#5827)
1 parent eb75438 commit 7e53851

30 files changed

+751
-89
lines changed

ace-internal.d.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,13 @@ export namespace Ace {
8888
}
8989

9090
interface HardWrapOptions {
91+
/** First row of the range to process */
9192
startRow: number;
93+
/** Last row of the range to process */
9294
endRow: number;
95+
/** Whether to merge short adjacent lines that fit within the limit */
9396
allowMerge?: boolean;
97+
/** Maximum column width for line wrapping (defaults to editor's print margin) */
9498
column?: number;
9599
}
96100

@@ -971,24 +975,34 @@ export namespace Ace {
971975
type CompleterCallback = (error: any, completions: Completion[]) => void;
972976

973977
interface Completer {
978+
/** Regular expressions defining valid identifier characters for completion triggers */
974979
identifierRegexps?: Array<RegExp>,
975980

981+
/** Main completion method that provides suggestions for the given context */
976982
getCompletions(editor: Editor,
977983
session: EditSession,
978984
position: Point,
979985
prefix: string,
980986
callback: CompleterCallback): void;
981987

988+
/** Returns documentation tooltip for a completion item */
982989
getDocTooltip?(item: Completion): void | string | Completion;
983990

991+
/** Called when a completion item becomes visible */
984992
onSeen?: (editor: Ace.Editor, completion: Completion) => void;
993+
/** Called when a completion item is inserted */
985994
onInsert?: (editor: Ace.Editor, completion: Completion) => void;
986995

996+
/** Cleanup method called when completion is cancelled */
987997
cancel?(): void;
988998

999+
/** Unique identifier for this completer */
9891000
id?: string;
1001+
/** Characters that trigger autocompletion when typed */
9901002
triggerCharacters?: string[];
1003+
/** Whether to hide inline preview text */
9911004
hideInlinePreview?: boolean;
1005+
/** Custom insertion handler for completion items */
9921006
insertMatch?: (editor: Editor, data: Completion) => void;
9931007
}
9941008

@@ -1252,10 +1266,15 @@ export namespace Ace {
12521266
}>>
12531267

12541268
export interface StaticHighlightOptions {
1269+
/** Syntax mode (e.g., 'ace/mode/javascript'). Auto-detected from CSS class if not provided */
12551270
mode?: string | SyntaxMode,
1271+
/** Color theme (e.g., 'ace/theme/textmate'). Defaults to 'ace/theme/textmate' */
12561272
theme?: string | Theme,
1273+
/** Whether to trim whitespace from code content */
12571274
trim?: boolean,
1275+
/** Starting line number for display */
12581276
firstLineNumber?: number,
1277+
/** Whether to show line numbers gutter */
12591278
showGutter?: boolean
12601279
}
12611280

@@ -1294,6 +1313,28 @@ export namespace Ace {
12941313
setLabel?: boolean;
12951314
inline?: boolean;
12961315
}
1316+
1317+
export interface TextAreaOptions {
1318+
/** Programming language mode for syntax highlighting (e.g., "javascript", "html", "css") */
1319+
mode?: string;
1320+
/** Visual theme for the editor appearance (e.g., "textmate", "monokai", "eclipse") */
1321+
theme?: string;
1322+
/** Line wrapping behavior - "off", "free", or specific column number like "40", "80" */
1323+
wrap?: string | number;
1324+
/** Font size in CSS units (e.g., "12px", "14px", "16px") */
1325+
fontSize?: string;
1326+
/** Whether to display the line number gutter on the left side */
1327+
showGutter?: boolean | string;
1328+
/** Keyboard handler/bindings to use - "ace", "vim", or "emacs" */
1329+
keybindings?: string;
1330+
/** Whether to show the print margin indicator line */
1331+
showPrintMargin?: boolean | string;
1332+
/** Whether to use soft tabs (spaces) instead of hard tabs */
1333+
useSoftTabs?: boolean | string;
1334+
/** Whether to show invisible characters like spaces and tabs */
1335+
showInvisibles?: boolean | string;
1336+
}
1337+
12971338
}
12981339

12991340

ace.d.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,13 @@ declare module "ace-code" {
8686
gutterOffset: number;
8787
}
8888
interface HardWrapOptions {
89+
/** First row of the range to process */
8990
startRow: number;
91+
/** Last row of the range to process */
9092
endRow: number;
93+
/** Whether to merge short adjacent lines that fit within the limit */
9194
allowMerge?: boolean;
95+
/** Maximum column width for line wrapping (defaults to editor's print margin) */
9296
column?: number;
9397
}
9498
interface CommandBarOptions {
@@ -778,15 +782,25 @@ declare module "ace-code" {
778782
};
779783
type CompleterCallback = (error: any, completions: Completion[]) => void;
780784
interface Completer {
785+
/** Regular expressions defining valid identifier characters for completion triggers */
781786
identifierRegexps?: Array<RegExp>;
787+
/** Main completion method that provides suggestions for the given context */
782788
getCompletions(editor: Editor, session: EditSession, position: Point, prefix: string, callback: CompleterCallback): void;
789+
/** Returns documentation tooltip for a completion item */
783790
getDocTooltip?(item: Completion): void | string | Completion;
791+
/** Called when a completion item becomes visible */
784792
onSeen?: (editor: Ace.Editor, completion: Completion) => void;
793+
/** Called when a completion item is inserted */
785794
onInsert?: (editor: Ace.Editor, completion: Completion) => void;
795+
/** Cleanup method called when completion is cancelled */
786796
cancel?(): void;
797+
/** Unique identifier for this completer */
787798
id?: string;
799+
/** Characters that trigger autocompletion when typed */
788800
triggerCharacters?: string[];
801+
/** Whether to hide inline preview text */
789802
hideInlinePreview?: boolean;
803+
/** Custom insertion handler for completion items */
790804
insertMatch?: (editor: Editor, data: Completion) => void;
791805
}
792806
interface CompletionOptions {
@@ -985,10 +999,15 @@ declare module "ace-code" {
985999
value: string;
9861000
}>>;
9871001
export interface StaticHighlightOptions {
1002+
/** Syntax mode (e.g., 'ace/mode/javascript'). Auto-detected from CSS class if not provided */
9881003
mode?: string | SyntaxMode;
1004+
/** Color theme (e.g., 'ace/theme/textmate'). Defaults to 'ace/theme/textmate' */
9891005
theme?: string | Theme;
1006+
/** Whether to trim whitespace from code content */
9901007
trim?: boolean;
1008+
/** Starting line number for display */
9911009
firstLineNumber?: number;
1010+
/** Whether to show line numbers gutter */
9921011
showGutter?: boolean;
9931012
}
9941013
export interface Operation {
@@ -1031,6 +1050,26 @@ declare module "ace-code" {
10311050
setLabel?: boolean;
10321051
inline?: boolean;
10331052
}
1053+
export interface TextAreaOptions {
1054+
/** Programming language mode for syntax highlighting (e.g., "javascript", "html", "css") */
1055+
mode?: string;
1056+
/** Visual theme for the editor appearance (e.g., "textmate", "monokai", "eclipse") */
1057+
theme?: string;
1058+
/** Line wrapping behavior - "off", "free", or specific column number like "40", "80" */
1059+
wrap?: string | number;
1060+
/** Font size in CSS units (e.g., "12px", "14px", "16px") */
1061+
fontSize?: string;
1062+
/** Whether to display the line number gutter on the left side */
1063+
showGutter?: boolean | string;
1064+
/** Keyboard handler/bindings to use - "ace", "vim", or "emacs" */
1065+
keybindings?: string;
1066+
/** Whether to show the print margin indicator line */
1067+
showPrintMargin?: boolean | string;
1068+
/** Whether to use soft tabs (spaces) instead of hard tabs */
1069+
useSoftTabs?: boolean | string;
1070+
/** Whether to show invisible characters like spaces and tabs */
1071+
showInvisibles?: boolean | string;
1072+
}
10341073
}
10351074
export const config: typeof import("ace-code/src/config");
10361075
export function edit(el?: string | (HTMLElement & {

src/ext/beautify.js

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,61 @@
1-
// [WIP]
1+
/**
2+
* ## Code beautification and formatting extension.
3+
*
4+
* **This extension is considered outdated.** For better formatting support with modern language servers
5+
* and advanced formatting capabilities, consider using [ace-linters](https://github.com/mkslanc/ace-linters)
6+
* which provides comprehensive language support including formatting, linting, and IntelliSense features.
7+
*
8+
* This legacy extension provides basic formatting for HTML, CSS, JavaScript, and PHP code with support for
9+
* proper indentation, whitespace management, line breaks, and bracket alignment. It handles various language
10+
* constructs including HTML tags, CSS selectors, JavaScript operators, control structures, and maintains
11+
* consistent code style throughout the document.
12+
*
13+
* @module
14+
*/
15+
216

317
"use strict";
18+
419
var TokenIterator = require("../token_iterator").TokenIterator;
520

621
function is(token, type) {
722
return token.type.lastIndexOf(type + ".xml") > -1;
823
}
924

10-
// do not indent after singleton tags or <html>
25+
/**
26+
* List of HTML singleton (self-closing) tags that do not require additional indentation.
27+
* These tags are typically void elements that cannot have child content and are closed within themselves.
28+
*
29+
* @type {string[]}
30+
* @exports
31+
*/
1132
exports.singletonTags = ["area", "base", "br", "col", "command", "embed", "hr", "html", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
1233

13-
// insert a line break after block level tags
34+
/**
35+
* List of HTML block-level tags that typically require line breaks after their opening and closing tags.
36+
* These tags represent structural elements that usually contain other content and are rendered as block-level elements.
37+
*
38+
* @type {string[]}
39+
*/
1440
exports.blockTags = ["article", "aside", "blockquote", "body", "div", "dl", "fieldset", "footer", "form", "head", "header", "html", "nav", "ol", "p", "script", "section", "style", "table", "tbody", "tfoot", "thead", "ul"];
1541

1642
/**
17-
*
43+
* Configuration options for code formatting behavior.
44+
* Controls various formatting rules such as line break placement and spacing preferences.
45+
*
1846
* @type {{lineBreaksAfterCommasInCurlyBlock?: boolean}}
1947
*/
2048
exports.formatOptions = {
2149
lineBreaksAfterCommasInCurlyBlock: true
2250
};
2351

2452
/**
25-
*
26-
* @param {import("../edit_session").EditSession} session
53+
* Formats and beautifies code in the editor session with intelligent indentation, whitespace management, and bracket alignment.
54+
* Supports HTML, CSS, JavaScript, and PHP with configurable formatting options and language-specific rules.
55+
*
56+
* @param {import("../edit_session").EditSession} session - The editor session containing the code to format
2757
*/
58+
2859
exports.beautify = function(session) {
2960
var iterator = new TokenIterator(session, 0, 0);
3061
var token = iterator.getCurrentToken();
@@ -398,6 +429,12 @@ exports.beautify = function(session) {
398429
session.doc.setValue(code);
399430
};
400431

432+
/**
433+
* Array of command definitions for the beautify extension.
434+
* Contains the main beautify command with keyboard shortcut and execution handler.
435+
*
436+
* @type {import("../../ace-internal").Ace.Command[]}
437+
*/
401438
exports.commands = [{
402439
name: "beautify",
403440
description: "Format selection (Beautify)",

src/ext/code_lens.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/**
2+
* ## Code Lens extension.
3+
*
4+
* Displaying contextual information and clickable commands above code lines. Supports registering custom providers,
5+
* rendering lens widgets with proper positioning and styling, and handling user interactions with lens commands.
6+
* @module
7+
*/
8+
19
"use strict";
210
/**
311
* @typedef {import("../edit_session").EditSession} EditSession

src/ext/command_bar.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/**
2+
* ## Command Bar extension.
3+
*
4+
* Provides an interactive command bar tooltip that displays above the editor's active line. The extension enables
5+
* clickable commands with keyboard shortcuts, icons, and various button types including standard buttons, checkboxes,
6+
* and text elements. Supports overflow handling with a secondary tooltip for additional commands when space is limited.
7+
* The tooltip can be configured to always show or display only on mouse hover over the active line.
8+
*
9+
* @module
10+
*/
11+
112
/**
213
* @typedef {import("../editor").Editor} Editor
314
* @typedef {import("../../ace-internal").Ace.TooltipCommand} TooltipCommand

src/ext/elastic_tabstops_lite.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/**
2+
* ## Elastic Tabstops Lite extension.
3+
*
4+
* Automatically adjusts tab spacing to align content in tabular format by calculating optimal column widths
5+
* and maintaining consistent vertical alignment across multiple lines. Tracks content changes and dynamically
6+
* reprocesses affected rows to ensure proper formatting without manual intervention.
7+
*
8+
* **Enable:** `editor.setOption("useElasticTabstops", true)`
9+
* or configure it during editor initialization in the options object.
10+
* @module
11+
*/
12+
113
"use strict";
214
class ElasticTabstopsLite {
315
/**

src/ext/emmet.js

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* ## Emmet extension
3+
*
4+
* Providing HTML/CSS abbreviation expansion, code navigation, and text editing utilities with configurable options and
5+
* keyboard shortcuts for rapid web development workflow.
6+
*
7+
* **Enable:** `editor.setOption("enableEmmet", true)`
8+
* or configure it during editor initialization in the options object.
9+
* @module
10+
*/
111
"use strict";
212
var HashHandler = require("../keyboard/hash_handler").HashHandler;
313
var Editor = require("../editor").Editor;
@@ -322,9 +332,12 @@ var keymap = {
322332

323333
var editorProxy = new AceEmmetEditor();
324334
exports.commands = new HashHandler();
335+
325336
/**
326-
* @param {Editor} editor
327-
* @return {ReturnType<typeof setTimeout> | boolean}
337+
* Runs an Emmet command on the given editor.
338+
*
339+
* @param {Editor} editor - The Ace editor instance to run the Emmet command on
340+
* @return {ReturnType<typeof setTimeout> | boolean} The result of the Emmet command execution
328341
*/
329342
exports.runEmmetCommand = function runEmmetCommand(editor) {
330343
if (this.action == "expand_abbreviation_with_tab") {
@@ -372,8 +385,10 @@ for (var command in keymap) {
372385
}
373386

374387
/**
375-
* @param {Editor} editor
376-
* @param {boolean} [enabled]
388+
* Updates the keyboard handler for Emmet commands in the editor.
389+
*
390+
* @param {Editor} editor - The Ace editor instance
391+
* @param {boolean} [enabled] - Whether Emmet commands should be enabled
377392
*/
378393
exports.updateCommands = function(editor, enabled) {
379394
if (enabled) {
@@ -383,6 +398,12 @@ exports.updateCommands = function(editor, enabled) {
383398
}
384399
};
385400

401+
/**
402+
* Determines if a given editor mode is supported by Emmet.
403+
*
404+
* @param {Object|string} mode - The editor mode to check for Emmet support
405+
* @returns {boolean} Whether the mode is supported by Emmet
406+
*/
386407
exports.isSupportedMode = function(mode) {
387408
if (!mode) return false;
388409
if (mode.emmetConfig) return true;
@@ -391,9 +412,11 @@ exports.isSupportedMode = function(mode) {
391412
};
392413

393414
/**
394-
* @param {Editor} editor
395-
* @param {string} command
396-
* @return {boolean}
415+
* Checks if an Emmet command is available for the current editor context.
416+
*
417+
* @param {Editor} editor - The current Ace editor instance
418+
* @param {string} command - The Emmet command to check availability for
419+
* @return {boolean} Whether the command is available in the current editor mode
397420
*/
398421
exports.isAvailable = function(editor, command) {
399422
if (/(evaluate_math_expression|expand_abbreviation)$/.test(command))
@@ -423,6 +446,12 @@ var onChangeMode = function(e, target) {
423446
exports.updateCommands(editor, enabled);
424447
};
425448

449+
/**
450+
* Loads the Emmet core module dynamically.
451+
*
452+
* @param {Function} [cb] - Optional callback function to be executed after module loading
453+
* @return {boolean} Whether the Emmet core module loading was initiated successfully
454+
*/
426455
exports.load = function(cb) {
427456
if (typeof emmetPath !== "string") {
428457
config.warn("script for emmet-core is not loaded");
@@ -446,6 +475,13 @@ config.defineOptions(Editor.prototype, "editor", {
446475
}
447476
});
448477

478+
/**
479+
* Sets the Emmet core module or path.
480+
*
481+
* @param {string|Object} e - Either the path to the Emmet core script or the Emmet core module itself
482+
* If a string is provided, it sets the path to load the Emmet core script.
483+
* If an object is provided, it directly sets the Emmet core module.
484+
*/
449485
exports.setCore = function(e) {
450486
if (typeof e == "string")
451487
emmetPath = e;

0 commit comments

Comments
 (0)