You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

300 lines
14 KiB

Major refactor/rework -- many new features and breaking changes Adds all-new, beautiful, highly customizable and themeable, file blame annotations Adds all-new configurability and themeability to the current line blame annotations Adds all-new configurability to the status bar blame information Adds all-new configurability over which commands are added to which menus via the `gitlens.advanced.menus` setting Adds better configurability over where Git code lens will be shown -- both by default and per language Adds an all-new `changes` (diff) hover annotation to the current line - provides instant access to the line's previous version Adds `Toggle Line Blame Annotations` command (`gitlens.toggleLineBlame`) - toggles the current line blame annotations on and off Adds `Show Line Blame Annotations` command (`gitlens.showLineBlame`) - shows the current line blame annotations Adds `Toggle File Blame Annotations` command (`gitlens.toggleFileBlame`) - toggles the file blame annotations on and off Adds `Show File Blame Annotations` command (`gitlens.showFileBlame`) - shows the file blame annotations Adds `Open File in Remote` command (`gitlens.openFileInRemote`) to the `editor/title` context menu Adds `Open Repo in Remote` command (`gitlens.openRepoInRemote`) to the `editor/title` context menu Changes the position of the `Open File in Remote` command (`gitlens.openFileInRemote`) in the context menus - now in the `navigation` group Changes the `Toggle Git Code Lens` command (`gitlens.toggleCodeLens`) to always toggle the Git code lens on and off Removes the on-demand `trailing` file blame annotations -- didn't work out and just ended up with a ton of visual noise Removes `Toggle Blame Annotations` command (`gitlens.toggleBlame`) - replaced by the `Toggle File Blame Annotations` command (`gitlens.toggleFileBlame`) Removes `Show Blame Annotations` command (`gitlens.showBlame`) - replaced by the `Show File Blame Annotations` command (`gitlens.showFileBlame`)
7 years ago
Major refactor/rework -- many new features and breaking changes Adds all-new, beautiful, highly customizable and themeable, file blame annotations Adds all-new configurability and themeability to the current line blame annotations Adds all-new configurability to the status bar blame information Adds all-new configurability over which commands are added to which menus via the `gitlens.advanced.menus` setting Adds better configurability over where Git code lens will be shown -- both by default and per language Adds an all-new `changes` (diff) hover annotation to the current line - provides instant access to the line's previous version Adds `Toggle Line Blame Annotations` command (`gitlens.toggleLineBlame`) - toggles the current line blame annotations on and off Adds `Show Line Blame Annotations` command (`gitlens.showLineBlame`) - shows the current line blame annotations Adds `Toggle File Blame Annotations` command (`gitlens.toggleFileBlame`) - toggles the file blame annotations on and off Adds `Show File Blame Annotations` command (`gitlens.showFileBlame`) - shows the file blame annotations Adds `Open File in Remote` command (`gitlens.openFileInRemote`) to the `editor/title` context menu Adds `Open Repo in Remote` command (`gitlens.openRepoInRemote`) to the `editor/title` context menu Changes the position of the `Open File in Remote` command (`gitlens.openFileInRemote`) in the context menus - now in the `navigation` group Changes the `Toggle Git Code Lens` command (`gitlens.toggleCodeLens`) to always toggle the Git code lens on and off Removes the on-demand `trailing` file blame annotations -- didn't work out and just ended up with a ton of visual noise Removes `Toggle Blame Annotations` command (`gitlens.toggleBlame`) - replaced by the `Toggle File Blame Annotations` command (`gitlens.toggleFileBlame`) Removes `Show Blame Annotations` command (`gitlens.showBlame`) - replaced by the `Show File Blame Annotations` command (`gitlens.showFileBlame`)
7 years ago
Major refactor/rework -- many new features and breaking changes Adds all-new, beautiful, highly customizable and themeable, file blame annotations Adds all-new configurability and themeability to the current line blame annotations Adds all-new configurability to the status bar blame information Adds all-new configurability over which commands are added to which menus via the `gitlens.advanced.menus` setting Adds better configurability over where Git code lens will be shown -- both by default and per language Adds an all-new `changes` (diff) hover annotation to the current line - provides instant access to the line's previous version Adds `Toggle Line Blame Annotations` command (`gitlens.toggleLineBlame`) - toggles the current line blame annotations on and off Adds `Show Line Blame Annotations` command (`gitlens.showLineBlame`) - shows the current line blame annotations Adds `Toggle File Blame Annotations` command (`gitlens.toggleFileBlame`) - toggles the file blame annotations on and off Adds `Show File Blame Annotations` command (`gitlens.showFileBlame`) - shows the file blame annotations Adds `Open File in Remote` command (`gitlens.openFileInRemote`) to the `editor/title` context menu Adds `Open Repo in Remote` command (`gitlens.openRepoInRemote`) to the `editor/title` context menu Changes the position of the `Open File in Remote` command (`gitlens.openFileInRemote`) in the context menus - now in the `navigation` group Changes the `Toggle Git Code Lens` command (`gitlens.toggleCodeLens`) to always toggle the Git code lens on and off Removes the on-demand `trailing` file blame annotations -- didn't work out and just ended up with a ton of visual noise Removes `Toggle Blame Annotations` command (`gitlens.toggleBlame`) - replaced by the `Toggle File Blame Annotations` command (`gitlens.toggleFileBlame`) Removes `Show Blame Annotations` command (`gitlens.showBlame`) - replaced by the `Show File Blame Annotations` command (`gitlens.showFileBlame`)
7 years ago
Major refactor/rework -- many new features and breaking changes Adds all-new, beautiful, highly customizable and themeable, file blame annotations Adds all-new configurability and themeability to the current line blame annotations Adds all-new configurability to the status bar blame information Adds all-new configurability over which commands are added to which menus via the `gitlens.advanced.menus` setting Adds better configurability over where Git code lens will be shown -- both by default and per language Adds an all-new `changes` (diff) hover annotation to the current line - provides instant access to the line's previous version Adds `Toggle Line Blame Annotations` command (`gitlens.toggleLineBlame`) - toggles the current line blame annotations on and off Adds `Show Line Blame Annotations` command (`gitlens.showLineBlame`) - shows the current line blame annotations Adds `Toggle File Blame Annotations` command (`gitlens.toggleFileBlame`) - toggles the file blame annotations on and off Adds `Show File Blame Annotations` command (`gitlens.showFileBlame`) - shows the file blame annotations Adds `Open File in Remote` command (`gitlens.openFileInRemote`) to the `editor/title` context menu Adds `Open Repo in Remote` command (`gitlens.openRepoInRemote`) to the `editor/title` context menu Changes the position of the `Open File in Remote` command (`gitlens.openFileInRemote`) in the context menus - now in the `navigation` group Changes the `Toggle Git Code Lens` command (`gitlens.toggleCodeLens`) to always toggle the Git code lens on and off Removes the on-demand `trailing` file blame annotations -- didn't work out and just ended up with a ton of visual noise Removes `Toggle Blame Annotations` command (`gitlens.toggleBlame`) - replaced by the `Toggle File Blame Annotations` command (`gitlens.toggleFileBlame`) Removes `Show Blame Annotations` command (`gitlens.showBlame`) - replaced by the `Show File Blame Annotations` command (`gitlens.showFileBlame`)
7 years ago
Major refactor/rework -- many new features and breaking changes Adds all-new, beautiful, highly customizable and themeable, file blame annotations Adds all-new configurability and themeability to the current line blame annotations Adds all-new configurability to the status bar blame information Adds all-new configurability over which commands are added to which menus via the `gitlens.advanced.menus` setting Adds better configurability over where Git code lens will be shown -- both by default and per language Adds an all-new `changes` (diff) hover annotation to the current line - provides instant access to the line's previous version Adds `Toggle Line Blame Annotations` command (`gitlens.toggleLineBlame`) - toggles the current line blame annotations on and off Adds `Show Line Blame Annotations` command (`gitlens.showLineBlame`) - shows the current line blame annotations Adds `Toggle File Blame Annotations` command (`gitlens.toggleFileBlame`) - toggles the file blame annotations on and off Adds `Show File Blame Annotations` command (`gitlens.showFileBlame`) - shows the file blame annotations Adds `Open File in Remote` command (`gitlens.openFileInRemote`) to the `editor/title` context menu Adds `Open Repo in Remote` command (`gitlens.openRepoInRemote`) to the `editor/title` context menu Changes the position of the `Open File in Remote` command (`gitlens.openFileInRemote`) in the context menus - now in the `navigation` group Changes the `Toggle Git Code Lens` command (`gitlens.toggleCodeLens`) to always toggle the Git code lens on and off Removes the on-demand `trailing` file blame annotations -- didn't work out and just ended up with a ton of visual noise Removes `Toggle Blame Annotations` command (`gitlens.toggleBlame`) - replaced by the `Toggle File Blame Annotations` command (`gitlens.toggleFileBlame`) Removes `Show Blame Annotations` command (`gitlens.showBlame`) - replaced by the `Show File Blame Annotations` command (`gitlens.showFileBlame`)
7 years ago
  1. 'use strict';
  2. // import { Objects } from './system';
  3. import { commands, ExtensionContext, extensions, languages, window, workspace } from 'vscode';
  4. import { AnnotationController } from './annotations/annotationController';
  5. import { CloseUnchangedFilesCommand, OpenChangedFilesCommand } from './commands';
  6. import { OpenBranchesInRemoteCommand, OpenBranchInRemoteCommand, OpenCommitInRemoteCommand, OpenFileInRemoteCommand, OpenInRemoteCommand, OpenRepoInRemoteCommand } from './commands';
  7. import { CopyMessageToClipboardCommand, CopyShaToClipboardCommand } from './commands';
  8. import { DiffDirectoryCommand, DiffLineWithPreviousCommand, DiffLineWithWorkingCommand, DiffWithBranchCommand, DiffWithCommand, DiffWithNextCommand, DiffWithPreviousCommand, DiffWithRevisionCommand, DiffWithWorkingCommand } from './commands';
  9. import { ResetSuppressedWarningsCommand } from './commands';
  10. import { ClearFileAnnotationsCommand, ShowFileBlameCommand, ShowLineBlameCommand, ToggleFileBlameCommand, ToggleFileRecentChangesCommand, ToggleLineBlameCommand } from './commands';
  11. import { ShowBlameHistoryCommand, ShowFileHistoryCommand } from './commands';
  12. import { ShowLastQuickPickCommand } from './commands';
  13. import { ShowQuickBranchHistoryCommand, ShowQuickCurrentBranchHistoryCommand, ShowQuickFileHistoryCommand } from './commands';
  14. import { ShowCommitSearchCommand, ShowQuickCommitDetailsCommand, ShowQuickCommitFileDetailsCommand } from './commands';
  15. import { ShowQuickRepoStatusCommand, ShowQuickStashListCommand } from './commands';
  16. import { StashApplyCommand, StashDeleteCommand, StashSaveCommand } from './commands';
  17. import { ToggleCodeLensCommand } from './commands';
  18. import { CodeLensLocations, IConfig, LineHighlightLocations } from './configuration';
  19. import { ApplicationInsightsKey, CommandContext, ExtensionKey, QualifiedExtensionId, setCommandContext, WorkspaceState } from './constants';
  20. import { CodeLensController } from './codeLensController';
  21. import { CurrentLineController, LineAnnotationType } from './currentLineController';
  22. import { RemoteProviderFactory } from './git/remotes/factory';
  23. import { GitContentProvider } from './gitContentProvider';
  24. import { GitExplorer } from './views/gitExplorer';
  25. import { GitRevisionCodeLensProvider } from './gitRevisionCodeLensProvider';
  26. import { GitContextTracker, GitService } from './gitService';
  27. import { Keyboard } from './keyboard';
  28. import { Logger } from './logger';
  29. import { Messages, SuppressedKeys } from './messages';
  30. import { Telemetry } from './telemetry';
  31. // this method is called when your extension is activated
  32. export async function activate(context: ExtensionContext) {
  33. Logger.configure(context);
  34. Messages.configure(context);
  35. Telemetry.configure(ApplicationInsightsKey);
  36. RemoteProviderFactory.configure(context);
  37. const gitlens = extensions.getExtension(QualifiedExtensionId)!;
  38. const gitlensVersion = gitlens.packageJSON.version;
  39. const rootPath = workspace.rootPath && workspace.rootPath.replace(/\\/g, '/');
  40. Logger.log(`GitLens(v${gitlensVersion}) active: ${rootPath}`);
  41. const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
  42. const gitPath = cfg.advanced.git;
  43. try {
  44. await GitService.getGitPath(gitPath);
  45. }
  46. catch (ex) {
  47. Logger.error(ex, 'Extension.activate');
  48. if (ex.message.includes('Unable to find git')) {
  49. await window.showErrorMessage(`GitLens was unable to find Git. Please make sure Git is installed. Also ensure that Git is either in the PATH, or that 'gitlens.advanced.git' is pointed to its installed location.`);
  50. }
  51. setCommandContext(CommandContext.Enabled, false);
  52. return;
  53. }
  54. const repoPath = await GitService.getRepoPath(rootPath);
  55. const gitVersion = GitService.getGitVersion();
  56. Logger.log(`Git version: ${gitVersion}`);
  57. const telemetryContext: { [id: string]: any } = Object.create(null);
  58. telemetryContext.version = gitlensVersion;
  59. telemetryContext['git.version'] = gitVersion;
  60. Telemetry.setContext(telemetryContext);
  61. await migrateSettings(context);
  62. notifyOnUnsupportedGitVersion(context, gitVersion);
  63. notifyOnNewGitLensVersion(context, gitlensVersion);
  64. await context.globalState.update(WorkspaceState.GitLensVersion, gitlensVersion);
  65. const git = new GitService(repoPath);
  66. context.subscriptions.push(git);
  67. const gitContextTracker = new GitContextTracker(git);
  68. context.subscriptions.push(gitContextTracker);
  69. context.subscriptions.push(workspace.registerTextDocumentContentProvider(GitContentProvider.scheme, new GitContentProvider(context, git)));
  70. context.subscriptions.push(languages.registerCodeLensProvider(GitRevisionCodeLensProvider.selector, new GitRevisionCodeLensProvider(context, git)));
  71. const annotationController = new AnnotationController(context, git, gitContextTracker);
  72. context.subscriptions.push(annotationController);
  73. const codeLensController = new CodeLensController(context, git);
  74. context.subscriptions.push(codeLensController);
  75. const currentLineController = new CurrentLineController(context, git, gitContextTracker, annotationController);
  76. context.subscriptions.push(currentLineController);
  77. context.subscriptions.push(new Keyboard());
  78. context.subscriptions.push(window.registerTreeDataProvider('gitlens.gitExplorer', new GitExplorer(context, git)));
  79. context.subscriptions.push(commands.registerTextEditorCommand('gitlens.computingFileAnnotations', () => { }));
  80. context.subscriptions.push(new CloseUnchangedFilesCommand(git));
  81. context.subscriptions.push(new OpenChangedFilesCommand(git));
  82. context.subscriptions.push(new CopyMessageToClipboardCommand(git));
  83. context.subscriptions.push(new CopyShaToClipboardCommand(git));
  84. context.subscriptions.push(new DiffDirectoryCommand(git));
  85. context.subscriptions.push(new DiffLineWithPreviousCommand(git));
  86. context.subscriptions.push(new DiffLineWithWorkingCommand(git));
  87. context.subscriptions.push(new DiffWithCommand(git));
  88. context.subscriptions.push(new DiffWithBranchCommand(git));
  89. context.subscriptions.push(new DiffWithNextCommand(git));
  90. context.subscriptions.push(new DiffWithPreviousCommand(git));
  91. context.subscriptions.push(new DiffWithRevisionCommand(git));
  92. context.subscriptions.push(new DiffWithWorkingCommand(git));
  93. context.subscriptions.push(new OpenBranchesInRemoteCommand(git));
  94. context.subscriptions.push(new OpenBranchInRemoteCommand(git));
  95. context.subscriptions.push(new OpenCommitInRemoteCommand(git));
  96. context.subscriptions.push(new OpenFileInRemoteCommand(git));
  97. context.subscriptions.push(new OpenInRemoteCommand());
  98. context.subscriptions.push(new OpenRepoInRemoteCommand(git));
  99. context.subscriptions.push(new ClearFileAnnotationsCommand(annotationController));
  100. context.subscriptions.push(new ShowFileBlameCommand(annotationController));
  101. context.subscriptions.push(new ShowLineBlameCommand(currentLineController));
  102. context.subscriptions.push(new ToggleFileBlameCommand(annotationController));
  103. context.subscriptions.push(new ToggleFileRecentChangesCommand(annotationController));
  104. context.subscriptions.push(new ToggleLineBlameCommand(currentLineController));
  105. context.subscriptions.push(new ResetSuppressedWarningsCommand(context));
  106. context.subscriptions.push(new ShowBlameHistoryCommand(git));
  107. context.subscriptions.push(new ShowFileHistoryCommand(git));
  108. context.subscriptions.push(new ShowLastQuickPickCommand());
  109. context.subscriptions.push(new ShowQuickBranchHistoryCommand(git));
  110. context.subscriptions.push(new ShowQuickCurrentBranchHistoryCommand(git));
  111. context.subscriptions.push(new ShowQuickCommitDetailsCommand(git));
  112. context.subscriptions.push(new ShowQuickCommitFileDetailsCommand(git));
  113. context.subscriptions.push(new ShowCommitSearchCommand(git));
  114. context.subscriptions.push(new ShowQuickFileHistoryCommand(git));
  115. context.subscriptions.push(new ShowQuickRepoStatusCommand(git));
  116. context.subscriptions.push(new ShowQuickStashListCommand(git));
  117. context.subscriptions.push(new StashApplyCommand(git));
  118. context.subscriptions.push(new StashDeleteCommand(git));
  119. context.subscriptions.push(new StashSaveCommand(git));
  120. context.subscriptions.push(new ToggleCodeLensCommand(codeLensController));
  121. // Constantly over my data cap so stop collecting initialized event
  122. // Telemetry.trackEvent('initialized', Objects.flatten(cfg, 'config', true));
  123. }
  124. // this method is called when your extension is deactivated
  125. export function deactivate() { }
  126. async function migrateSettings(context: ExtensionContext) {
  127. const previousVersion = context.globalState.get<string>(WorkspaceState.GitLensVersion);
  128. if (previousVersion === undefined) return;
  129. const [major] = previousVersion.split('.');
  130. if (parseInt(major, 10) >= 4) return;
  131. try {
  132. const cfg = workspace.getConfiguration(ExtensionKey);
  133. const prevCfg = workspace.getConfiguration().get<any>(ExtensionKey)!;
  134. if (prevCfg.blame !== undefined && prevCfg.blame.annotation !== undefined) {
  135. switch (prevCfg.blame.annotation.activeLine) {
  136. case 'off':
  137. await cfg.update('blame.line.enabled', false, true);
  138. break;
  139. case 'hover':
  140. await cfg.update('blame.line.annotationType', LineAnnotationType.Hover, true);
  141. break;
  142. }
  143. if (prevCfg.blame.annotation.activeLineDarkColor != null) {
  144. await cfg.update('theme.annotations.line.trailing.dark.foregroundColor', prevCfg.blame.annotation.activeLineDarkColor, true);
  145. }
  146. if (prevCfg.blame.annotation.activeLineLightColor != null) {
  147. await cfg.update('theme.annotations.line.trailing.light.foregroundColor', prevCfg.blame.annotation.activeLineLightColor, true);
  148. }
  149. switch (prevCfg.blame.annotation.highlight) {
  150. case 'none':
  151. await cfg.update('blame.file.lineHighlight.enabled', false);
  152. break;
  153. case 'gutter':
  154. await cfg.update('blame.file.lineHighlight.locations', [LineHighlightLocations.Gutter, LineHighlightLocations.OverviewRuler], true);
  155. break;
  156. case 'line':
  157. await cfg.update('blame.file.lineHighlight.locations', [LineHighlightLocations.Line, LineHighlightLocations.OverviewRuler], true);
  158. break;
  159. case 'both':
  160. }
  161. if (prevCfg.blame.annotation.dateFormat != null) {
  162. await cfg.update('annotations.file.gutter.dateFormat', prevCfg.blame.annotation.dateFormat, true);
  163. await cfg.update('annotations.line.trailing.dateFormat', prevCfg.blame.annotation.dateFormat, true);
  164. }
  165. }
  166. if (prevCfg.codeLens !== undefined) {
  167. switch (prevCfg.codeLens.visibility) {
  168. case 'ondemand':
  169. case 'off':
  170. await cfg.update('codeLens.enabled', false);
  171. }
  172. switch (prevCfg.codeLens.location) {
  173. case 'all':
  174. await cfg.update('codeLens.locations', [CodeLensLocations.Document, CodeLensLocations.Containers, CodeLensLocations.Blocks], true);
  175. break;
  176. case 'document+containers':
  177. await cfg.update('codeLens.locations', [CodeLensLocations.Document, CodeLensLocations.Containers], true);
  178. break;
  179. case 'document':
  180. await cfg.update('codeLens.locations', [CodeLensLocations.Document], true);
  181. break;
  182. case 'custom':
  183. await cfg.update('codeLens.locations', [CodeLensLocations.Custom], true);
  184. break;
  185. }
  186. if (prevCfg.codeLens.locationCustomSymbols != null) {
  187. await cfg.update('codeLens.customLocationSymbols', prevCfg.codeLens.locationCustomSymbols, true);
  188. }
  189. }
  190. if ((prevCfg.menus && prevCfg.menus.diff && prevCfg.menus.diff.enabled) === false) {
  191. await cfg.update('advanced.menus', {
  192. editorContext: {
  193. blame: true,
  194. copy: true,
  195. details: true,
  196. fileDiff: false,
  197. history: true,
  198. lineDiff: false,
  199. remote: true
  200. },
  201. editorTitle: {
  202. blame: true,
  203. fileDiff: false,
  204. history: true,
  205. remote: true,
  206. status: true
  207. },
  208. editorTitleContext: {
  209. blame: true,
  210. fileDiff: false,
  211. history: true,
  212. remote: true
  213. },
  214. explorerContext: {
  215. fileDiff: false,
  216. history: true,
  217. remote: true
  218. }
  219. }, true);
  220. }
  221. switch (prevCfg.statusBar && prevCfg.statusBar.date) {
  222. case 'off':
  223. await cfg.update('statusBar.format', '${author}', true);
  224. break;
  225. case 'absolute':
  226. await cfg.update('statusBar.format', '${author}, ${date}', true);
  227. break;
  228. }
  229. }
  230. catch (ex) {
  231. Logger.error(ex, 'migrateSettings');
  232. }
  233. finally {
  234. window.showInformationMessage(`GitLens v4 adds many new settings and removes a few old ones, so please review your settings to ensure they are configured properly.`);
  235. }
  236. }
  237. async function notifyOnNewGitLensVersion(context: ExtensionContext, version: string) {
  238. if (context.globalState.get(SuppressedKeys.UpdateNotice, false)) return;
  239. const previousVersion = context.globalState.get<string>(WorkspaceState.GitLensVersion);
  240. if (previousVersion === undefined) {
  241. Logger.log(`GitLens first-time install`);
  242. await Messages.showWelcomeMessage();
  243. return;
  244. }
  245. Logger.log(`GitLens upgraded from v${previousVersion} to v${version}`);
  246. const [major, minor] = version.split('.');
  247. const [prevMajor, prevMinor] = previousVersion.split('.');
  248. if (major === prevMajor && minor === prevMinor) return;
  249. // Don't notify on downgrades
  250. if (major < prevMajor || (major === prevMajor && minor < prevMinor)) return;
  251. await Messages.showUpdateMessage(version);
  252. }
  253. async function notifyOnUnsupportedGitVersion(context: ExtensionContext, version: string) {
  254. if (GitService.validateGitVersion(2, 2)) return;
  255. // If git is less than v2.2.0
  256. await Messages.showUnsupportedGitVersionErrorMessage(version);
  257. }