Browse Source

Changes git code lens custom locations

Reworks settings to easily include/exclude symbols for git code lens
main
Eric Amodio 7 years ago
parent
commit
d22deb7475
6 changed files with 31 additions and 31 deletions
  1. +6
    -0
      CHANGELOG.md
  2. +2
    -2
      README.md
  3. +3
    -4
      package.json
  4. +1
    -2
      src/configuration.ts
  5. +0
    -3
      src/extension.ts
  6. +19
    -20
      src/gitCodeLensProvider.ts

+ 6
- 0
CHANGELOG.md View File

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Changed
- Changes `gitlens.codeLens.customLocationSymbols` setting to both include and exclude (using a `!` prefix) symbols and therefore is always applied
### Removed
- Removes `Custom` from the `gitlens.codeLens.locations` setting as it wasn't really required
- Removes properties (symbol `Property`) from being included in the `Blocks` option of the `gitlens.codeLens.locations` setting -- can be easily re-added by setting `"gitlens.codeLens.customLocationSymbols": [ "Property" ]` if desired
## [5.5.0] - 2017-10-09
### Added

+ 2
- 2
README.md View File

@ -351,8 +351,8 @@ GitLens is highly customizable and provides many configuration settings to allow
|`gitlens.codeLens.recentChange.command`|Specifies the command to be executed when the `recent change` code lens is clicked<br />`gitlens.toggleFileBlame` - toggles file blame annotations<br />`gitlens.diffWithPrevious` - compares the current committed file with the previous commit<br />`gitlens.showQuickCommitDetails` - shows a commit details quick pick<br />`gitlens.showQuickCommitFileDetails` - shows a commit file details quick pick<br />`gitlens.showQuickFileHistory` - shows a file history quick pick<br />`gitlens.showQuickRepoHistory` - shows a branch history quick pick
|`gitlens.codeLens.authors.enabled`|Specifies whether or not to show an `authors` code lens showing number of authors of the file or code block and the most prominent author (if there is more than one)
|`gitlens.codeLens.authors.command`|Specifies the command to be executed when the `authors` code lens is clicked<br />`gitlens.toggleFileBlame` - toggles file blame annotations<br />`gitlens.diffWithPrevious` - compares the current committed file with the previous commit<br />`gitlens.showQuickCommitDetails` - shows a commit details quick pick<br />`gitlens.showQuickCommitFileDetails` - shows a commit file details quick pick<br />`gitlens.showQuickFileHistory` - shows a file history quick pick<br />`gitlens.showQuickRepoHistory` - shows a branch history quick pick
|`gitlens.codeLens.locations`|Specifies where Git code lens will be shown in the document<br />`document` - adds code lens at the top of the document<br />`containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)<br />`blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines<br />`custom` - adds code lens at the start of symbols contained in `gitlens.codeLens.locationCustomSymbols`
|`gitlens.codeLens.customLocationSymbols`|Specifies the set of document symbols where Git code lens will be shown in the document
|`gitlens.codeLens.locations`|Specifies where Git code lens will be shown in the document<br />`document` - adds code lens at the top of the document<br />`containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)<br />`blocks` - adds code lens at the start of block-like symbols (functions, methods, etc) lines
|`gitlens.codeLens.customLocationSymbols`|Specifies a set of document symbols where Git code lens will or will not be shown in the document<br />Prefix with `!` to not show Git code lens for the symbol<br />Must be a member of `SymbolKind`
|`gitlens.codeLens.perLanguageLocations`|Specifies where Git code lens will be shown in the document for the specified languages
### GitLens Custom View Settings

+ 3
- 4
package.json View File

@ -292,14 +292,13 @@
"enum": [
"document",
"containers",
"blocks",
"custom"
"blocks"
]
},
"minItems": 1,
"maxItems": 4,
"uniqueItems": true,
"description": "Specifies where Git code lens will be shown in the document\n `document` - adds code lens at the top of the document\n `containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)\n `blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines\n `custom` - adds code lens at the start of symbols contained in `gitlens.codeLens.locationCustomSymbols`"
"description": "Specifies where Git code lens will be shown in the document\n `document` - adds code lens at the top of the document\n `containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)\n `blocks` - adds code lens at the start of block-like symbols (functions, methods, etc) lines"
},
"gitlens.codeLens.customLocationSymbols": {
"type": "array",
@ -307,7 +306,7 @@
"type": "string"
},
"uniqueItems": true,
"description": "Specifies the set of document symbols where Git code lens will be shown in the document\nMust be a member of `SymbolKind`"
"description": "Specifies a set of document symbols where Git code lens will or will not be shown in the document\nPrefix with `!` to not show Git code lens for the symbol\nMust be a member of `SymbolKind`"
},
"gitlens.codeLens.perLanguageLocations": {
"type": "array",

+ 1
- 2
src/configuration.ts View File

@ -18,8 +18,7 @@ export enum CodeLensCommand {
export enum CodeLensLocations {
Document = 'document',
Containers = 'containers',
Blocks = 'blocks',
Custom = 'custom'
Blocks = 'blocks'
}
export enum LineHighlightLocations {

+ 0
- 3
src/extension.ts View File

@ -156,9 +156,6 @@ async function migrateSettings(context: ExtensionContext) {
case 'document':
await cfg.update('codeLens.locations', [CodeLensLocations.Document], true);
break;
case 'custom':
await cfg.update('codeLens.locations', [CodeLensLocations.Custom], true);
break;
}
if (prevCfg.codeLens.locationCustomSymbols != null) {

+ 19
- 20
src/gitCodeLensProvider.ts View File

@ -64,6 +64,10 @@ export class GitCodeLensProvider implements CodeLensProvider {
} as ICodeLensLanguageLocation;
}
languageLocations.customSymbols = languageLocations.customSymbols != null
? languageLocations.customSymbols = languageLocations.customSymbols.map(_ => _.toLowerCase())
: [];
const lenses: CodeLens[] = [];
const gitUri = await GitUri.fromUri(document.uri, this.git);
@ -88,8 +92,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
symbols.forEach(sym => this._provideCodeLens(gitUri, document, sym, languageLocations!, blame!, lenses));
}
if (languageLocations.locations.includes(CodeLensLocations.Document) ||
(languageLocations.locations.includes(CodeLensLocations.Custom) && (languageLocations.customSymbols || []).find(_ => _.toLowerCase() === 'file'))) {
if ((languageLocations.locations.includes(CodeLensLocations.Document) || languageLocations.customSymbols.includes('file')) && !languageLocations.customSymbols.includes('!file')) {
// Check if we have a lens for the whole document -- if not add one
if (!lenses.find(l => l.range.start.line === 0 && l.range.end.line === 0)) {
const blameRange = document.validateRange(new Range(0, 1000000, 1000000, 1000000));
@ -116,13 +119,11 @@ export class GitCodeLensProvider implements CodeLensProvider {
let valid = false;
let range: Range | undefined;
const symbolName = SymbolKind[symbol.kind].toLowerCase();
switch (symbol.kind) {
case SymbolKind.File:
if (languageLocation.locations.includes(CodeLensLocations.Containers)) {
valid = true;
}
else if (languageLocation.locations.includes(CodeLensLocations.Custom)) {
valid = !!(languageLocation.customSymbols || []).find(_ => _.toLowerCase() === SymbolKind[symbol.kind].toLowerCase());
if (languageLocation.locations.includes(CodeLensLocations.Containers) || languageLocation.customSymbols!.includes(symbolName)) {
valid = !languageLocation.customSymbols!.includes(`!${symbolName}`);
}
if (valid) {
@ -132,11 +133,8 @@ export class GitCodeLensProvider implements CodeLensProvider {
break;
case SymbolKind.Package:
if (languageLocation.locations.includes(CodeLensLocations.Containers)) {
valid = true;
}
else if (languageLocation.locations.includes(CodeLensLocations.Custom)) {
valid = !!(languageLocation.customSymbols || []).find(_ => _.toLowerCase() === SymbolKind[symbol.kind].toLowerCase());
if (languageLocation.locations.includes(CodeLensLocations.Containers) || languageLocation.customSymbols!.includes(symbolName)) {
valid = !languageLocation.customSymbols!.includes(`!${symbolName}`);
}
if (valid) {
@ -152,8 +150,8 @@ export class GitCodeLensProvider implements CodeLensProvider {
case SymbolKind.Module:
case SymbolKind.Namespace:
case SymbolKind.Struct:
if (languageLocation.locations.includes(CodeLensLocations.Containers)) {
valid = true;
if (languageLocation.locations.includes(CodeLensLocations.Containers) || languageLocation.customSymbols!.includes(symbolName)) {
valid = !languageLocation.customSymbols!.includes(`!${symbolName}`);
}
break;
@ -161,15 +159,16 @@ export class GitCodeLensProvider implements CodeLensProvider {
case SymbolKind.Enum:
case SymbolKind.Function:
case SymbolKind.Method:
case SymbolKind.Property:
if (languageLocation.locations.includes(CodeLensLocations.Blocks)) {
valid = true;
if (languageLocation.locations.includes(CodeLensLocations.Blocks) || languageLocation.customSymbols!.includes(symbolName)) {
valid = !languageLocation.customSymbols!.includes(`!${symbolName}`);
}
break;
}
if (!valid && languageLocation.locations.includes(CodeLensLocations.Custom)) {
valid = !!(languageLocation.customSymbols || []).find(_ => _.toLowerCase() === SymbolKind[symbol.kind].toLowerCase());
default:
if (languageLocation.customSymbols!.includes(symbolName)) {
valid = !languageLocation.customSymbols!.includes(`!${symbolName}`);
}
break;
}
return valid ? range || symbol.location.range : undefined;

Loading…
Cancel
Save