Browse Source

Replaces usages of workspace.getConfiguration

main
Eric Amodio 5 years ago
parent
commit
48ffc9fa87
4 changed files with 34 additions and 10 deletions
  1. +3
    -4
      src/annotations/annotations.ts
  2. +26
    -1
      src/configuration.ts
  3. +4
    -4
      src/git/gitService.ts
  4. +1
    -1
      src/telemetry.ts

+ 3
- 4
src/annotations/annotations.ts View File

@ -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<number>('letterSpacing');
const spacing = configuration.getAny<number>('editor.letterSpacing');
if (spacing != null && spacing !== 0) {
width = `calc(${chars}ch + ${Math.round(chars * spacing)}px)`;
}

+ 26
- 1
src/configuration.ts View File

@ -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
@ -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!);
}
@ -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,
@ -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) {

+ 4
- 4
src/git/gitService.ts View File

@ -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() {
@ -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<string>('encoding'));
return Git.getEncoding(configuration.getAny<string>('files.encoding', uri));
}
static deletedOrMissingSha = Git.deletedOrMissingSha;

+ 1
- 1
src/telemetry.ts View File

@ -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;
// }

Loading…
Cancel
Save