Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: inline autocompletion #5084

Merged
merged 6 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions ace.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,71 @@ export namespace Ace {
prefix: string,
callback: CompleterCallback): void;
}

export class AceInline {
show(editor: Editor, completion: Completion, prefix: string): void;
isOpen(): void;
hide(): void;
destroy(): void;
}

interface CompletionOptions {
matches?: Completion[];
}

type CompletionProviderOptions = {
exactMatch?: boolean;
ignoreCaption?: boolean;
}

type CompletionRecord = {
all: Completion[];
filtered: Completion[];
filterText: string;
} | CompletionProviderOptions

type GatherCompletionRecord = {
prefix: string;
matches: Completion[];
finished: boolean;
}

type CompletionCallbackFunction = (err: Error | undefined, data: GatherCompletionRecord) => void;
type CompletionProviderCallback = (err: Error | undefined, completions: CompletionRecord, finished: boolean) => void;

export class CompletionProvider {
insertByIndex(editor: Editor, index: number, options: CompletionProviderOptions): boolean;
insertMatch(editor: Editor, data: Completion, options: CompletionProviderOptions): boolean;
completions: CompletionRecord;
gatherCompletions(editor: Editor, callback: CompletionCallbackFunction): boolean;
provideCompletions(editor: Editor, options: CompletionProviderOptions, callback: CompletionProviderCallback): void;
detach(): void;
}

export class Autocomplete {
constructor();
autoInsert?: boolean;
autoSelect?: boolean;
exactMatch?: boolean;
inlineEnabled?: boolean;
getPopup(): AcePopup;
showPopup(editor: Editor, options: CompletionOptions): void;
detach(): void;
destroy(): void;
}

type AcePopupNavigation = "up" | "down" | "start" | "end";

export class AcePopup {
constructor(parentNode: HTMLElement);
setData(list: Completion[], filterText: string): void;
getData(row: number): Completion;
getRow(): number;
getRow(line: number): void;
hide(): void;
show(pos: Point, lineHeight: number, topdownOnly: boolean): void;
goTo(where: AcePopupNavigation): void;
}
}


Expand All @@ -944,3 +1009,43 @@ export const Range: {
fromPoints(start: Ace.Point, end: Ace.Point): Ace.Range;
comparePoints(p1: Ace.Point, p2: Ace.Point): number;
};


type InlineAutocompleteAction = "prev" | "next" | "first" | "last";

type TooltipCommandEnabledFunction = (editor: Ace.Editor) => boolean;

interface TooltipCommand extends Ace.Command {
enabled: TooltipCommandEnabledFunction | boolean,
position?: number;
}

export class InlineAutocomplete {
constructor();
getInlineRenderer(): Ace.AceInline;
getInlineTooltip(): InlineTooltip;
getCompletionProvider(): Ace.CompletionProvider;
show(editor: Ace.Editor): void;
isOpen(): boolean;
detach(): void;
destroy(): void;
goTo(action: InlineAutocompleteAction): void;
tooltipEnabled: boolean;
commands: Record<string, TooltipCommand>
getIndex(): number;
setIndex(value: number): void;
getLength(): number;
getData(index?: number): Ace.Completion | undefined;
updateCompletions(options: Ace.CompletionOptions): void;
}

export class InlineTooltip {
constructor(parentElement: HTMLElement);
setCommands(commands: Record<string, TooltipCommand>): void;
show(editor: Ace.Editor): void;
updatePosition(): void;
updateButtons(force?: boolean): void;
isShown(): boolean;
detach(): void;
destroy(): void;
}
48 changes: 48 additions & 0 deletions demo/inline_autocompletion.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ACE Inline Autocompletion demo</title>
<style type="text/css" media="screen">
body {
overflow: hidden;
}

#editor {
margin: 0;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>

<pre id="editor"></pre>

<script src="kitchen-sink/require.js"></script>
<script>
// setup paths
require.config({paths: { "ace" : "../src"}});
// load ace and extensions
require(["ace/ace", "ace/mode/javascript", "ace/ext/language_tools", "ace/ext/inline_autocomplete"], function(ace, codeLens) {
var editor = ace.edit("editor");
editor.session.setMode("ace/mode/javascript");
editor.setTheme("ace/theme/tomorrow");
// enable inline autocompletion
editor.setOptions({
enableBasicAutocompletion: false,
enableInlineAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: false
});

window.editor = editor;
});
</script>

<script src="./show_own_source.js"></script>
</body>
</html>
Loading