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.

149 lines
4.8 KiB

преди 8 години
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 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
  1. 'use strict';
  2. import { Disposable, workspace } from 'vscode';
  3. import { Logger } from '../logger';
  4. interface ConfigurationInspection {
  5. key: string;
  6. defaultValue?: string;
  7. globalValue?: string;
  8. workspaceValue?: string;
  9. }
  10. enum SettingLocation {
  11. workspace,
  12. global,
  13. default
  14. }
  15. class RenderWhitespaceConfiguration {
  16. constructor(public inspection: ConfigurationInspection) { }
  17. get location(): SettingLocation {
  18. if (this.inspection.workspaceValue) return SettingLocation.workspace;
  19. if (this.inspection.globalValue) return SettingLocation.global;
  20. return SettingLocation.default;
  21. }
  22. get overrideRequired() {
  23. return this.value != null && this.value !== 'none';
  24. }
  25. get value(): string | undefined {
  26. return this.inspection.workspaceValue || this.inspection.globalValue || this.inspection.defaultValue;
  27. }
  28. update(replacement: ConfigurationInspection): boolean {
  29. let override = false;
  30. switch (this.location) {
  31. case SettingLocation.workspace:
  32. this.inspection.defaultValue = replacement.defaultValue;
  33. this.inspection.globalValue = replacement.globalValue;
  34. if (replacement.workspaceValue !== 'none') {
  35. this.inspection.workspaceValue = replacement.workspaceValue;
  36. override = true;
  37. }
  38. break;
  39. case SettingLocation.global:
  40. this.inspection.defaultValue = replacement.defaultValue;
  41. this.inspection.workspaceValue = replacement.workspaceValue;
  42. if (replacement.globalValue !== 'none') {
  43. this.inspection.globalValue = replacement.globalValue;
  44. override = true;
  45. }
  46. break;
  47. case SettingLocation.default:
  48. this.inspection.globalValue = replacement.globalValue;
  49. this.inspection.workspaceValue = replacement.workspaceValue;
  50. if (replacement.defaultValue !== 'none') {
  51. this.inspection.defaultValue = replacement.defaultValue;
  52. override = true;
  53. }
  54. break;
  55. }
  56. return override;
  57. }
  58. }
  59. export class WhitespaceController extends Disposable {
  60. private _configuration: RenderWhitespaceConfiguration;
  61. private _count: number = 0;
  62. private _disposable: Disposable;
  63. private _disposed: boolean = false;
  64. constructor() {
  65. super(() => this.dispose());
  66. const subscriptions: Disposable[] = [];
  67. subscriptions.push(workspace.onDidChangeConfiguration(this._onConfigurationChanged, this));
  68. this._disposable = Disposable.from(...subscriptions);
  69. this._onConfigurationChanged();
  70. }
  71. async dispose() {
  72. this._disposed = true;
  73. if (this._count !== 0) {
  74. await this._restoreWhitespace();
  75. this._count = 0;
  76. }
  77. }
  78. private _onConfigurationChanged() {
  79. if (this._disposed) return;
  80. const inspection = workspace.getConfiguration('editor').inspect<string>('renderWhitespace')!;
  81. if (!this._count) {
  82. this._configuration = new RenderWhitespaceConfiguration(inspection);
  83. return;
  84. }
  85. if (this._configuration.update(inspection)) {
  86. // Since we were currently overriding whitespace, re-override
  87. setTimeout(() => this._overrideWhitespace(), 1);
  88. }
  89. }
  90. async override() {
  91. if (this._disposed) return;
  92. Logger.log(`Request whitespace override; count=${this._count}`);
  93. this._count++;
  94. if (this._count === 1 && this._configuration.overrideRequired) {
  95. // Override whitespace (turn off)
  96. await this._overrideWhitespace();
  97. }
  98. }
  99. private async _overrideWhitespace() {
  100. Logger.log(`Override whitespace`);
  101. const cfg = workspace.getConfiguration('editor');
  102. return cfg.update('renderWhitespace', 'none', this._configuration.location === SettingLocation.global);
  103. }
  104. async restore() {
  105. if (this._disposed || this._count === 0) return;
  106. Logger.log(`Request whitespace restore; count=${this._count}`);
  107. this._count--;
  108. if (this._count === 0 && this._configuration.overrideRequired) {
  109. // restore whitespace
  110. await this._restoreWhitespace();
  111. }
  112. }
  113. private async _restoreWhitespace() {
  114. Logger.log(`Restore whitespace`);
  115. const cfg = workspace.getConfiguration('editor');
  116. return cfg.update('renderWhitespace',
  117. this._configuration.location === SettingLocation.default
  118. ? undefined
  119. : this._configuration.value,
  120. this._configuration.location === SettingLocation.global);
  121. }
  122. }