Skip to content

Commit

Permalink
Fix bugs with reference nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
blindmansion committed Sep 9, 2024
1 parent 1bfa554 commit 00950b3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 73 deletions.
2 changes: 1 addition & 1 deletion packages/cannoli-core/src/fileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface FileManager {
path: string,
content?: string,
verbose?: boolean
): Promise<boolean>;
): Promise<string>;

getNotePath(noteName: string): Promise<string | null>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class ReferenceNode extends ContentNode {
(this.reference.type === ReferenceType.Variable &&
this.reference.shouldExtract)
) {
await this.processDynamicReference("");
await this.processDynamicReference(null);

const fetchedContent = await this.getContent();
await this.loadOutgoingEdges(fetchedContent);
Expand Down Expand Up @@ -208,12 +208,12 @@ export class ReferenceNode extends ContentNode {
return `Could not find reference.`;
}

async processDynamicReference(content: string) {
async processDynamicReference(content: string | null) {
if (this.run.isMock) {
return;
}

const incomingEdges = this.getIncomingEdges();
const incomingEdges = this.getAllAvailableProvideEdges();

// Find the incoming edge with the same name as the reference name
const referenceNameEdge = incomingEdges.find(
Expand Down Expand Up @@ -303,7 +303,7 @@ export class ReferenceNode extends ContentNode {
noteName = await this.run.fileManager.createNoteAtExistingPath(
referenceNameEdge.content,
path,
content
content ?? ""
);
} catch (e) {
this.error(`Could not create note: ${e.message}`);
Expand Down Expand Up @@ -520,6 +520,12 @@ export class ReferenceNode extends ContentNode {
}
} else if (edgeObject.edgeModifier === EdgeModifier.Note) {
// Load the edge with the name of the note

// Add double brackets if the reference name is not already in double brackets
if (!this.reference.name.startsWith("[[") && !this.reference.name.endsWith("]]")) {
this.reference.name = `[[${this.reference.name}]]`;
}

edgeObject.load({
content: `${this.reference.name}`,
request: request,
Expand Down
Loading

0 comments on commit 00950b3

Please sign in to comment.