mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-29 21:51:59 +02:00
Split out slow pathParameters extension and skip unnecessary model updates
This commit is contained in:
@@ -2,12 +2,41 @@ import { useQuery } from '@tanstack/react-query';
|
||||
import type { GetTemplateFunctionsResponse, TemplateFunction } from '@yaakapp-internal/plugin';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { useState } from 'react';
|
||||
import { useMemo, useState } from 'react';
|
||||
import type {TwigCompletionOption} from "../components/core/Editor/twig/completion";
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { usePluginsKey } from './usePlugins';
|
||||
|
||||
const templateFunctionsAtom = atom<TemplateFunction[]>([]);
|
||||
|
||||
export function useTwigCompletionOptions(
|
||||
onClick: (fn: TemplateFunction, ragTag: string, pos: number) => void,
|
||||
) {
|
||||
const templateFunctions = useTemplateFunctions();
|
||||
return useMemo<TwigCompletionOption[]>(() => {
|
||||
return (
|
||||
templateFunctions.map((fn) => {
|
||||
const NUM_ARGS = 2;
|
||||
const shortArgs =
|
||||
fn.args
|
||||
.slice(0, NUM_ARGS)
|
||||
.map((a) => a.name)
|
||||
.join(', ') + (fn.args.length > NUM_ARGS ? ', …' : '');
|
||||
return {
|
||||
name: fn.name,
|
||||
aliases: fn.aliases,
|
||||
type: 'function',
|
||||
description: fn.description,
|
||||
args: fn.args.map((a) => ({ name: a.name })),
|
||||
value: null,
|
||||
label: `${fn.name}(${shortArgs})`,
|
||||
onClick: (rawTag: string, startPos: number) => onClick(fn, rawTag, startPos),
|
||||
};
|
||||
}) ?? []
|
||||
);
|
||||
}, [onClick, templateFunctions]);
|
||||
}
|
||||
|
||||
export function useTemplateFunctions() {
|
||||
return useAtomValue(templateFunctionsAtom);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user