Skip to content

Commit d22deb7

Browse files
committed
Changes git code lens custom locations
Reworks settings to easily include/exclude symbols for git code lens
1 parent a632057 commit d22deb7

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
8+
### Changed
9+
- Changes `gitlens.codeLens.customLocationSymbols` setting to both include and exclude (using a `!` prefix) symbols and therefore is always applied
10+
11+
### Removed
12+
- Removes `Custom` from the `gitlens.codeLens.locations` setting as it wasn't really required
13+
- 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
814

915
## [5.5.0] - 2017-10-09
1016
### Added

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ GitLens is highly customizable and provides many configuration settings to allow
351351
|`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
352352
|`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)
353353
|`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
354-
|`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`
355-
|`gitlens.codeLens.customLocationSymbols`|Specifies the set of document symbols where Git code lens will be shown in the document
354+
|`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
355+
|`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`
356356
|`gitlens.codeLens.perLanguageLocations`|Specifies where Git code lens will be shown in the document for the specified languages
357357

358358
### GitLens Custom View Settings

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,22 +292,21 @@
292292
"enum": [
293293
"document",
294294
"containers",
295-
"blocks",
296-
"custom"
295+
"blocks"
297296
]
298297
},
299298
"minItems": 1,
300299
"maxItems": 4,
301300
"uniqueItems": true,
302-
"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`"
301+
"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"
303302
},
304303
"gitlens.codeLens.customLocationSymbols": {
305304
"type": "array",
306305
"items": {
307306
"type": "string"
308307
},
309308
"uniqueItems": true,
310-
"description": "Specifies the set of document symbols where Git code lens will be shown in the document\nMust be a member of `SymbolKind`"
309+
"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`"
311310
},
312311
"gitlens.codeLens.perLanguageLocations": {
313312
"type": "array",

src/configuration.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ export enum CodeLensCommand {
1818
export enum CodeLensLocations {
1919
Document = 'document',
2020
Containers = 'containers',
21-
Blocks = 'blocks',
22-
Custom = 'custom'
21+
Blocks = 'blocks'
2322
}
2423

2524
export enum LineHighlightLocations {

src/extension.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ async function migrateSettings(context: ExtensionContext) {
156156
case 'document':
157157
await cfg.update('codeLens.locations', [CodeLensLocations.Document], true);
158158
break;
159-
case 'custom':
160-
await cfg.update('codeLens.locations', [CodeLensLocations.Custom], true);
161-
break;
162159
}
163160

164161
if (prevCfg.codeLens.locationCustomSymbols != null) {

src/gitCodeLensProvider.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export class GitCodeLensProvider implements CodeLensProvider {
6464
} as ICodeLensLanguageLocation;
6565
}
6666

67+
languageLocations.customSymbols = languageLocations.customSymbols != null
68+
? languageLocations.customSymbols = languageLocations.customSymbols.map(_ => _.toLowerCase())
69+
: [];
70+
6771
const lenses: CodeLens[] = [];
6872

6973
const gitUri = await GitUri.fromUri(document.uri, this.git);
@@ -88,8 +92,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
8892
symbols.forEach(sym => this._provideCodeLens(gitUri, document, sym, languageLocations!, blame!, lenses));
8993
}
9094

91-
if (languageLocations.locations.includes(CodeLensLocations.Document) ||
92-
(languageLocations.locations.includes(CodeLensLocations.Custom) && (languageLocations.customSymbols || []).find(_ => _.toLowerCase() === 'file'))) {
95+
if ((languageLocations.locations.includes(CodeLensLocations.Document) || languageLocations.customSymbols.includes('file')) && !languageLocations.customSymbols.includes('!file')) {
9396
// Check if we have a lens for the whole document -- if not add one
9497
if (!lenses.find(l => l.range.start.line === 0 && l.range.end.line === 0)) {
9598
const blameRange = document.validateRange(new Range(0, 1000000, 1000000, 1000000));
@@ -116,13 +119,11 @@ export class GitCodeLensProvider implements CodeLensProvider {
116119
let valid = false;
117120
let range: Range | undefined;
118121

122+
const symbolName = SymbolKind[symbol.kind].toLowerCase();
119123
switch (symbol.kind) {
120124
case SymbolKind.File:
121-
if (languageLocation.locations.includes(CodeLensLocations.Containers)) {
122-
valid = true;
123-
}
124-
else if (languageLocation.locations.includes(CodeLensLocations.Custom)) {
125-
valid = !!(languageLocation.customSymbols || []).find(_ => _.toLowerCase() === SymbolKind[symbol.kind].toLowerCase());
125+
if (languageLocation.locations.includes(CodeLensLocations.Containers) || languageLocation.customSymbols!.includes(symbolName)) {
126+
valid = !languageLocation.customSymbols!.includes(`!${symbolName}`);
126127
}
127128

128129
if (valid) {
@@ -132,11 +133,8 @@ export class GitCodeLensProvider implements CodeLensProvider {
132133
break;
133134

134135
case SymbolKind.Package:
135-
if (languageLocation.locations.includes(CodeLensLocations.Containers)) {
136-
valid = true;
137-
}
138-
else if (languageLocation.locations.includes(CodeLensLocations.Custom)) {
139-
valid = !!(languageLocation.customSymbols || []).find(_ => _.toLowerCase() === SymbolKind[symbol.kind].toLowerCase());
136+
if (languageLocation.locations.includes(CodeLensLocations.Containers) || languageLocation.customSymbols!.includes(symbolName)) {
137+
valid = !languageLocation.customSymbols!.includes(`!${symbolName}`);
140138
}
141139

142140
if (valid) {
@@ -152,24 +150,25 @@ export class GitCodeLensProvider implements CodeLensProvider {
152150
case SymbolKind.Module:
153151
case SymbolKind.Namespace:
154152
case SymbolKind.Struct:
155-
if (languageLocation.locations.includes(CodeLensLocations.Containers)) {
156-
valid = true;
153+
if (languageLocation.locations.includes(CodeLensLocations.Containers) || languageLocation.customSymbols!.includes(symbolName)) {
154+
valid = !languageLocation.customSymbols!.includes(`!${symbolName}`);
157155
}
158156
break;
159157

160158
case SymbolKind.Constructor:
161159
case SymbolKind.Enum:
162160
case SymbolKind.Function:
163161
case SymbolKind.Method:
164-
case SymbolKind.Property:
165-
if (languageLocation.locations.includes(CodeLensLocations.Blocks)) {
166-
valid = true;
162+
if (languageLocation.locations.includes(CodeLensLocations.Blocks) || languageLocation.customSymbols!.includes(symbolName)) {
163+
valid = !languageLocation.customSymbols!.includes(`!${symbolName}`);
167164
}
168165
break;
169-
}
170166

171-
if (!valid && languageLocation.locations.includes(CodeLensLocations.Custom)) {
172-
valid = !!(languageLocation.customSymbols || []).find(_ => _.toLowerCase() === SymbolKind[symbol.kind].toLowerCase());
167+
default:
168+
if (languageLocation.customSymbols!.includes(symbolName)) {
169+
valid = !languageLocation.customSymbols!.includes(`!${symbolName}`);
170+
}
171+
break;
173172
}
174173

175174
return valid ? range || symbol.location.range : undefined;

0 commit comments

Comments
 (0)