No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

104 líneas
5.4 KiB

  1. 'use strict';
  2. import { commands, ConfigurationTarget, Uri, window } from 'vscode';
  3. import { BuiltInCommands } from './constants';
  4. import { GitCommit } from './gitService';
  5. import { Logger } from './logger';
  6. import { configuration } from './configuration';
  7. export enum SuppressedMessages {
  8. CommitHasNoPreviousCommitWarning = 'suppressCommitHasNoPreviousCommitWarning',
  9. CommitNotFoundWarning = 'suppressCommitNotFoundWarning',
  10. FileNotUnderSourceControlWarning = 'suppressFileNotUnderSourceControlWarning',
  11. GitVersionWarning = 'suppressGitVersionWarning',
  12. LineUncommittedWarning = 'suppressLineUncommittedWarning',
  13. NoRepositoryWarning = 'suppressNoRepositoryWarning',
  14. UpdateNotice = 'suppressUpdateNotice',
  15. WelcomeNotice = 'suppressWelcomeNotice'
  16. }
  17. export class Messages {
  18. static showCommitHasNoPreviousCommitWarningMessage(commit?: GitCommit): Promise<string | undefined> {
  19. if (commit === undefined) return Messages.showMessage('info', `Commit has no previous commit`, SuppressedMessages.CommitHasNoPreviousCommitWarning);
  20. return Messages.showMessage('info', `Commit ${commit.shortSha} (${commit.author}, ${commit.fromNow()}) has no previous commit`, SuppressedMessages.CommitHasNoPreviousCommitWarning);
  21. }
  22. static showCommitNotFoundWarningMessage(message: string): Promise<string | undefined> {
  23. return Messages.showMessage('warn', `${message}. The commit could not be found`, SuppressedMessages.CommitNotFoundWarning);
  24. }
  25. static showFileNotUnderSourceControlWarningMessage(message: string): Promise<string | undefined> {
  26. return Messages.showMessage('warn', `${message}. The file is probably not under source control`, SuppressedMessages.FileNotUnderSourceControlWarning);
  27. }
  28. static showLineUncommittedWarningMessage(message: string): Promise<string | undefined> {
  29. return Messages.showMessage('warn', `${message}. The line has uncommitted changes`, SuppressedMessages.LineUncommittedWarning);
  30. }
  31. static showNoRepositoryWarningMessage(message: string): Promise<string | undefined> {
  32. return Messages.showMessage('warn', `${message}. No repository could be found`, SuppressedMessages.NoRepositoryWarning);
  33. }
  34. static showUnsupportedGitVersionErrorMessage(version: string): Promise<string | undefined> {
  35. return Messages.showMessage('error', `GitLens requires a newer version of Git (>= 2.2.0) than is currently installed (${version}). Please install a more recent version of Git.`, SuppressedMessages.GitVersionWarning);
  36. }
  37. static async showUpdateMessage(version: string): Promise<string | undefined> {
  38. const viewReleaseNotes = 'View Release Notes';
  39. const result = await Messages.showMessage('info', `GitLens has been updated to v${version}`, SuppressedMessages.UpdateNotice, undefined, viewReleaseNotes);
  40. if (result === viewReleaseNotes) {
  41. commands.executeCommand(BuiltInCommands.Open, Uri.parse('https://marketplace.visualstudio.com/items/eamodio.gitlens/changelog'));
  42. }
  43. return result;
  44. }
  45. static async showWelcomeMessage(): Promise<string | undefined> {
  46. const viewDocs = 'View Docs';
  47. const result = await Messages.showMessage('info', `Thank you for choosing GitLens! GitLens is powerful, feature rich, and highly configurable, so please be sure to view the docs and tailor it to suit your needs.`, SuppressedMessages.WelcomeNotice, null, viewDocs);
  48. if (result === viewDocs) {
  49. commands.executeCommand(BuiltInCommands.Open, Uri.parse('https://marketplace.visualstudio.com/items/eamodio.gitlens'));
  50. }
  51. return result;
  52. }
  53. private static async showMessage(type: 'info' | 'warn' | 'error', message: string, suppressionKey: SuppressedMessages, dontShowAgain: string | null = 'Don\'t Show Again', ...actions: any[]): Promise<string | undefined> {
  54. Logger.log(`ShowMessage(${type}, '${message}', ${suppressionKey}, ${dontShowAgain})`);
  55. if (configuration.get<boolean>(configuration.name('advanced')('messages')(suppressionKey).value)) {
  56. Logger.log(`ShowMessage(${type}, '${message}', ${suppressionKey}, ${dontShowAgain}) skipped`);
  57. return undefined;
  58. }
  59. if (dontShowAgain !== null) {
  60. actions.push(dontShowAgain);
  61. }
  62. let result: string | undefined = undefined;
  63. switch (type) {
  64. case 'info':
  65. result = await window.showInformationMessage(message, ...actions);
  66. break;
  67. case 'warn':
  68. result = await window.showWarningMessage(message, ...actions);
  69. break;
  70. case 'error':
  71. result = await window.showErrorMessage(message, ...actions);
  72. break;
  73. }
  74. if (dontShowAgain === null || result === dontShowAgain) {
  75. Logger.log(`ShowMessage(${type}, '${message}', ${suppressionKey}, ${dontShowAgain}) don't show again requested`);
  76. const section = configuration.name('advanced')('messages').value;
  77. const messages: { [key: string]: boolean } = configuration.get(section);
  78. messages[suppressionKey] = true;
  79. await configuration.update(section, messages, ConfigurationTarget.Global);
  80. if (result === dontShowAgain) return undefined;
  81. }
  82. Logger.log(`ShowMessage(${type}, '${message}', ${suppressionKey}, ${dontShowAgain}) returned ${result}`);
  83. return result;
  84. }
  85. }