-
-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8cebdc8
commit 466f395
Showing
4 changed files
with
75 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { ConfigurationChangeEvent, workspace } from 'vscode'; | ||
import { Config } from './Config'; | ||
import { IDisposable } from './types'; | ||
|
||
export class ConfigService implements IDisposable { | ||
private static readonly _namespace = 'oxc'; | ||
private readonly _disposables: IDisposable[] = []; | ||
|
||
public config: Config; | ||
|
||
public onConfigChange: | ||
| ((this: ConfigService, config: ConfigurationChangeEvent) => void) | ||
| undefined; | ||
|
||
constructor() { | ||
this.config = new Config(); | ||
this.onConfigChange = undefined; | ||
|
||
const disposeChangeListener = workspace.onDidChangeConfiguration( | ||
this.onVscodeConfigChange.bind(this), | ||
); | ||
this._disposables.push(disposeChangeListener); | ||
} | ||
|
||
private onVscodeConfigChange(event: ConfigurationChangeEvent): void { | ||
if (event.affectsConfiguration(ConfigService._namespace)) { | ||
this.config.refresh(); | ||
this.onConfigChange?.call(this, event); | ||
} | ||
} | ||
|
||
dispose() { | ||
for (const disposable of this._disposables) { | ||
disposable.dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { strictEqual } from 'assert'; | ||
import { ConfigService } from './config.js'; | ||
import { Config } from './Config.js'; | ||
|
||
suite('default values on initialization', () => { | ||
const service = new ConfigService(); | ||
suite('Config', () => { | ||
test('default values on initialization', () => { | ||
const config = new Config(); | ||
|
||
strictEqual(service.runTrigger, 'onType'); | ||
strictEqual(service.enable, true); | ||
strictEqual(service.trace, 'off'); | ||
strictEqual(service.configPath, '.eslintrc'); | ||
strictEqual(service.binPath, ''); | ||
strictEqual(config.runTrigger, 'onType'); | ||
strictEqual(config.enable, true); | ||
strictEqual(config.trace, 'off'); | ||
strictEqual(config.configPath, '.eslintrc'); | ||
strictEqual(config.binPath, ''); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters