This commit is contained in:
Adria Navarro 2025-02-11 12:51:13 +01:00
parent 62d19fd68c
commit 32683e240b
3 changed files with 15 additions and 11 deletions

View File

@ -89,7 +89,7 @@ export const buildSectionHeader = (
export const helpersToCompletion = ( export const helpersToCompletion = (
helpers: Record<string, Helper>, helpers: Record<string, Helper>,
mode: { name: "javascript" | "handlebars" } mode: { name: "javascript" | "handlebars" }
) => { ): BindingCompletionOption[] => {
const { type, name: sectionName, icon } = SECTIONS.HB_HELPER const { type, name: sectionName, icon } = SECTIONS.HB_HELPER
const helperSection = buildSectionHeader(type, sectionName, icon, 99) const helperSection = buildSectionHeader(type, sectionName, icon, 99)
@ -117,7 +117,7 @@ export const helpersToCompletion = (
export const getHelperCompletions = (mode: { export const getHelperCompletions = (mode: {
name: "javascript" | "handlebars" name: "javascript" | "handlebars"
}) => { }): BindingCompletionOption[] => {
// TODO: manifest needs to be properly typed // TODO: manifest needs to be properly typed
const manifest: any = getManifest() const manifest: any = getManifest()
return Object.keys(manifest).flatMap(key => { return Object.keys(manifest).flatMap(key => {
@ -161,19 +161,21 @@ export const snippetAutoComplete = (snippets: Snippet[]): BindingCompletion => {
const bindingFilter = (options: BindingCompletionOption[], query: string) => { const bindingFilter = (options: BindingCompletionOption[], query: string) => {
return options.filter(completion => { return options.filter(completion => {
const section_parsed = completion.section.name.toLowerCase() const section_parsed = completion.section?.name.toLowerCase()
const label_parsed = completion.label.toLowerCase() const label_parsed = completion.label.toLowerCase()
const query_parsed = query.toLowerCase() const query_parsed = query.toLowerCase()
return ( return (
section_parsed.includes(query_parsed) || section_parsed?.includes(query_parsed) ||
label_parsed.includes(query_parsed) label_parsed.includes(query_parsed)
) )
}) })
} }
export const hbAutocomplete = (baseCompletions: BindingCompletionOption[]) => { export const hbAutocomplete = (
async function coreCompletion(context: CompletionContext) { baseCompletions: BindingCompletionOption[]
): BindingCompletion => {
function coreCompletion(context: CompletionContext) {
let bindingStart = context.matchBefore(EditorModes.Handlebars.match) let bindingStart = context.matchBefore(EditorModes.Handlebars.match)
let options = baseCompletions || [] let options = baseCompletions || []
@ -202,7 +204,7 @@ export const hbAutocomplete = (baseCompletions: BindingCompletionOption[]) => {
export const jsAutocomplete = ( export const jsAutocomplete = (
baseCompletions: BindingCompletionOption[] baseCompletions: BindingCompletionOption[]
): BindingCompletion => { ): BindingCompletion => {
async function coreCompletion(context: CompletionContext) { function coreCompletion(context: CompletionContext) {
let jsBinding = context.matchBefore(/\$\("[\s\w]*/) let jsBinding = context.matchBefore(/\$\("[\s\w]*/)
let options = baseCompletions || [] let options = baseCompletions || []
@ -230,7 +232,7 @@ export const jsAutocomplete = (
export const jsHelperAutocomplete = ( export const jsHelperAutocomplete = (
baseCompletions: BindingCompletionOption[] baseCompletions: BindingCompletionOption[]
): BindingCompletion => { ): BindingCompletion => {
async function coreCompletion(context: CompletionContext) { function coreCompletion(context: CompletionContext) {
if (context.matchBefore(/\$\("[\s\w]*/)) { if (context.matchBefore(/\$\("[\s\w]*/)) {
// We are handing a js field completion // We are handing a js field completion
return null return null

View File

@ -1,7 +1,7 @@
import { BindingCompletionOption } from "@budibase/types" import { BindingCompletionOption } from "@budibase/types"
import { CompletionContext } from "@codemirror/autocomplete" import { CompletionContext } from "@codemirror/autocomplete"
export type BindingCompletion = (context: CompletionContext) => Promise<{ export type BindingCompletion = (context: CompletionContext) => {
from: number from: number
options: BindingCompletionOption[] options: BindingCompletionOption[]
} | null> } | null

View File

@ -1,9 +1,11 @@
export interface BindingCompletionOption { export interface BindingCompletionOption {
section: { section?: {
name: string name: string
} }
label: string label: string
text?: string
simple?: boolean simple?: boolean
apply?: any // TODO
} }
export interface EnrichedBinding { export interface EnrichedBinding {