Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TwIStOy committed Nov 29, 2023
1 parent ee89fca commit 722768d
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/conf/plugins/edit/conform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ const spec: PluginOpts<[]> = {
opts: {
formatters: formatters_opts,
formatters_by_ft: formatters_by_ft,
format_on_save: {
format_after_save: {
lsp_fallback: true,
timeout_ms: 500,
},
// format_on_save: {
// lsp_fallback: false,
// timeout_ms: 500,
// },
},
event: "BufReadPost",
config: true,
Expand Down
13 changes: 13 additions & 0 deletions src/core/snippets/snippet.ts
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, "");
}
120 changes: 120 additions & 0 deletions src/types/plugin/luasnip/luasnip.d.ts
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;
};
}
}
72 changes: 72 additions & 0 deletions src/types/plugin/luasnip/nodes.d.ts
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 {}
}

0 comments on commit 722768d

Please sign in to comment.