diff --git a/src/annotations/annotations.ts b/src/annotations/annotations.ts index 556987f..156e0f3 100644 --- a/src/annotations/annotations.ts +++ b/src/annotations/annotations.ts @@ -4,11 +4,10 @@ import { MarkdownString, ThemableDecorationAttachmentRenderOptions, ThemableDecorationRenderOptions, - ThemeColor, - workspace + ThemeColor } from 'vscode'; import { DiffWithCommand, ShowQuickCommitDetailsCommand } from '../commands'; -import { FileAnnotationType } from '../configuration'; +import { configuration, FileAnnotationType } from '../configuration'; import { GlyphChars } from '../constants'; import { Container } from '../container'; import { @@ -276,7 +275,7 @@ export class Annotations { let width; if (chars >= 0) { - const spacing = workspace.getConfiguration('editor').get('letterSpacing'); + const spacing = configuration.getAny('editor.letterSpacing'); if (spacing != null && spacing !== 0) { width = `calc(${chars}ch + ${Math.round(chars * spacing)}px)`; } diff --git a/src/configuration.ts b/src/configuration.ts index 2904ddf..487609d 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -38,13 +38,22 @@ export class Configuration { return this._onDidChange.event; } + private _onDidChangeAny = new EventEmitter(); + get onDidChangeAny(): Event { + return this._onDidChange.event; + } + private _onWillChange = new EventEmitter(); get onWillChange(): Event { return this._onWillChange.event; } private onConfigurationChanged(e: ConfigurationChangeEvent) { - if (!e.affectsConfiguration(extensionId, null!)) return; + if (!e.affectsConfiguration(extensionId, null!)) { + this._onDidChangeAny.fire(e); + + return; + } const evt: ConfigurationWillChangeEvent = { change: e @@ -72,6 +81,12 @@ export class Configuration { .get(section === undefined ? extensionId : section, defaultValue)!; } + getAny(section: string, resource?: Uri | null, defaultValue?: T) { + return defaultValue === undefined + ? workspace.getConfiguration(undefined, resource!).get(section)! + : workspace.getConfiguration(undefined, resource!).get(section, defaultValue)!; + } + changed(e: ConfigurationChangeEvent, section: string, resource?: Uri | null) { return e.affectsConfiguration(`${extensionId}.${section}`, resource!); } @@ -86,6 +101,10 @@ export class Configuration { .inspect(section === undefined ? extensionId : section); } + inspectAny(section: string, resource?: Uri | null) { + return workspace.getConfiguration(undefined, resource!).inspect(section); + } + async migrate( from: string, to: string, @@ -228,6 +247,12 @@ export class Configuration { .update(section, value, target); } + updateAny(section: string, value: any, target: ConfigurationTarget, resource?: Uri | null) { + return workspace + .getConfiguration(undefined, target === ConfigurationTarget.Global ? undefined : resource!) + .update(section, value, target); + } + async updateEffective(section: string, value: any, resource: Uri | null = null) { const inspect = await configuration.inspect(section, resource)!; if (inspect.workspaceFolderValue !== undefined) { diff --git a/src/git/gitService.ts b/src/git/gitService.ts index 463c6ae..bb15935 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -147,7 +147,7 @@ export class GitService implements Disposable { gitPath = gitApi.git.path; } - await Git.setOrFindGitPath(gitPath || workspace.getConfiguration('git').get('path')); + await Git.setOrFindGitPath(gitPath || configuration.getAny('git.path')); } get useCaching() { @@ -306,8 +306,8 @@ export class GitService implements Disposable { // Get any specified excludes -- this is a total hack, but works for some simple cases and something is better than nothing :) let excludes = { - ...workspace.getConfiguration('files', uri).get<{ [key: string]: boolean }>('exclude', {}), - ...workspace.getConfiguration('search', uri).get<{ [key: string]: boolean }>('exclude', {}) + ...configuration.getAny<{ [key: string]: boolean }>('files.exclude', uri, {}), + ...configuration.getAny<{ [key: string]: boolean }>('search.exclude', uri, {}) }; const excludedPaths = [ @@ -2613,7 +2613,7 @@ export class GitService implements Disposable { static getEncoding(uri: Uri): string; static getEncoding(repoPathOrUri: string | Uri, fileName?: string): string { const uri = typeof repoPathOrUri === 'string' ? GitUri.resolveToUri(fileName!, repoPathOrUri) : repoPathOrUri; - return Git.getEncoding(workspace.getConfiguration('files', uri).get('encoding')); + return Git.getEncoding(configuration.getAny('files.encoding', uri)); } static deletedOrMissingSha = Git.deletedOrMissingSha; diff --git a/src/telemetry.ts b/src/telemetry.ts index bf1d5ba..db9c25a 100644 --- a/src/telemetry.ts +++ b/src/telemetry.ts @@ -11,7 +11,7 @@ // static configure(key: string) { // if (!configuration.get(configuration.name('advanced')('telemetry')('enabled').value) || -// !workspace.getConfiguration('telemetry').get('enableTelemetry', true)) { +// !configuration.getAny('telemetry.enableTelemetry', undefined, true)) { // return; // }