From 11dc8f37f780e1b5a3b86cd77a45e08077bbad42 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 19 Jun 2018 11:11:26 -0400 Subject: [PATCH] Makes scopes optional on codeLens.scopesByLanguage --- package.json | 3 +-- src/gitCodeLensProvider.ts | 22 +++++++++------------- src/ui/config.ts | 2 +- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 2f21207..ea66f25 100644 --- a/package.json +++ b/package.json @@ -275,8 +275,7 @@ "items": { "type": "object", "required": [ - "language", - "scopes" + "language" ], "properties": { "language": { diff --git a/src/gitCodeLensProvider.ts b/src/gitCodeLensProvider.ts index a91dd88..7d9f465 100644 --- a/src/gitCodeLensProvider.ts +++ b/src/gitCodeLensProvider.ts @@ -90,18 +90,14 @@ export class GitCodeLensProvider implements CodeLensProvider { let languageScope = cfg.scopesByLanguage && cfg.scopesByLanguage.find(ll => ll.language !== undefined && ll.language.toLowerCase() === document.languageId); if (languageScope == null) { languageScope = { - language: undefined, - scopes: cfg.scopes, - symbolScopes: cfg.symbolScopes + language: undefined } as CodeLensLanguageScope; } - else { - if (languageScope.scopes === undefined) { - languageScope.scopes = cfg.scopes; - } - if (languageScope.symbolScopes === undefined) { - languageScope.symbolScopes = cfg.symbolScopes; - } + if (languageScope.scopes == null) { + languageScope.scopes = cfg.scopes; + } + if (languageScope.symbolScopes == null) { + languageScope.symbolScopes = cfg.symbolScopes; } languageScope.symbolScopes = languageScope.symbolScopes != null @@ -148,7 +144,7 @@ export class GitCodeLensProvider implements CodeLensProvider { if (symbols !== undefined) { Logger.log('GitCodeLensProvider.provideCodeLenses:', `${symbols.length} symbol(s) found`); - symbols.forEach(sym => this.provideCodeLens(lenses, document, sym, languageScope!, documentRangeFn, blame, gitUri, cfg, dirty, dirtyCommand)); + symbols.forEach(sym => this.provideCodeLens(lenses, document, sym, languageScope as Required, documentRangeFn, blame, gitUri, cfg, dirty, dirtyCommand)); } if ((languageScope.scopes.includes(CodeLensScopes.Document) || languageScope.symbolScopes.includes('file')) && !languageScope.symbolScopes.includes('!file')) { @@ -196,7 +192,7 @@ export class GitCodeLensProvider implements CodeLensProvider { return lenses; } - private validateSymbolAndGetBlameRange(symbol: SymbolInformation, languageScope: CodeLensLanguageScope, documentRangeFn: () => Range): Range | undefined { + private validateSymbolAndGetBlameRange(symbol: SymbolInformation, languageScope: Required, documentRangeFn: () => Range): Range | undefined { let valid = false; let range: Range | undefined; @@ -255,7 +251,7 @@ export class GitCodeLensProvider implements CodeLensProvider { return valid ? range || symbol.location.range : undefined; } - 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 { + private provideCodeLens(lenses: CodeLens[], document: TextDocument, symbol: SymbolInformation, languageScope: Required, documentRangeFn: () => Range, blame: GitBlame | undefined, gitUri: GitUri | undefined, cfg: ICodeLensConfig, dirty: boolean, dirtyCommand: Command | undefined): void { const blameRange = this.validateSymbolAndGetBlameRange(symbol, languageScope, documentRangeFn); if (blameRange === undefined) return; diff --git a/src/ui/config.ts b/src/ui/config.ts index 992ed57..14f62aa 100644 --- a/src/ui/config.ts +++ b/src/ui/config.ts @@ -16,7 +16,7 @@ export enum CodeLensCommand { export interface CodeLensLanguageScope { language: string | undefined; - scopes: CodeLensScopes[]; + scopes?: CodeLensScopes[]; symbolScopes?: string[]; }