✨ option to configure how context provider is displayed inline

This commit is contained in:
Nate Sesti 2024-02-15 18:53:20 -08:00
parent 7ad086a0fe
commit f8e968c037
6 changed files with 24 additions and 4 deletions

View file

@ -12,6 +12,7 @@ class CodebaseContextProvider extends BaseContextProvider {
displayTitle: "Codebase",
description: "Automatically find relevant files",
type: "normal",
renderInlineAs: "",
};
async getContextItems(

View file

@ -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,
};
}

2
core/index.d.ts vendored
View file

@ -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,

View file

@ -106,6 +106,20 @@ export const Mention = Node.create<MentionOptions>({
},
},
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"),

View file

@ -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,
}))

View file

@ -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") {