Skip to content

Commit 11dc8f3

Browse files
committed
Makes scopes optional on codeLens.scopesByLanguage
1 parent cbb6986 commit 11dc8f3

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@
275275
"items": {
276276
"type": "object",
277277
"required": [
278-
"language",
279-
"scopes"
278+
"language"
280279
],
281280
"properties": {
282281
"language": {

src/gitCodeLensProvider.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,14 @@ export class GitCodeLensProvider implements CodeLensProvider {
9090
let languageScope = cfg.scopesByLanguage && cfg.scopesByLanguage.find(ll => ll.language !== undefined && ll.language.toLowerCase() === document.languageId);
9191
if (languageScope == null) {
9292
languageScope = {
93-
language: undefined,
94-
scopes: cfg.scopes,
95-
symbolScopes: cfg.symbolScopes
93+
language: undefined
9694
} as CodeLensLanguageScope;
9795
}
98-
else {
99-
if (languageScope.scopes === undefined) {
100-
languageScope.scopes = cfg.scopes;
101-
}
102-
if (languageScope.symbolScopes === undefined) {
103-
languageScope.symbolScopes = cfg.symbolScopes;
104-
}
96+
if (languageScope.scopes == null) {
97+
languageScope.scopes = cfg.scopes;
98+
}
99+
if (languageScope.symbolScopes == null) {
100+
languageScope.symbolScopes = cfg.symbolScopes;
105101
}
106102

107103
languageScope.symbolScopes = languageScope.symbolScopes != null
@@ -148,7 +144,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
148144

149145
if (symbols !== undefined) {
150146
Logger.log('GitCodeLensProvider.provideCodeLenses:', `${symbols.length} symbol(s) found`);
151-
symbols.forEach(sym => this.provideCodeLens(lenses, document, sym, languageScope!, documentRangeFn, blame, gitUri, cfg, dirty, dirtyCommand));
147+
symbols.forEach(sym => this.provideCodeLens(lenses, document, sym, languageScope as Required<CodeLensLanguageScope>, documentRangeFn, blame, gitUri, cfg, dirty, dirtyCommand));
152148
}
153149

154150
if ((languageScope.scopes.includes(CodeLensScopes.Document) || languageScope.symbolScopes.includes('file')) && !languageScope.symbolScopes.includes('!file')) {
@@ -196,7 +192,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
196192
return lenses;
197193
}
198194

199-
private validateSymbolAndGetBlameRange(symbol: SymbolInformation, languageScope: CodeLensLanguageScope, documentRangeFn: () => Range): Range | undefined {
195+
private validateSymbolAndGetBlameRange(symbol: SymbolInformation, languageScope: Required<CodeLensLanguageScope>, documentRangeFn: () => Range): Range | undefined {
200196
let valid = false;
201197
let range: Range | undefined;
202198

@@ -255,7 +251,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
255251
return valid ? range || symbol.location.range : undefined;
256252
}
257253

258-
private provideCodeLens(lenses: CodeLens[], document: TextDocument, symbol: SymbolInformation, languageScope: CodeLensLanguageScope, documentRangeFn: () => Range, blame: GitBlame | undefined, gitUri: GitUri | undefined, cfg: ICodeLensConfig, dirty: boolean, dirtyCommand: Command | undefined): void {
254+
private provideCodeLens(lenses: CodeLens[], document: TextDocument, symbol: SymbolInformation, languageScope: Required<CodeLensLanguageScope>, documentRangeFn: () => Range, blame: GitBlame | undefined, gitUri: GitUri | undefined, cfg: ICodeLensConfig, dirty: boolean, dirtyCommand: Command | undefined): void {
259255
const blameRange = this.validateSymbolAndGetBlameRange(symbol, languageScope, documentRangeFn);
260256
if (blameRange === undefined) return;
261257

src/ui/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export enum CodeLensCommand {
1616

1717
export interface CodeLensLanguageScope {
1818
language: string | undefined;
19-
scopes: CodeLensScopes[];
19+
scopes?: CodeLensScopes[];
2020
symbolScopes?: string[];
2121
}
2222

0 commit comments

Comments
 (0)