Skip to content

Commit

Permalink
Replaces usages of workspace.getConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed May 22, 2019
1 parent e683d14 commit 48ffc9f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/annotations/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -276,7 +275,7 @@ export class Annotations {

let width;
if (chars >= 0) {
const spacing = workspace.getConfiguration('editor').get<number>('letterSpacing');
const spacing = configuration.getAny<number>('editor.letterSpacing');
if (spacing != null && spacing !== 0) {
width = `calc(${chars}ch + ${Math.round(chars * spacing)}px)`;
}
Expand Down
27 changes: 26 additions & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,22 @@ export class Configuration {
return this._onDidChange.event;
}

private _onDidChangeAny = new EventEmitter<ConfigurationChangeEvent>();
get onDidChangeAny(): Event<ConfigurationChangeEvent> {
return this._onDidChange.event;
}

private _onWillChange = new EventEmitter<ConfigurationWillChangeEvent>();
get onWillChange(): Event<ConfigurationWillChangeEvent> {
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
Expand Down Expand Up @@ -72,6 +81,12 @@ export class Configuration {
.get<T>(section === undefined ? extensionId : section, defaultValue)!;
}

getAny<T>(section: string, resource?: Uri | null, defaultValue?: T) {
return defaultValue === undefined
? workspace.getConfiguration(undefined, resource!).get<T>(section)!
: workspace.getConfiguration(undefined, resource!).get<T>(section, defaultValue)!;
}

changed(e: ConfigurationChangeEvent, section: string, resource?: Uri | null) {
return e.affectsConfiguration(`${extensionId}.${section}`, resource!);
}
Expand All @@ -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<TFrom, TTo>(
from: string,
to: string,
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/git/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class GitService implements Disposable {
gitPath = gitApi.git.path;
}

await Git.setOrFindGitPath(gitPath || workspace.getConfiguration('git').get<string>('path'));
await Git.setOrFindGitPath(gitPath || configuration.getAny<string>('git.path'));
}

get useCaching() {
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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<string>('encoding'));
return Git.getEncoding(configuration.getAny<string>('files.encoding', uri));
}

static deletedOrMissingSha = Git.deletedOrMissingSha;
Expand Down
2 changes: 1 addition & 1 deletion src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// static configure(key: string) {
// if (!configuration.get<boolean>(configuration.name('advanced')('telemetry')('enabled').value) ||
// !workspace.getConfiguration('telemetry').get<boolean>('enableTelemetry', true)) {
// !configuration.getAny<boolean>('telemetry.enableTelemetry', undefined, true)) {
// return;
// }

Expand Down

0 comments on commit 48ffc9f

Please sign in to comment.