From f8e968c037e9b37e76a637ce1de42da3c2a604ee Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Thu, 15 Feb 2024 18:53:20 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20option=20to=20configure=20how=20con?= =?UTF-8?q?text=20provider=20is=20displayed=20inline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/context/providers/CodebaseContextProvider.ts | 1 + core/context/providers/CustomContextProvider.ts | 1 + core/index.d.ts | 2 ++ gui/src/components/mainInput/MentionExtension.ts | 14 ++++++++++++++ gui/src/components/mainInput/getSuggestion.ts | 1 + gui/src/components/mainInput/resolveInput.ts | 9 +++++---- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/core/context/providers/CodebaseContextProvider.ts b/core/context/providers/CodebaseContextProvider.ts index c79d8cc60..bca80c9c0 100644 --- a/core/context/providers/CodebaseContextProvider.ts +++ b/core/context/providers/CodebaseContextProvider.ts @@ -12,6 +12,7 @@ class CodebaseContextProvider extends BaseContextProvider { displayTitle: "Codebase", description: "Automatically find relevant files", type: "normal", + renderInlineAs: "", }; async getContextItems( diff --git a/core/context/providers/CustomContextProvider.ts b/core/context/providers/CustomContextProvider.ts index b6bf91d30..5d5ababb2 100644 --- a/core/context/providers/CustomContextProvider.ts +++ b/core/context/providers/CustomContextProvider.ts @@ -19,6 +19,7 @@ class CustomContextProviderClass implements IContextProvider { displayTitle: this.custom.displayTitle || this.custom.title, description: this.custom.description || "", type: this.custom.type || "normal", + renderInlineAs: this.custom.renderInlineAs, }; } diff --git a/core/index.d.ts b/core/index.d.ts index ea85bac36..ad01aedfe 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -97,6 +97,7 @@ export interface ContextProviderDescription { title: string; displayTitle: string; description: string; + renderInlineAs?: string; type: ContextProviderType; } @@ -116,6 +117,7 @@ export interface CustomContextProvider { title: string; displayTitle?: string; description?: string; + renderInlineAs?: string; type?: ContextProviderType; getContextItems( query: string, diff --git a/gui/src/components/mainInput/MentionExtension.ts b/gui/src/components/mainInput/MentionExtension.ts index 4de688508..7fd2470f2 100644 --- a/gui/src/components/mainInput/MentionExtension.ts +++ b/gui/src/components/mainInput/MentionExtension.ts @@ -106,6 +106,20 @@ export const Mention = Node.create({ }, }, + renderInlineAs: { + default: null, + parseHTML: (element) => element.getAttribute("data-renderInlineAs"), + renderHTML: (attributes) => { + if (!attributes.renderInlineAs) { + return {}; + } + + return { + "data-renderInlineAs": attributes.renderInlineAs, + }; + }, + }, + query: { default: null, parseHTML: (element) => element.getAttribute("data-query"), diff --git a/gui/src/components/mainInput/getSuggestion.ts b/gui/src/components/mainInput/getSuggestion.ts index 63bbff313..cb70c8830 100644 --- a/gui/src/components/mainInput/getSuggestion.ts +++ b/gui/src/components/mainInput/getSuggestion.ts @@ -118,6 +118,7 @@ export function getMentionSuggestion( id: provider.title, title: provider.displayTitle, label: provider.displayTitle, + renderInlineAs: provider.renderInlineAs, type: "contextProvider" as ComboBoxItemType, contextProvider: provider, })) diff --git a/gui/src/components/mainInput/resolveInput.ts b/gui/src/components/mainInput/resolveInput.ts index d9ee02ea2..8f4288cd0 100644 --- a/gui/src/components/mainInput/resolveInput.ts +++ b/gui/src/components/mainInput/resolveInput.ts @@ -151,11 +151,12 @@ function resolveParagraph(p: JSONContent): [string, MentionAttrs[], string] { let slashCommand = undefined; for (const child of p.content || []) { if (child.type === "text") { - text += child.text; + text += text === "" ? child.text.trimStart() : child.text; } else if (child.type === "mention") { - if (!["codebase"].includes(child.attrs.id)) { - text += child.attrs.label; - } + text += + typeof child.attrs.renderInlineAs === "string" + ? child.attrs.renderInlineAs + : child.attrs.label; contextItems.push(child.attrs); } else if (child.type === "slashcommand") { if (typeof slashCommand === "undefined") {