vscode#TextDocumentSaveReason TypeScript Examples

The following examples show how to use vscode#TextDocumentSaveReason. 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
/**
   * If note is in workspace, execute {@link onWillSaveNote}
   * @param event
   * @returns
   */
  onWillSaveTextDocument(event: TextDocumentWillSaveEvent) {
    try {
      const ctx = "WorkspaceWatcher:onWillSaveTextDocument";
      const uri = event.document.uri;
      Logger.info({
        ctx,
        url: uri.fsPath,
        reason: TextDocumentSaveReason[event.reason],
        msg: "enter",
      });
      const { wsRoot, vaults } = this._extension.getDWorkspace();
      if (
        !WorkspaceUtils.isPathInWorkspace({ fpath: uri.fsPath, wsRoot, vaults })
      ) {
        Logger.debug({
          ctx,
          uri: uri.fsPath,
          msg: "not in workspace, ignoring.",
        });
        return { changes: [] };
      }

      if (uri.fsPath.endsWith(".md")) {
        return this.onWillSaveNote(event);
      } else {
        Logger.debug({
          ctx,
          uri: uri.fsPath,
          msg: "File type is not registered for updates. ignoring.",
        });
        return { changes: [] };
      }
    } catch (error) {
      Sentry.captureException(error);
      throw error;
    }
  }