diff --git a/packages/plugin-core/src/WorkspaceWatcher.ts b/packages/plugin-core/src/WorkspaceWatcher.ts index 3542432ffe..1b2586cb0e 100644 --- a/packages/plugin-core/src/WorkspaceWatcher.ts +++ b/packages/plugin-core/src/WorkspaceWatcher.ts @@ -1,4 +1,4 @@ -import { NotePropsV2, NoteUtilsV2 } from "@dendronhq/common-all"; +import { DNodeUtilsV2, NotePropsV2, NoteUtilsV2 } from "@dendronhq/common-all"; import { HistoryService } from "@dendronhq/engine-server"; import _ from "lodash"; import moment from "moment"; @@ -45,12 +45,20 @@ export class WorkspaceWatcher { const eclient = DendronWorkspace.instance().getEngine(); const fname = path.basename(uri.fsPath, ".md"); const now = moment.now(); + const vault = DNodeUtilsV2.getVaultByDir({ + dirPath: path.dirname(uri.fsPath), + vaults: eclient.vaultsv3, + }); + const note = NoteUtilsV2.getNoteByFnameV4({ + fname, + vault, + notes: eclient.notes, + }) as NotePropsV2; // if recently changed, ignore const recentEvents = HistoryService.instance().lookBack(); if (recentEvents[0].uri?.fsPath === uri.fsPath) { - let lastUpdated: string | number = - NoteUtilsV2.getNoteByFname(fname, eclient.notes)?.updated || now; + let lastUpdated: string | number = note?.updated || now; if (_.isString(lastUpdated)) { lastUpdated = _.parseInt(lastUpdated); } @@ -71,9 +79,6 @@ export class WorkspaceWatcher { const startPos = ev.document.positionAt(match.index); const endPos = ev.document.positionAt(match.index + match[0].length); const p = new Promise(async (resolve) => { - const note = NoteUtilsV2.getNoteByFname(fname, eclient.notes, { - throwIfEmpty: true, - }) as NotePropsV2; note.updated = now.toString(); await eclient.updateNote(note); resolve([ diff --git a/packages/plugin-core/src/commands/CopyNoteLink.ts b/packages/plugin-core/src/commands/CopyNoteLink.ts index 89ffa1ea97..444d24165d 100644 --- a/packages/plugin-core/src/commands/CopyNoteLink.ts +++ b/packages/plugin-core/src/commands/CopyNoteLink.ts @@ -2,10 +2,11 @@ import clipboardy from "@dendronhq/clipboardy"; import { NotePropsV2, NoteUtilsV2 } from "@dendronhq/common-all"; import _ from "lodash"; import { TextEditor, window } from "vscode"; +import { PickerUtilsV2 } from "../components/lookup/utils"; import { DENDRON_COMMANDS } from "../constants"; import { VSCodeUtils } from "../utils"; import { getHeaderFromSelection } from "../utils/editor"; -import { DendronWorkspace } from "../workspace"; +import { getEngine } from "../workspace"; import { BasicCommand } from "./base"; type CommandOpts = {}; @@ -31,10 +32,13 @@ export class CopyNoteLinkCommand extends BasicCommand< const editor = VSCodeUtils.getActiveTextEditor() as TextEditor; const fname = NoteUtilsV2.uri2Fname(editor.document.uri); let note: NotePropsV2; - note = NoteUtilsV2.getNoteByFname( + + const vault = PickerUtilsV2.getOrPromptVaultForOpenEditor(); + note = NoteUtilsV2.getNoteByFnameV4({ fname, - DendronWorkspace.instance().getEngine().notes - ) as NotePropsV2; + vault, + notes: getEngine().notes, + }) as NotePropsV2; if (!note) { throw Error(`${fname} not found in engine`); } diff --git a/packages/plugin-core/src/commands/DeleteNodeCommand.ts b/packages/plugin-core/src/commands/DeleteNodeCommand.ts index c30cee14ca..0ae13fc23a 100644 --- a/packages/plugin-core/src/commands/DeleteNodeCommand.ts +++ b/packages/plugin-core/src/commands/DeleteNodeCommand.ts @@ -5,7 +5,7 @@ import { window } from "vscode"; import { PickerUtilsV2 } from "../components/lookup/utils"; import { DENDRON_COMMANDS } from "../constants"; import { DendronClientUtilsV2, VSCodeUtils } from "../utils"; -import { DendronWorkspace } from "../workspace"; +import { DendronWorkspace, getEngine } from "../workspace"; import { BasicCommand } from "./base"; type CommandOpts = {}; @@ -32,11 +32,12 @@ export class DeleteNodeCommand extends BasicCommand< const trimEnd = mode === "note" ? ".md" : ".schema.yml"; const fname = path.basename(fsPath, trimEnd); const client = DendronWorkspace.instance().getEngine(); - const vault = PickerUtilsV2.getVaultForOpenEditor(); if (mode === "note") { - const note = NoteUtilsV2.getNoteByFname(fname, client.notes, { - throwIfEmpty: true, + const vault = PickerUtilsV2.getOrPromptVaultForOpenEditor(); + const note = NoteUtilsV2.getNoteByFnameV4({ + fname, vault, + notes: getEngine().notes, }) as NotePropsV2; return (await client.deleteNote(note.id)) as EngineDeletePayload; } else { diff --git a/packages/plugin-core/src/commands/GoToSiblingCommand.ts b/packages/plugin-core/src/commands/GoToSiblingCommand.ts index a53186335e..7791ed6e67 100644 --- a/packages/plugin-core/src/commands/GoToSiblingCommand.ts +++ b/packages/plugin-core/src/commands/GoToSiblingCommand.ts @@ -47,9 +47,11 @@ export class GoToSiblingCommand extends BasicCommand< vaults: client.vaultsv3 as DVault[], dirPath: path.dirname(maybeTextEditor.document.uri.fsPath), }); - const rootNode = NoteUtilsV2.getNoteByFname(value, client.notes, { + const rootNode = NoteUtilsV2.getNoteByFnameV4({ + fname: value, vault, - }); + notes: client.notes, + }) as NotePropsV2; if (_.isUndefined(rootNode)) { throw new DendronError({ msg: "no root node found" }); } diff --git a/packages/plugin-core/src/components/lookup/LookupProviderV2.ts b/packages/plugin-core/src/components/lookup/LookupProviderV2.ts index 8bd1f59c31..f90cbcc884 100644 --- a/packages/plugin-core/src/components/lookup/LookupProviderV2.ts +++ b/packages/plugin-core/src/components/lookup/LookupProviderV2.ts @@ -17,7 +17,7 @@ import { CancellationToken, Uri, window } from "vscode"; import { Logger } from "../../logger"; import { EngineFlavor, EngineOpts } from "../../types"; import { getDurationMilliseconds, profile } from "../../utils/system"; -import { DendronWorkspace, getWS } from "../../workspace"; +import { DendronWorkspace, getEngine, getWS } from "../../workspace"; import { MORE_RESULTS_LABEL } from "./constants"; import { LookupControllerV2 } from "./LookupControllerV2"; import { DendronQuickPickerV2 } from "./types"; @@ -123,7 +123,12 @@ export class LookupProviderV2 { Logger.info({ ctx, msg: "pre:checkNoteExist", uri }); // TODO: check for overwriting schema - let noteExists = NoteUtilsV2.getNoteByFname(nodeNew.fname, engine.notes); + const vault = PickerUtilsV2.getOrPromptVaultForOpenEditor(); + const noteExists = NoteUtilsV2.getNoteByFnameV4({ + fname: nodeNew.fname, + vault, + notes: engine.notes, + }) as NotePropsV2; if ( noteExists && !foundStub && @@ -222,7 +227,6 @@ export class LookupProviderV2 { activeItems: picker.activeItems.map((ent) => NoteUtilsV2.toLogObj(ent)), }); const resp = this.validate(picker.value, opts.flavor); - const ws = DendronWorkspace.instance(); let uri: Uri; let newNode: NotePropsV2 | SchemaModulePropsV2 | undefined; if (resp) { @@ -259,10 +263,12 @@ export class LookupProviderV2 { // item from pressing enter if (opts.flavor === "note") { try { - const maybeNote = NoteUtilsV2.getNoteByFname( - value, - ws.getEngine().notes - ); + const vault = PickerUtilsV2.getOrPromptVaultForOpenEditor(); + const maybeNote = NoteUtilsV2.getNoteByFnameV4({ + fname: value, + vault, + notes: getEngine().notes, + }); if (maybeNote) { uri = node2Uri(maybeNote); await showDocAndHidePicker([uri], picker); @@ -286,7 +292,6 @@ export class LookupProviderV2 { Logger.info({ ctx, msg: "enter", value, opts }); let selectedItems = PickerUtilsV2.getSelection(picker); const resp = this.validate(picker.value, opts.flavor); - const ws = DendronWorkspace.instance(); let uris: Uri[]; if (resp) { window.showErrorMessage(resp); @@ -296,10 +301,12 @@ export class LookupProviderV2 { // check if we get note by quickpick value instead of selection const activeItem = picker.activeItems[0]; const maybeNoteFname = activeItem ? activeItem.fname : value; - const maybeNote = NoteUtilsV2.getNoteByFname( - maybeNoteFname, - ws.getEngine().notes - ); + const vault = PickerUtilsV2.getOrPromptVaultForOpenEditor(); + const maybeNote = NoteUtilsV2.getNoteByFnameV4({ + fname: maybeNoteFname, + vault, + notes: getEngine().notes, + }) as NotePropsV2; if (_.isEmpty(selectedItems) && opts.flavor === "note") { if (maybeNote) { if (maybeNote.stub) { diff --git a/packages/plugin-core/src/fileWatcher.ts b/packages/plugin-core/src/fileWatcher.ts index 05a12188bb..b9011a0890 100644 --- a/packages/plugin-core/src/fileWatcher.ts +++ b/packages/plugin-core/src/fileWatcher.ts @@ -66,10 +66,11 @@ export class VaultWatcher { dirPath: path.dirname(uri.fsPath), }); let note = string2Note({ content, fname, vault }); - const noteHydrated = NoteUtilsV2.getNoteByFname( + const noteHydrated = NoteUtilsV2.getNoteByFnameV4({ fname, - eclient.notes - ) as NotePropsV2; + vault, + notes: eclient.notes, + }) as NotePropsV2; note = NoteUtilsV2.hydrate({ noteRaw: note, noteHydrated }); const links = ParserUtilsV2.findLinks({ note }); note.links = links; @@ -106,9 +107,16 @@ export class VaultWatcher { try { this.L.debug({ ctx, uri, msg: "pre-add-to-engine" }); - // TODO: MULTI_VAULT - note = file2Note(uri.fsPath, { fsPath: path.dirname(uri.fsPath) }); - const maybeNote = NoteUtilsV2.getNoteByFname(fname, this.engine.notes); + const vault = DNodeUtilsV2.getVaultByDir({ + dirPath: path.dirname(uri.fsPath), + vaults: this.engine.vaultsv3, + }); + note = file2Note(uri.fsPath, vault); + const maybeNote = NoteUtilsV2.getNoteByFnameV4({ + fname, + vault, + notes: this.engine.notes, + }) as NotePropsV2; if (maybeNote) { note = { ...note, diff --git a/packages/plugin-core/src/test/suite-integ/LookupScratch.test.ts b/packages/plugin-core/src/test/suite-integ/LookupScratch.test.ts index dfc3a15f8d..f3fb8a53f1 100644 --- a/packages/plugin-core/src/test/suite-integ/LookupScratch.test.ts +++ b/packages/plugin-core/src/test/suite-integ/LookupScratch.test.ts @@ -117,7 +117,7 @@ suite("Scratch Notes", function () { }); }); - test.only("domainAsNamespace", function (done) { + test("domainAsNamespace", function (done) { runLegacyMultiWorkspaceTest({ ctx, configOverride: { diff --git a/packages/plugin-core/src/views/DendronTreeViewV2.ts b/packages/plugin-core/src/views/DendronTreeViewV2.ts index 767aab221b..89c357bb76 100644 --- a/packages/plugin-core/src/views/DendronTreeViewV2.ts +++ b/packages/plugin-core/src/views/DendronTreeViewV2.ts @@ -19,7 +19,7 @@ import { VaultUtils } from "@dendronhq/common-server"; import { GotoNoteCommandOpts } from "../commands/GotoNote"; import { DENDRON_COMMANDS, ICONS } from "../constants"; import { Logger } from "../logger"; -import { DendronWorkspace } from "../workspace"; +import { DendronWorkspace, getEngine } from "../workspace"; import { HistoryEvent, HistoryService } from "@dendronhq/engine-server"; function createTreeNote(note: NotePropsV2) { @@ -193,8 +193,11 @@ export class DendronTreeViewV2 { vaults: DendronWorkspace.instance().vaults, }); const fname = NoteUtilsV2.uri2Fname(uri); - const notes = DendronWorkspace.instance().getEngine().notes; - const note = NoteUtilsV2.getNoteByFname(fname, notes, { vault }); + const note = NoteUtilsV2.getNoteByFnameV4({ + fname, + vault, + notes: getEngine().notes, + }) as NotePropsV2; if (note) { this.treeView.reveal(note.id); } diff --git a/packages/plugin-core/src/workspace.ts b/packages/plugin-core/src/workspace.ts index 5158e3b35d..8428b93db8 100644 --- a/packages/plugin-core/src/workspace.ts +++ b/packages/plugin-core/src/workspace.ts @@ -86,6 +86,10 @@ export function getWS() { return DendronWorkspace.instance(); } +export function getEngine() { + return DendronWorkspace.instance().getEngine(); +} + export function resolveRelToWSRoot(fpath: string): string { return resolvePath(fpath, DendronWorkspace.wsRoot() as string); }