vscode#FileWillRenameEvent TypeScript Examples

The following examples show how to use vscode#FileWillRenameEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorkspaceWatcher.ts    From dendron with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
   * method to make modifications to the workspace before the file is renamed.
   * It updates all the references to the oldUri
   */
  onWillRenameFiles(args: FileWillRenameEvent) {
    // No-op if we're not in a Dendron Workspace
    if (!this._extension.isActive()) {
      return;
    }
    try {
      const files = args.files[0];
      const { vaults, wsRoot } = this._extension.getDWorkspace();
      const { oldUri, newUri } = files;
      const oldVault = VaultUtils.getVaultByFilePath({
        vaults,
        wsRoot,
        fsPath: oldUri.fsPath,
      });
      const oldFname = DNodeUtils.fname(oldUri.fsPath);

      const newVault = VaultUtils.getVaultByFilePath({
        vaults,
        wsRoot,
        fsPath: newUri.fsPath,
      });
      const newFname = DNodeUtils.fname(newUri.fsPath);
      const opts = {
        oldLoc: {
          fname: oldFname,
          vaultName: VaultUtils.getName(oldVault),
        },
        newLoc: {
          fname: newFname,
          vaultName: VaultUtils.getName(newVault),
        },
        isEventSourceEngine: false,
      };
      AnalyticsUtils.track(ContextualUIEvents.ContextualUIRename);
      const engine = this._extension.getEngine();
      const updateNoteReferences = engine.renameNote(opts);
      args.waitUntil(updateNoteReferences);
    } catch (error: any) {
      Sentry.captureException(error);
      throw error;
    }
  }