-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to open the full commit message in a separate tab
Add a new configuration option: "showEditor" that displays the commit message in a separate tab as a text document the user can edit. If autoCommit is set to true, saving the file will automatically commit the message. If autoCommit is set to false, it will paste the contents into the scm as usual and close the tab.
- Loading branch information
Showing
8 changed files
with
143 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @since 2021-01-29 11:09 | ||
* @author sbacic | ||
*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import * as VSCodeGit from '../../vendors/git'; | ||
import { state } from './provider'; | ||
|
||
/** | ||
* Opens a new empty file and adds the commit message. The language mode is set to "Git Commit Message" and | ||
* the FileSystemProvider is set to CommitProvider. | ||
* @param repository The project repository. | ||
*/ | ||
export default async function openMessageInTab( | ||
repository: VSCodeGit.Repository, | ||
) { | ||
state.repository = repository; | ||
const uri = vscode.Uri.file('COMMIT_EDITMSG').with({ | ||
scheme: 'commit-message', | ||
}); | ||
await vscode.commands.executeCommand('vscode.open', uri); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import * as vscode from 'vscode'; | ||
import { TextDecoder, TextEncoder } from 'util'; | ||
import localize from '../localize'; | ||
import { Repository } from '../../vendors/git'; | ||
import * as configuration from '../configuration'; | ||
import * as output from '../output'; | ||
|
||
interface State { | ||
repository?: Repository; | ||
} | ||
|
||
export const state: State = { | ||
repository: undefined, | ||
}; | ||
|
||
/** | ||
* Simplified provider for handling Git commit messages. | ||
* On save, the contents are instead autocommited or used to update repository object (depending on settings). | ||
*/ | ||
const CommitProvider = new (class implements vscode.FileSystemProvider { | ||
private _emitter = new vscode.EventEmitter<vscode.FileChangeEvent[]>(); | ||
readonly onDidChangeFile: vscode.Event<vscode.FileChangeEvent[]> = this | ||
._emitter.event; | ||
|
||
watch(_resource: vscode.Uri): vscode.Disposable { | ||
return new vscode.Disposable(() => {}); | ||
} | ||
|
||
stat(): vscode.FileStat { | ||
return { | ||
type: vscode.FileType.File, | ||
ctime: Date.now(), | ||
mtime: Date.now(), | ||
size: 0, | ||
}; | ||
} | ||
|
||
readDirectory() { | ||
return []; | ||
} | ||
|
||
readFile(_uri: vscode.Uri): Uint8Array { | ||
const enc = new TextEncoder(); | ||
return enc.encode(state.repository?.inputBox.value); | ||
} | ||
|
||
createDirectory(): void {} | ||
writeFile(_uri: vscode.Uri, content: Uint8Array): Thenable<void> { | ||
return new Promise(async (resolve) => { | ||
try { | ||
const value = new TextDecoder().decode(content); | ||
|
||
if (state.repository) { | ||
const autoCommit = configuration.get<boolean>('autoCommit'); | ||
state.repository.inputBox.value = value; | ||
vscode.commands.executeCommand( | ||
'workbench.action.revertAndCloseActiveEditor', | ||
); | ||
|
||
if (autoCommit) { | ||
await vscode.commands.executeCommand( | ||
'git.commit', | ||
state.repository, | ||
); | ||
resolve(); | ||
} else { | ||
await vscode.commands.executeCommand('workbench.view.scm'); | ||
resolve(); | ||
} | ||
|
||
output.appendLine('Finished successfully.'); | ||
} | ||
} catch (e) { | ||
output.appendLine(`Finished with an error: ${e.stack}`); | ||
vscode.window.showErrorMessage( | ||
`${localize('extension.name')}: ${e.message}`, | ||
); | ||
} | ||
}); | ||
} | ||
rename(): void {} | ||
delete(): void {} | ||
})(); | ||
|
||
export default CommitProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters