Skip to content

Commit

Permalink
Allow live configuration lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
neild3r committed Mar 25, 2018
1 parent 7c1ba65 commit 7409483
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
7 changes: 0 additions & 7 deletions src/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ import Config from "./util/config";
*/
export default class Completions implements CompletionItemProvider
{
/**
* A config which will modify the result of the docblock
*
* @type {{}}
*/
protected config:{};

/**
* List of tags and snippets that are filled in docblocks
*
Expand Down
36 changes: 27 additions & 9 deletions src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ export default class Config {
private static _instance: Config;

/**
* List of defaults
* Data to use when we aren't in live mode
*
* @type {Object}
*/
private data:{}

/**
* Are we in test mode or live
*
* @type {boolean}
*/
private isLive:boolean = true;

/**
* Returns the instance for this util
*
Expand All @@ -34,24 +41,31 @@ export default class Config {
}

/**
* Load in the defaults or the config
* Set whether this is live mode or not
*
* @param {boolean} bool
*/
public load(force:boolean = false)
public set live(bool:boolean)
{
let current:WorkspaceConfiguration = workspace.getConfiguration();
let config = current.get('php-docblocker');
this.isLive = bool;
}

if (config == null || force) {
config = {};
/**
* Load in the defaults or the config
*/
public load()
{
if (!this.isLive) {
let config = {};
let packageJson = JSON.parse(fs.readFileSync(__dirname + '/../../../package.json').toString());
let props = packageJson.contributes.configuration.properties;
for (var key in props) {
var item = props[key];
config[key.replace('php-docblocker.', '')] = item.default;
}
}

this.data = config;
this.data = config;
}
}

/**
Expand All @@ -71,6 +85,10 @@ export default class Config {
*/
public get(setting:string)
{
if (this.isLive) {
return workspace.getConfiguration('php-docblocker').get(setting);
}

return this.data[setting];
}
}
2 changes: 1 addition & 1 deletion test/doc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ suite("Snippet build tests", () => {
if (testData.config != undefined) {
Helper.setConfig(testData.config);
} else {
Config.instance.load(true);
Config.instance.load();
}
if (testData.input != undefined) {
doc.fromObject(testData.input);
Expand Down
3 changes: 2 additions & 1 deletion test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export default class Helper {
}

public static setConfig(overrides:any) {
Config.instance.load(true);
Config.instance.load();
Config.instance.live = false;
Config.instance.override(overrides);
}
}

0 comments on commit 7409483

Please sign in to comment.