mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-12 19:18:32 -05:00
Adds new CodeLens visibility & location settings
Adds new command to toggle CodeLens on and off when `gitlens.codeLens.visibility` is set to `ondemand`
This commit is contained in:
28
README.md
28
README.md
@@ -21,15 +21,18 @@ Must be using Git and it must be in your path.
|
|||||||
|
|
||||||
|Name | Description
|
|Name | Description
|
||||||
|-----|------------
|
|-----|------------
|
||||||
|_gitlens.blame.annotation.style_|Specifies the style of the blame annotations. Compact - groups annotations to limit the repetition and also adds author and date when possible. Expanded - shows an annotation on every line
|
|`gitlens.blame.annotation.style`|Specifies the style of the blame annotations. `compact` - groups annotations to limit the repetition and also adds author and date when possible. `expanded` - shows an annotation on every line
|
||||||
|_gitlens.blame.annotation.sha_|Specifies whether the commit sha will be shown in the blame annotations. Applies only to the Expanded annotation style
|
|`gitlens.blame.annotation.sha`|Specifies whether the commit sha will be shown in the blame annotations. Applies only to the `expanded` annotation style
|
||||||
|_gitlens.blame.annotation.author_|Specifies whether the committer will be shown in the blame annotations. Applies only to the Expanded annotation style
|
|`gitlens.blame.annotation.author`|Specifies whether the committer will be shown in the blame annotations. Applies only to the `expanded` annotation style
|
||||||
|_gitlens.blame.annotation.date_|Specifies whether the commit date will be shown in the blame annotations. Applies only to the Expanded annotation style
|
|`gitlens.blame.annotation.date`|Specifies whether the commit date will be shown in the blame annotations. Applies only to the `expanded` annotation style
|
||||||
|_gitlens.blame.annotation.useCodeActions_|Specifies whether code actions (Diff with Working, Diff with Previous) will be provided for the selected line, when annotating. Not required as context menu options are always provided
|
|`gitlens.blame.annotation.useCodeActions`|Specifies whether code actions (Diff with Working, Diff with Previous) will be provided for the selected line, when annotating. Not required as context menu options are always provided
|
||||||
|_gitlens.codeLens.recentChange.enabled_|Specifies whether the recent change CodeLens is shown
|
|`gitlens.codeLens.visibility`|Specifies when CodeLens will be triggered in the active document. `auto` - automatically. `ondemand` - only when requested. `off` - disables all active document CodeLens
|
||||||
|_gitlens.codeLens.recentChange.command_|Specifies the command executed when the recent change CodeLens is clicked. Annotate - toggles blame annotations. Explorer - opens the blame explorer. History - opens a file history picker, which requires the Git History (git log) extension
|
|`gitlens.codeLens.location`|Specifies where CodeLens will be rendered in the active document. `all` - render at the top of the document, on container-like (classes, modules, etc), and on member-like (methods, functions, properties, etc) lines. `document+containers` - render at the top of the document and on container-like lines. `document` - only render at the top of the document. `custom` - rendering controlled by `gitlens.codeLens.locationCustomSymbols`
|
||||||
|_gitlens.codeLens.authors.enabled_|Specifies whether the authors CodeLens is shown
|
|`gitlens.codeLens.locationCustomSymbols`|Specifies the set of document symbols to render active document CodeLens on. Must be a member of `SymbolKind`
|
||||||
|_gitlens.codeLens.authors.command_|Specifies the command executed when the authors CodeLens is clicked. Annotate - toggles blame annotations. Explorer - opens the blame explorer. History - opens a file history picker, which requires the Git History (git log) extension
|
|`gitlens.codeLens.recentChange.enabled`|Specifies whether the recent change CodeLens is shown
|
||||||
|
|`gitlens.codeLens.recentChange.command`|Specifies the command executed when the recent change CodeLens is clicked. `blame.annotate` - toggles blame annotations. `blame.explorer` - opens the blame explorer. `git.history` - opens a file history picker, which requires the Git History (git log) extension
|
||||||
|
|`gitlens.codeLens.authors.enabled`|Specifies whether the authors CodeLens is shown
|
||||||
|
|`gitlens.codeLens.authors.command`|Specifies the command executed when the authors CodeLens is clicked. `blame.annotate` - toggles blame annotations. `blame.explorer` - opens the blame explorer. `git.history` - opens a file history picker, which requires the Git History (git log) extension
|
||||||
|
|
||||||
## Known Issues
|
## Known Issues
|
||||||
|
|
||||||
@@ -40,6 +43,11 @@ Must be using Git and it must be in your path.
|
|||||||
|
|
||||||
## Release Notes
|
## Release Notes
|
||||||
|
|
||||||
|
### 0.3.0
|
||||||
|
|
||||||
|
- Adds new CodeLens visibility & location settings -- see **Extension Settings** above for details
|
||||||
|
- Adds new command to toggle CodeLens on and off when `gitlens.codeLens.visibility` is set to `ondemand`
|
||||||
|
|
||||||
### 0.2.0
|
### 0.2.0
|
||||||
|
|
||||||
- Fixes [#1](https://github.com/eamodio/vscode-gitlens/issues/1) - Support blame on files outside the workspace repository
|
- Fixes [#1](https://github.com/eamodio/vscode-gitlens/issues/1) - Support blame on files outside the workspace repository
|
||||||
@@ -52,7 +60,7 @@ Must be using Git and it must be in your path.
|
|||||||
|
|
||||||
- Improved blame annotations, now with sha and author by default
|
- Improved blame annotations, now with sha and author by default
|
||||||
- Add new blame annotation styles -- compact and expanded (default)
|
- Add new blame annotation styles -- compact and expanded (default)
|
||||||
- Adds many new configuration settings; see Contributions tab above
|
- Adds many new configuration settings; see **Extension Settings** above for details
|
||||||
|
|
||||||
### 0.0.7
|
### 0.0.7
|
||||||
|
|
||||||
|
|||||||
50
package.json
50
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gitlens",
|
"name": "gitlens",
|
||||||
"version": "0.2.0",
|
"version": "0.3.0",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Eric Amodio",
|
"name": "Eric Amodio",
|
||||||
"email": "eamodio@gmail.com"
|
"email": "eamodio@gmail.com"
|
||||||
@@ -45,28 +45,53 @@
|
|||||||
"compact",
|
"compact",
|
||||||
"expanded"
|
"expanded"
|
||||||
],
|
],
|
||||||
"description": "Specifies the style of the blame annotations. Compact - groups annotations to limit the repetition and also adds author and date when possible. Expanded - shows an annotation on every line"
|
"description": "Specifies the style of the blame annotations. `compact` - groups annotations to limit the repetition and also adds author and date when possible. `expanded` - shows an annotation on every line"
|
||||||
},
|
},
|
||||||
"gitlens.blame.annotation.sha": {
|
"gitlens.blame.annotation.sha": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"default": true,
|
||||||
"description": "Specifies whether the commit sha will be shown in the blame annotations. Applies only to the Expanded annotation style"
|
"description": "Specifies whether the commit sha will be shown in the blame annotations. Applies only to the `expanded` annotation style"
|
||||||
},
|
},
|
||||||
"gitlens.blame.annotation.author": {
|
"gitlens.blame.annotation.author": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"default": true,
|
||||||
"description": "Specifies whether the committer will be shown in the blame annotations. Applies only to the Expanded annotation style"
|
"description": "Specifies whether the committer will be shown in the blame annotations. Applies only to the `expanded` annotation style"
|
||||||
},
|
},
|
||||||
"gitlens.blame.annotation.date": {
|
"gitlens.blame.annotation.date": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
"description": "Specifies whether the commit date will be shown in the blame annotations. Applies only to the Expanded annotation style"
|
"description": "Specifies whether the commit date will be shown in the blame annotations. Applies only to the `expanded` annotation style"
|
||||||
},
|
},
|
||||||
"gitlens.blame.annotation.useCodeActions": {
|
"gitlens.blame.annotation.useCodeActions": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
"description": "Specifies whether code actions (Diff with Working, Diff with Previous) will be provided for the selected line, when annotating. Not required as context menu options are always provided"
|
"description": "Specifies whether code actions (Diff with Working, Diff with Previous) will be provided for the selected line, when annotating. Not required as context menu options are always provided"
|
||||||
},
|
},
|
||||||
|
"gitlens.codeLens.visibility": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "auto",
|
||||||
|
"enum": [
|
||||||
|
"auto",
|
||||||
|
"ondemand",
|
||||||
|
"off"
|
||||||
|
],
|
||||||
|
"description": "Specifies when CodeLens will be triggered in the active document. `auto` - automatically. `ondemand` - only when requested. `off` - disables all active document CodeLens"
|
||||||
|
},
|
||||||
|
"gitlens.codeLens.location": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "document+containers",
|
||||||
|
"enum": [
|
||||||
|
"all",
|
||||||
|
"document+containers",
|
||||||
|
"document",
|
||||||
|
"custom"
|
||||||
|
],
|
||||||
|
"description": "Specifies where CodeLens will be rendered in the active document. `all` - render at the top of the document, on container-like (classes, modules, etc), and on member-like (methods, functions, properties, etc) lines. `document+containers` - render at the top of the document and on container-like lines. `document` - only render at the top of the document. `custom` - rendering controlled by `gitlens.codeLens.locationCustomSymbols`"
|
||||||
|
},
|
||||||
|
"gitlens.codeLens.locationCustomSymbols": {
|
||||||
|
"type": "array",
|
||||||
|
"description": "Specifies the set of document symbols to render active document CodeLens on. Must be a member of `SymbolKind`"
|
||||||
|
},
|
||||||
"gitlens.codeLens.recentChange.enabled": {
|
"gitlens.codeLens.recentChange.enabled": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"default": true,
|
||||||
@@ -80,7 +105,7 @@
|
|||||||
"blame.explorer",
|
"blame.explorer",
|
||||||
"git.history"
|
"git.history"
|
||||||
],
|
],
|
||||||
"description": "Specifies the command executed when the recent change CodeLens is clicked. Annotate - toggles blame annotations. Explorer - opens the blame explorer. History - opens a file history picker, which requires the Git History (git log) extension"
|
"description": "Specifies the command executed when the recent change CodeLens is clicked. `blame.annotate` - toggles blame annotations. `blame.explorer` - opens the blame explorer. `git.history` - opens a file history picker, which requires the Git History (git log) extension"
|
||||||
},
|
},
|
||||||
"gitlens.codeLens.authors.enabled": {
|
"gitlens.codeLens.authors.enabled": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@@ -95,7 +120,7 @@
|
|||||||
"blame.explorer",
|
"blame.explorer",
|
||||||
"git.history"
|
"git.history"
|
||||||
],
|
],
|
||||||
"description": "Specifies the command executed when the authors CodeLens is clicked. Annotate - toggles blame annotations. Explorer - opens the blame explorer. History - opens a file history picker, which requires the Git History (git log) extension"
|
"description": "Specifies the command executed when the authors CodeLens is clicked. `blame.annotate` - toggles blame annotations. `blame.explorer` - opens the blame explorer. `git.history` - opens a file history picker, which requires the Git History (git log) extension"
|
||||||
},
|
},
|
||||||
"gitlens.advanced.caching.enabled": {
|
"gitlens.advanced.caching.enabled": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@@ -123,6 +148,11 @@
|
|||||||
"command": "gitlens.toggleBlame",
|
"command": "gitlens.toggleBlame",
|
||||||
"title": "Git: Toggle Blame",
|
"title": "Git: Toggle Blame",
|
||||||
"category": "GitLens"
|
"category": "GitLens"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "gitlens.toggleCodeLens",
|
||||||
|
"title": "Git: Toggle CodeLens",
|
||||||
|
"category": "GitLens"
|
||||||
}],
|
}],
|
||||||
"menus": {
|
"menus": {
|
||||||
"editor/title": [{
|
"editor/title": [{
|
||||||
@@ -152,6 +182,12 @@
|
|||||||
"key": "alt+b",
|
"key": "alt+b",
|
||||||
"mac": "alt+b",
|
"mac": "alt+b",
|
||||||
"when": "editorTextFocus"
|
"when": "editorTextFocus"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "gitlens.toggleCodeLens",
|
||||||
|
"key": "alt+shift+b",
|
||||||
|
"mac": "alt+shift+b",
|
||||||
|
"when": "editorTextFocus"
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
"activationEvents": [
|
"activationEvents": [
|
||||||
|
|||||||
@@ -154,4 +154,14 @@ export class ToggleBlameCommand extends EditorCommand {
|
|||||||
.catch(ex => console.error('[GitLens.ToggleBlameCommand]', 'getBlameForLine', ex))
|
.catch(ex => console.error('[GitLens.ToggleBlameCommand]', 'getBlameForLine', ex))
|
||||||
.then(blame => this.blameController.toggleBlame(editor, blame && blame.commit.sha));
|
.then(blame => this.blameController.toggleBlame(editor, blame && blame.commit.sha));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ToggleCodeLensCommand extends EditorCommand {
|
||||||
|
constructor(private git: GitProvider) {
|
||||||
|
super(Commands.ToggleCodeLens);
|
||||||
|
}
|
||||||
|
|
||||||
|
execute(editor: TextEditor, edit: TextEditorEdit) {
|
||||||
|
return this.git.toggleCodeLens(editor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -23,12 +23,30 @@ export const CodeLensCommand = {
|
|||||||
GitHistory: 'git.history' as CodeLensCommand
|
GitHistory: 'git.history' as CodeLensCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type CodeLensLocation = 'all' | 'document+containers' | 'document' | 'custom';
|
||||||
|
export const CodeLensLocation = {
|
||||||
|
All: 'all' as CodeLensLocation,
|
||||||
|
DocumentAndContainers: 'document+containers' as CodeLensLocation,
|
||||||
|
Document: 'document' as CodeLensLocation,
|
||||||
|
Custom: 'custom' as CodeLensLocation,
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CodeLensVisibility = 'auto' | 'ondemand' | 'off';
|
||||||
|
export const CodeLensVisibility = {
|
||||||
|
Auto: 'auto' as CodeLensVisibility,
|
||||||
|
OnDemand: 'ondemand' as CodeLensVisibility,
|
||||||
|
Off: 'off' as CodeLensVisibility
|
||||||
|
}
|
||||||
|
|
||||||
export interface ICodeLensConfig {
|
export interface ICodeLensConfig {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
command: CodeLensCommand;
|
command: CodeLensCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICodeLensesConfig {
|
export interface ICodeLensesConfig {
|
||||||
|
visibility: CodeLensVisibility;
|
||||||
|
location: CodeLensLocation;
|
||||||
|
locationCustomSymbols: string[];
|
||||||
recentChange: ICodeLensConfig;
|
recentChange: ICodeLensConfig;
|
||||||
authors: ICodeLensConfig;
|
authors: ICodeLensConfig;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,20 +16,21 @@ export const BuiltInCommands = {
|
|||||||
ToggleRenderWhitespace: 'editor.action.toggleRenderWhitespace' as BuiltInCommands
|
ToggleRenderWhitespace: 'editor.action.toggleRenderWhitespace' as BuiltInCommands
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Commands = 'gitlens.diffWithPrevious' | 'gitlens.diffWithWorking' | 'gitlens.showBlame' | 'gitlens.showHistory' | 'gitlens.toggleBlame';
|
export type Commands = 'gitlens.diffWithPrevious' | 'gitlens.diffWithWorking' | 'gitlens.showBlame' | 'gitlens.showHistory' | 'gitlens.toggleBlame' | 'gitlens.toggleCodeLens';
|
||||||
export const Commands = {
|
export const Commands = {
|
||||||
DiffWithPrevious: 'gitlens.diffWithPrevious' as Commands,
|
DiffWithPrevious: 'gitlens.diffWithPrevious' as Commands,
|
||||||
DiffWithWorking: 'gitlens.diffWithWorking' as Commands,
|
DiffWithWorking: 'gitlens.diffWithWorking' as Commands,
|
||||||
ShowBlame: 'gitlens.showBlame' as Commands,
|
ShowBlame: 'gitlens.showBlame' as Commands,
|
||||||
ShowBlameHistory: 'gitlens.showHistory' as Commands,
|
ShowBlameHistory: 'gitlens.showHistory' as Commands,
|
||||||
ToggleBlame: 'gitlens.toggleBlame' as Commands,
|
ToggleBlame: 'gitlens.toggleBlame' as Commands,
|
||||||
|
ToggleCodeLens: 'gitlens.toggleCodeLens' as Commands,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DocumentSchemes = 'file' | 'git' | 'gitblame';
|
export type DocumentSchemes = 'file' | 'git' | 'git-blame';
|
||||||
export const DocumentSchemes = {
|
export const DocumentSchemes = {
|
||||||
File: 'file' as DocumentSchemes,
|
File: 'file' as DocumentSchemes,
|
||||||
Git: 'git' as DocumentSchemes,
|
Git: 'git' as DocumentSchemes,
|
||||||
GitBlame: 'gitblame' as DocumentSchemes
|
GitBlame: 'git-blame' as DocumentSchemes
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WorkspaceState = 'hasGitHistoryExtension' | 'repoPath';
|
export type WorkspaceState = 'hasGitHistoryExtension' | 'repoPath';
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import GitBlameCodeLensProvider from './gitBlameCodeLensProvider';
|
|||||||
import GitBlameContentProvider from './gitBlameContentProvider';
|
import GitBlameContentProvider from './gitBlameContentProvider';
|
||||||
import GitBlameController from './gitBlameController';
|
import GitBlameController from './gitBlameController';
|
||||||
import GitProvider, {Git} from './gitProvider';
|
import GitProvider, {Git} from './gitProvider';
|
||||||
import {DiffWithPreviousCommand, DiffWithWorkingCommand, ShowBlameCommand, ShowBlameHistoryCommand, ToggleBlameCommand} from './commands';
|
import {DiffWithPreviousCommand, DiffWithWorkingCommand, ShowBlameCommand, ShowBlameHistoryCommand, ToggleBlameCommand, ToggleCodeLensCommand} from './commands';
|
||||||
import {ICodeLensesConfig} from './configuration';
|
import {ICodeLensesConfig} from './configuration';
|
||||||
import {WorkspaceState} from './constants';
|
import {WorkspaceState} from './constants';
|
||||||
|
|
||||||
@@ -41,6 +41,7 @@ export function activate(context: ExtensionContext) {
|
|||||||
context.subscriptions.push(new ShowBlameCommand(git, blameController));
|
context.subscriptions.push(new ShowBlameCommand(git, blameController));
|
||||||
context.subscriptions.push(new ToggleBlameCommand(git, blameController));
|
context.subscriptions.push(new ToggleBlameCommand(git, blameController));
|
||||||
context.subscriptions.push(new ShowBlameHistoryCommand(git));
|
context.subscriptions.push(new ShowBlameHistoryCommand(git));
|
||||||
|
context.subscriptions.push(new ToggleCodeLensCommand(git));
|
||||||
}).catch(reason => console.warn('[GitLens]', reason));
|
}).catch(reason => console.warn('[GitLens]', reason));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export default class GitBlameController extends Disposable {
|
|||||||
// }));
|
// }));
|
||||||
|
|
||||||
workspace.onDidCloseTextDocument(d => {
|
workspace.onDidCloseTextDocument(d => {
|
||||||
if (!this._controller || this._controller.uri.fsPath !== d.uri.fsPath) return;
|
if (!this._controller || this._controller.uri.toString() !== d.uri.toString()) return;
|
||||||
this.clear();
|
this.clear();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import {CancellationToken, CodeLens, CodeLensProvider, commands, DocumentSelector, ExtensionContext, Location, Position, Range, SymbolInformation, SymbolKind, TextDocument, Uri, window, workspace} from 'vscode';
|
import {CancellationToken, CodeLens, CodeLensProvider, commands, DocumentSelector, ExtensionContext, Location, Position, Range, SymbolInformation, SymbolKind, TextDocument, Uri, window, workspace} from 'vscode';
|
||||||
import {BuiltInCommands, Commands, DocumentSchemes, WorkspaceState} from './constants';
|
import {BuiltInCommands, Commands, DocumentSchemes, WorkspaceState} from './constants';
|
||||||
import {CodeLensCommand, ICodeLensesConfig} from './configuration';
|
import {CodeLensCommand, CodeLensLocation, ICodeLensesConfig} from './configuration';
|
||||||
import GitProvider, {IGitBlame, IGitBlameLines, IGitCommit} from './gitProvider';
|
import GitProvider, {IGitBlame, IGitBlameLines, IGitCommit} from './gitProvider';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
@@ -49,14 +49,16 @@ export default class GitCodeLensProvider implements CodeLensProvider {
|
|||||||
const lenses: CodeLens[] = [];
|
const lenses: CodeLens[] = [];
|
||||||
symbols.forEach(sym => this._provideCodeLens(fileName, document, sym, lenses));
|
symbols.forEach(sym => this._provideCodeLens(fileName, document, sym, lenses));
|
||||||
|
|
||||||
// Check if we have a lens for the whole document -- if not add one
|
if (this._config.location !== CodeLensLocation.Custom || (this._config.locationCustomSymbols || []).find(_ => _.toLowerCase() === 'file')) {
|
||||||
if (!lenses.find(l => l.range.start.line === 0 && l.range.end.line === 0)) {
|
// Check if we have a lens for the whole document -- if not add one
|
||||||
const blameRange = document.validateRange(new Range(0, 1000000, 1000000, 1000000));
|
if (!lenses.find(l => l.range.start.line === 0 && l.range.end.line === 0)) {
|
||||||
if (this._config.recentChange.enabled) {
|
const blameRange = document.validateRange(new Range(0, 1000000, 1000000, 1000000));
|
||||||
lenses.push(new GitRecentChangeCodeLens(this.git, fileName, SymbolKind.File, blameRange, new Range(0, 0, 0, blameRange.start.character)));
|
if (this._config.recentChange.enabled) {
|
||||||
}
|
lenses.push(new GitRecentChangeCodeLens(this.git, fileName, SymbolKind.File, blameRange, new Range(0, 0, 0, blameRange.start.character)));
|
||||||
if (this._config.authors.enabled) {
|
}
|
||||||
lenses.push(new GitAuthorsCodeLens(this.git, fileName, SymbolKind.File, blameRange, new Range(0, 1, 0, blameRange.start.character)));
|
if (this._config.authors.enabled) {
|
||||||
|
lenses.push(new GitAuthorsCodeLens(this.git, fileName, SymbolKind.File, blameRange, new Range(0, 1, 0, blameRange.start.character)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,29 +66,36 @@ export default class GitCodeLensProvider implements CodeLensProvider {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
foo: string; bar: number;
|
private _isValidSymbol(kind: SymbolKind) {
|
||||||
|
switch (this._config.location) {
|
||||||
|
case CodeLensLocation.All:
|
||||||
|
case CodeLensLocation.DocumentAndContainers:
|
||||||
|
switch (kind) {
|
||||||
|
case SymbolKind.File:
|
||||||
|
case SymbolKind.Package:
|
||||||
|
case SymbolKind.Module:
|
||||||
|
case SymbolKind.Namespace:
|
||||||
|
case SymbolKind.Class:
|
||||||
|
case SymbolKind.Interface:
|
||||||
|
return true;
|
||||||
|
case SymbolKind.Constructor:
|
||||||
|
case SymbolKind.Method:
|
||||||
|
case SymbolKind.Function:
|
||||||
|
case SymbolKind.Property:
|
||||||
|
case SymbolKind.Enum:
|
||||||
|
return this._config.location === CodeLensLocation.All;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case CodeLensLocation.Document:
|
||||||
|
return false;
|
||||||
|
case CodeLensLocation.Custom:
|
||||||
|
return !!(this._config.locationCustomSymbols || []).find(_ => _.toLowerCase() === SymbolKind[kind].toLowerCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _provideCodeLens(fileName: string, document: TextDocument, symbol: SymbolInformation, lenses: CodeLens[]): void {
|
private _provideCodeLens(fileName: string, document: TextDocument, symbol: SymbolInformation, lenses: CodeLens[]): void {
|
||||||
let multiline = false;
|
if (!this._isValidSymbol(symbol.kind)) return;
|
||||||
switch (symbol.kind) {
|
|
||||||
case SymbolKind.Package:
|
|
||||||
case SymbolKind.Module:
|
|
||||||
case SymbolKind.Class:
|
|
||||||
case SymbolKind.Interface:
|
|
||||||
case SymbolKind.Constructor:
|
|
||||||
case SymbolKind.Method:
|
|
||||||
case SymbolKind.Function:
|
|
||||||
case SymbolKind.Enum:
|
|
||||||
// HACK for Omnisharp, since it doesn't return full ranges
|
|
||||||
multiline = fileName.endsWith('.cs') || (symbol.location.range.end.line - symbol.location.range.start.line) > 1;
|
|
||||||
break;
|
|
||||||
case SymbolKind.Property:
|
|
||||||
multiline = (symbol.location.range.end.line - symbol.location.range.start.line) > 1;
|
|
||||||
if (!multiline) return;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const line = document.lineAt(symbol.location.range.start);
|
const line = document.lineAt(symbol.location.range.start);
|
||||||
// Make sure there is only 1 lense per line
|
// Make sure there is only 1 lense per line
|
||||||
@@ -109,8 +118,30 @@ export default class GitCodeLensProvider implements CodeLensProvider {
|
|||||||
lenses.push(new GitRecentChangeCodeLens(this.git, fileName, symbol.kind, symbol.location.range, line.range.with(new Position(line.range.start.line, startChar))));
|
lenses.push(new GitRecentChangeCodeLens(this.git, fileName, symbol.kind, symbol.location.range, line.range.with(new Position(line.range.start.line, startChar))));
|
||||||
startChar++;
|
startChar++;
|
||||||
}
|
}
|
||||||
if (multiline && this._config.authors.enabled) {
|
|
||||||
lenses.push(new GitAuthorsCodeLens(this.git, fileName, symbol.kind, symbol.location.range, line.range.with(new Position(line.range.start.line, startChar))));
|
if (this._config.authors.enabled) {
|
||||||
|
// HACK for Omnisharp, since it doesn't return full ranges
|
||||||
|
let multiline = (symbol.location.range.end.line - symbol.location.range.start.line) > 1;
|
||||||
|
if (!multiline && fileName.endsWith('.cs')) {
|
||||||
|
switch (symbol.kind) {
|
||||||
|
case SymbolKind.File:
|
||||||
|
case SymbolKind.Package:
|
||||||
|
case SymbolKind.Module:
|
||||||
|
case SymbolKind.Namespace:
|
||||||
|
case SymbolKind.Class:
|
||||||
|
case SymbolKind.Interface:
|
||||||
|
case SymbolKind.Constructor:
|
||||||
|
case SymbolKind.Method:
|
||||||
|
case SymbolKind.Function:
|
||||||
|
case SymbolKind.Enum:
|
||||||
|
multiline = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (multiline) {
|
||||||
|
lenses.push(new GitAuthorsCodeLens(this.git, fileName, symbol.kind, symbol.location.range, line.range.with(new Position(line.range.start.line, startChar))));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
import {Disposable, ExtensionContext, languages, Location, Position, Range, Uri, workspace} from 'vscode';
|
import {Disposable, DocumentFilter, ExtensionContext, languages, Location, Position, Range, TextDocument, TextEditor, Uri, window, workspace} from 'vscode';
|
||||||
import {DocumentSchemes, WorkspaceState} from './constants';
|
import {DocumentSchemes, WorkspaceState} from './constants';
|
||||||
import {IConfig} from './configuration';
|
import {CodeLensVisibility, IConfig} from './configuration';
|
||||||
import GitCodeLensProvider from './gitCodeLensProvider';
|
import GitCodeLensProvider from './gitCodeLensProvider';
|
||||||
import Git, {GitBlameParserEnricher, GitBlameFormat, GitCommit, IGitAuthor, IGitBlame, IGitBlameCommitLines, IGitBlameLine, IGitBlameLines, IGitCommit} from './git/git';
|
import Git, {GitBlameParserEnricher, GitBlameFormat, GitCommit, IGitAuthor, IGitBlame, IGitBlameCommitLines, IGitBlameLine, IGitBlameLines, IGitCommit} from './git/git';
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
@@ -32,6 +32,7 @@ export default class GitProvider extends Disposable {
|
|||||||
private _config: IConfig;
|
private _config: IConfig;
|
||||||
private _disposable: Disposable;
|
private _disposable: Disposable;
|
||||||
private _codeLensProviderDisposable: Disposable;
|
private _codeLensProviderDisposable: Disposable;
|
||||||
|
private _codeLensProviderSelector: DocumentFilter;
|
||||||
private _gitignore: Promise<ignore.Ignore>;
|
private _gitignore: Promise<ignore.Ignore>;
|
||||||
|
|
||||||
static BlameEmptyPromise = Promise.resolve(<IGitBlame>null);
|
static BlameEmptyPromise = Promise.resolve(<IGitBlame>null);
|
||||||
@@ -84,8 +85,9 @@ export default class GitProvider extends Disposable {
|
|||||||
|
|
||||||
if (!_.isEqual(config.codeLens, this._config && this._config.codeLens)) {
|
if (!_.isEqual(config.codeLens, this._config && this._config.codeLens)) {
|
||||||
this._codeLensProviderDisposable && this._codeLensProviderDisposable.dispose();
|
this._codeLensProviderDisposable && this._codeLensProviderDisposable.dispose();
|
||||||
if (config.codeLens.recentChange.enabled || config.codeLens.authors.enabled) {
|
if (config.codeLens.visibility === CodeLensVisibility.Auto && (config.codeLens.recentChange.enabled || config.codeLens.authors.enabled)) {
|
||||||
this._codeLensProviderDisposable = languages.registerCodeLensProvider(GitCodeLensProvider.selector, new GitCodeLensProvider(this.context, this));
|
this._codeLensProviderSelector = GitCodeLensProvider.selector;
|
||||||
|
this._codeLensProviderDisposable = languages.registerCodeLensProvider(this._codeLensProviderSelector, new GitCodeLensProvider(this.context, this));
|
||||||
} else {
|
} else {
|
||||||
this._codeLensProviderDisposable = null;
|
this._codeLensProviderDisposable = null;
|
||||||
}
|
}
|
||||||
@@ -99,11 +101,11 @@ export default class GitProvider extends Disposable {
|
|||||||
const disposables: Disposable[] = [];
|
const disposables: Disposable[] = [];
|
||||||
|
|
||||||
// TODO: Maybe stop clearing on close and instead limit to a certain number of recent blames
|
// TODO: Maybe stop clearing on close and instead limit to a certain number of recent blames
|
||||||
disposables.push(workspace.onDidCloseTextDocument(d => this._removeCachedBlame(d.fileName, RemoveCacheReason.DocumentClosed)));
|
disposables.push(workspace.onDidCloseTextDocument(d => this._removeCachedBlame(d, RemoveCacheReason.DocumentClosed)));
|
||||||
|
|
||||||
const removeCachedBlameFn = _.debounce(this._removeCachedBlame.bind(this), 2500);
|
const removeCachedBlameFn = _.debounce(this._removeCachedBlame.bind(this), 2500);
|
||||||
disposables.push(workspace.onDidSaveTextDocument(d => removeCachedBlameFn(d.fileName, RemoveCacheReason.DocumentSaved)));
|
disposables.push(workspace.onDidSaveTextDocument(d => removeCachedBlameFn(d, RemoveCacheReason.DocumentSaved)));
|
||||||
disposables.push(workspace.onDidChangeTextDocument(e => removeCachedBlameFn(e.document.fileName, RemoveCacheReason.DocumentChanged)));
|
disposables.push(workspace.onDidChangeTextDocument(e => removeCachedBlameFn(e.document, RemoveCacheReason.DocumentChanged)));
|
||||||
|
|
||||||
this._blameCacheDisposable = Disposable.from(...disposables);
|
this._blameCacheDisposable = Disposable.from(...disposables);
|
||||||
} else {
|
} else {
|
||||||
@@ -121,10 +123,11 @@ export default class GitProvider extends Disposable {
|
|||||||
return fileName.toLowerCase();
|
return fileName.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _removeCachedBlame(fileName: string, reason: RemoveCacheReason) {
|
private _removeCachedBlame(document: TextDocument, reason: RemoveCacheReason) {
|
||||||
if (!this.UseCaching) return;
|
if (!this.UseCaching) return;
|
||||||
|
if (document.uri.scheme != DocumentSchemes.File) return;
|
||||||
|
|
||||||
fileName = Git.normalizePath(fileName);
|
const fileName = Git.normalizePath(document.fileName);
|
||||||
|
|
||||||
const cacheKey = this._getBlameCacheKey(fileName);
|
const cacheKey = this._getBlameCacheKey(fileName);
|
||||||
if (reason === RemoveCacheReason.DocumentClosed) {
|
if (reason === RemoveCacheReason.DocumentClosed) {
|
||||||
@@ -300,6 +303,35 @@ export default class GitProvider extends Disposable {
|
|||||||
return Git.getVersionedFileText(fileName, repoPath, sha);
|
return Git.getVersionedFileText(fileName, repoPath, sha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleCodeLens(editor: TextEditor) {
|
||||||
|
if (this._config.codeLens.visibility !== CodeLensVisibility.OnDemand ||
|
||||||
|
(!this._config.codeLens.recentChange.enabled && !this._config.codeLens.authors.enabled)) return;
|
||||||
|
|
||||||
|
if (this._codeLensProviderDisposable) {
|
||||||
|
this._codeLensProviderDisposable.dispose();
|
||||||
|
|
||||||
|
if (editor.document.fileName === (this._codeLensProviderSelector && this._codeLensProviderSelector.pattern)) {
|
||||||
|
this._codeLensProviderDisposable = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const disposables: Disposable[] = [];
|
||||||
|
|
||||||
|
this._codeLensProviderSelector = <DocumentFilter>{ scheme: DocumentSchemes.File, pattern: editor.document.fileName };
|
||||||
|
|
||||||
|
disposables.push(languages.registerCodeLensProvider(this._codeLensProviderSelector, new GitCodeLensProvider(this.context, this)));
|
||||||
|
|
||||||
|
disposables.push(window.onDidChangeActiveTextEditor(e => {
|
||||||
|
if (e.viewColumn && e.document !== editor.document) {
|
||||||
|
this._codeLensProviderDisposable && this._codeLensProviderDisposable.dispose();
|
||||||
|
this._codeLensProviderDisposable = null;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
this._codeLensProviderDisposable = Disposable.from(...disposables);
|
||||||
|
}
|
||||||
|
|
||||||
static fromBlameUri(uri: Uri): IGitBlameUriData {
|
static fromBlameUri(uri: Uri): IGitBlameUriData {
|
||||||
if (uri.scheme !== DocumentSchemes.GitBlame) throw new Error(`fromGitUri(uri=${uri}) invalid scheme`);
|
if (uri.scheme !== DocumentSchemes.GitBlame) throw new Error(`fromGitUri(uri=${uri}) invalid scheme`);
|
||||||
const data = GitProvider._fromGitUri<IGitBlameUriData>(uri);
|
const data = GitProvider._fromGitUri<IGitBlameUriData>(uri);
|
||||||
|
|||||||
Reference in New Issue
Block a user