From 722768d40f1cebca4531730b5ff0a49624d0ea81 Mon Sep 17 00:00:00 2001 From: Hawtian Wang Date: Wed, 29 Nov 2023 16:34:05 +0800 Subject: [PATCH] fix --- src/conf/plugins/edit/conform.ts | 7 +- src/core/snippets/snippet.ts | 13 +++ src/types/plugin/luasnip/luasnip.d.ts | 120 ++++++++++++++++++++++++++ src/types/plugin/luasnip/nodes.d.ts | 72 ++++++++++++++++ 4 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 src/core/snippets/snippet.ts create mode 100644 src/types/plugin/luasnip/luasnip.d.ts create mode 100644 src/types/plugin/luasnip/nodes.d.ts diff --git a/src/conf/plugins/edit/conform.ts b/src/conf/plugins/edit/conform.ts index 7cd8bca1..34e7b954 100644 --- a/src/conf/plugins/edit/conform.ts +++ b/src/conf/plugins/edit/conform.ts @@ -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, diff --git a/src/core/snippets/snippet.ts b/src/core/snippets/snippet.ts new file mode 100644 index 00000000..2d1fc05d --- /dev/null +++ b/src/core/snippets/snippet.ts @@ -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, ""); +} diff --git a/src/types/plugin/luasnip/luasnip.d.ts b/src/types/plugin/luasnip/luasnip.d.ts new file mode 100644 index 00000000..66233346 --- /dev/null +++ b/src/types/plugin/luasnip/luasnip.d.ts @@ -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; + }; + } +} diff --git a/src/types/plugin/luasnip/nodes.d.ts b/src/types/plugin/luasnip/nodes.d.ts new file mode 100644 index 00000000..18106db2 --- /dev/null +++ b/src/types/plugin/luasnip/nodes.d.ts @@ -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( + 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 {} +}