Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this be hooked into onSave? #65

Open
decryptedchaos opened this issue Oct 6, 2021 · 7 comments · May be fixed by #68
Open

Can this be hooked into onSave? #65

decryptedchaos opened this issue Oct 6, 2021 · 7 comments · May be fixed by #68

Comments

@decryptedchaos
Copy link

I'm using this in a workspace where i don't care about commit messages, it's a static repo, of markdown files.

And while this is useful, i would rather it automatically populate the message onsave that way all i have to do is click one button.

@MichaelCurrin
Copy link
Owner

Ah, nice idea

@MichaelCurrin
Copy link
Owner

MichaelCurrin commented Oct 6, 2021

I couldn't find that event here :( https://code.visualstudio.com/api/references/activation-events

Oh wait that is when the extension activates (like on startup), not when it runs.

@MichaelCurrin
Copy link
Owner

Let me know if you find anything. Or any extensions to base on.

Other extensions I know of listen use the format on save flow, so listening to format event rather than save event. Maybe I can hook into that? Can't see anything useful for formatting or saving here. https://github.com/prettier/prettier-vscode/search?q=save

An alternative would be to add another button, or a mode, or keyboard shortcut. To generate and commit in one move, at the loss of seeing the message in between.

@decryptedchaos
Copy link
Author

Perhaps this would work too? Not sure not the best coder in the world. it seems VS Code referees to any source file. as "text"

onDidSaveTextDocument: Event

There's also createFileSystemWatcher(globPattern: GlobPattern, ignoreCreateEvents?: boolean, ignoreChangeEvents?: boolean, ignoreDeleteEvents?: boolean): FileSystemWatcher

Your solution of a hot key to both would also solve the problem, have a look at those API references and let me know if either are useful

@MichaelCurrin
Copy link
Owner

MichaelCurrin commented Oct 9, 2021

I found https://code.visualstudio.com/api/references/vscode-api in the docs

I am seeing stuff print when using onDidSaveTextDocument like this.

  context.subscriptions.push(disposable);
  context.subscriptions.push(
    vscode.workspace.onDidSaveTextDocument(e => {
      console.log(`Running because of file change: ${e}`)
      vscode.window.showInformationMessage(`Running because of file change: ${e}`)
    })
  )

Use in VS Code

https://github.com/microsoft/vscode/blob/665e0adaec248003b1424514084e0fe27c7c2048/extensions/emmet/src/emmetCommon.ts#L140

And in another project

https://github.com/egodigital/vscode-powertools/blob/70f480b41e62fb912104b0d9e093bb0858d4ca85/src/extension.ts#L526

@MichaelCurrin
Copy link
Owner

MichaelCurrin commented Oct 10, 2021

@decryptedchaos I have #66 #67.

You can try it out

git checkout auto-commit-msg
git pull
git checkout feat-add-save-hook
make ext

@decryptedchaos
Copy link
Author

Yep, Will check it out when i'm back at my desk

Thanks for the addition.

@MichaelCurrin MichaelCurrin reopened this Oct 10, 2021
@MichaelCurrin MichaelCurrin linked a pull request Oct 10, 2021 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants