-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
210 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ifNil } from "@core/vim"; | ||
|
||
export interface SnippetSpec { | ||
name?: string; | ||
dscr?: string; | ||
mode?: string; | ||
} | ||
|
||
export function buildSnippet(trig: string, opts: SnippetSpec) { | ||
let name = ifNil(opts.name, trig); | ||
let dscr = ifNil(opts.dscr, `Snippet: ${name}`); | ||
let mode = ifNil(opts.mode, ""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
declare namespace LuaSnip { | ||
export interface ExpandParams { | ||
/** | ||
* The fully matched trigger. | ||
*/ | ||
trigger?: string; | ||
/** | ||
* This list could update the capture-groups from parameter in snippet expansion. | ||
*/ | ||
captures?: LuaTable; | ||
/** | ||
* Both (0, 0)-indexed, the region where text has to be cleared before inserting the snippet. | ||
*/ | ||
clear_region?: { | ||
from: [number, number]; | ||
to: [number, number]; | ||
}; | ||
/** | ||
* Override or extend the snippet's environment | ||
*/ | ||
env_override?: { | ||
[key: string]: string | string[]; | ||
}; | ||
} | ||
|
||
export interface Snippet {} | ||
|
||
export interface SnippetContext { | ||
trig: string; | ||
name?: string; | ||
/// Same as `dscr`. | ||
desc?: string; | ||
/// Description of the snippet, \n-separated or table for multiple lines. | ||
dscr?: string; | ||
/// The snippet is only expanded if the word (`[%w_]+`) before the cursor | ||
/// matches the trigger entirely. True by default. | ||
wordTrig?: boolean; | ||
/** | ||
* Whether the trigger should be interpreted as a lua pattern. | ||
* False by default. | ||
* Consider setting trigEngine to "pattern" instead, it is more expressive, | ||
* and in line with other settings. | ||
*/ | ||
regTrig?: boolean; | ||
/// Determines how `trig` is interpreted. | ||
trigEngine?: | ||
| "plain" // The default-behaviour, the trigger has to match the text | ||
// before the cursor exactly. | ||
| "pattern" // The trigger is interpreted as a lua pattern. | ||
| "ecma" // The trigger is interpreted as a ECMAScript RegExp. | ||
| "vim" // The trigger is interpreted as a vim regex. | ||
| (( | ||
trig: string | ||
) => ( | ||
line_to_cursor: string, | ||
trigger: string | ||
) => LuaMultiReturn<[string, string[]]>); | ||
/** | ||
* Textual representation of the snippet, specified like desc. | ||
*/ | ||
docstring?: string; | ||
/** | ||
* Hint for completion engines. | ||
*/ | ||
hidden?: boolean; | ||
/** | ||
* Priority of the snippet, 1000 by default. | ||
*/ | ||
priority?: number; | ||
/** | ||
* Whether this snippet has to be triggered by ls.expand() or whether is | ||
* triggered automatically. | ||
*/ | ||
snippetType?: "snippet" | "autosnippet"; | ||
/** | ||
* This function will be evaluated in `Snippet:matches()` to decide | ||
* whether the snippet can be expanded or not. | ||
*/ | ||
resolveExpandParams?: ( | ||
/** | ||
* The expanding snippet. | ||
*/ | ||
snippet: Snippet, | ||
/** | ||
* The line up to cursor. | ||
*/ | ||
line_to_cursor: string, | ||
/** | ||
* The fully matched trigger. | ||
*/ | ||
matched_trigger: string, | ||
/** | ||
* `captures` as returned by the `trigEngine`. | ||
*/ | ||
captures: LuaTable | ||
) => LuaSnip.ExpandParams | null; | ||
/** | ||
* Whether the snippet can be expanded. | ||
*/ | ||
condition?: ( | ||
line_to_cursor: string, | ||
matched_trigger: string, | ||
captures: LuaTable | ||
) => boolean; | ||
shown_condition?: (line_to_cursor: string) => boolean; | ||
/** | ||
* A single node or a list of nodes. The nodes that make up the snippet. | ||
*/ | ||
nodes: Node | Node[]; | ||
opts?: { | ||
/** | ||
* Contains functions that are called upon entering/leaving a node of | ||
* this snippet. | ||
*/ | ||
callbacks?: LuaTable; | ||
child_ext_opts?: LuaTable; | ||
merge_child_ext_opts?: LuaTable; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
declare namespace LuaSnip { | ||
export interface NodeOpts { | ||
node_ext_opts?: LuaTable; | ||
parent_ext_opts?: LuaTable; | ||
key?: any; | ||
} | ||
|
||
export interface Node {} | ||
|
||
export interface TextNode extends Node {} | ||
|
||
export function t(text: string | string[], opts?: NodeOpts): TextNode; | ||
|
||
export interface InsertNode extends Node {} | ||
|
||
export function i( | ||
jump_index: number, | ||
text: string | string[], | ||
opts?: NodeOpts | ||
): InsertNode; | ||
|
||
export interface FunctionNode extends Node {} | ||
|
||
export function f<UA extends any[]>( | ||
fn: ( | ||
argnode_text: string[][], | ||
parent: Node, | ||
...args: UA | ||
) => string | string[], | ||
argnode_references: number[], | ||
opts?: NodeOpts & { | ||
user_args?: UA; | ||
} | ||
): FunctionNode; | ||
|
||
export interface ChoiceNode extends Node {} | ||
|
||
export function c( | ||
jump_index: number, | ||
choices: Node[] | Node, | ||
opts?: NodeOpts & { | ||
restore_cursor?: boolean; | ||
} | ||
): ChoiceNode; | ||
|
||
export interface SnippetNode extends Node {} | ||
|
||
export function sn( | ||
jump_index: number, | ||
nodes: Node[] | Node, | ||
opts?: NodeOpts & { | ||
callbacks?: LuaTable; | ||
child_ext_opts?: LuaTable; | ||
merge_child_ext_opts?: LuaTable; | ||
} | ||
): SnippetNode; | ||
|
||
export interface IndentSnippetNode extends Node {} | ||
|
||
export function isn( | ||
jump_index: number, | ||
nodes: Node[] | Node, | ||
indentstring: string, | ||
opts?: NodeOpts & { | ||
callbacks?: LuaTable; | ||
child_ext_opts?: LuaTable; | ||
merge_child_ext_opts?: LuaTable; | ||
} | ||
): IndentSnippetNode; | ||
|
||
export interface DynamicNode extends Node {} | ||
} |