Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Oct 16, 2024
1 parent 66e0586 commit 213ee2b
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 167 deletions.
301 changes: 148 additions & 153 deletions editors/vscode/client/config.ts
Original file line number Diff line number Diff line change
@@ -1,166 +1,161 @@
import {
ConfigurationChangeEvent,
workspace,
WorkspaceConfiguration,
} from 'vscode'
import { IDisposable } from './types'
import { ConfigurationChangeEvent, workspace, WorkspaceConfiguration } from 'vscode';
import { IDisposable } from './types';

export class ConfigService implements Config, IDisposable {
private static readonly _namespace = 'oxc'
private readonly _disposables: IDisposable[] = []
private _inner: WorkspaceConfiguration
private _runTrigger: 'onSave' | 'onType'
private _enable: boolean
private _trace: 'off' | 'messages' | 'verbose'
private _configPath: string
private _binPath: string | undefined

public onConfigChange:
| ((this: ConfigService, config: ConfigurationChangeEvent) => void)
| undefined

constructor() {
this._inner = workspace.getConfiguration(ConfigService._namespace)
this._runTrigger = this._inner.get<Trigger>('lint.run') || 'onType'
this._enable = this._inner.get<boolean>('enable') ?? true
this._trace = this._inner.get<TraceLevel>('trace.server') || 'off'
this._configPath = this._inner.get<string>('configPath') || '.eslintrc'
this._binPath = this._inner.get<string>('path.server')
this.onConfigChange = undefined

const disposeChangeListener = workspace.onDidChangeConfiguration(
this.onVscodeConfigChange.bind(this)
)
this._disposables.push(disposeChangeListener)
private static readonly _namespace = 'oxc';
private readonly _disposables: IDisposable[] = [];
private _inner: WorkspaceConfiguration;
private _runTrigger: 'onSave' | 'onType';
private _enable: boolean;
private _trace: 'off' | 'messages' | 'verbose';
private _configPath: string;
private _binPath: string | undefined;

public onConfigChange:
| ((this: ConfigService, config: ConfigurationChangeEvent) => void)
| undefined;

constructor() {
this._inner = workspace.getConfiguration(ConfigService._namespace);
this._runTrigger = this._inner.get<Trigger>('lint.run') || 'onType';
this._enable = this._inner.get<boolean>('enable') ?? true;
this._trace = this._inner.get<TraceLevel>('trace.server') || 'off';
this._configPath = this._inner.get<string>('configPath') || '.eslintrc';
this._binPath = this._inner.get<string>('path.server');
this.onConfigChange = undefined;

const disposeChangeListener = workspace.onDidChangeConfiguration(
this.onVscodeConfigChange.bind(this),
);
this._disposables.push(disposeChangeListener);
}

get rawConfig(): WorkspaceConfiguration {
return this._inner;
}

get runTrigger(): Trigger {
return this._runTrigger;
}

set runTrigger(value: Trigger) {
this._runTrigger = value;
workspace
.getConfiguration(ConfigService._namespace)
.update('lint.run', value);
}

get enable(): boolean {
return this._enable;
}

set enable(value: boolean) {
this._enable = value;
workspace
.getConfiguration(ConfigService._namespace)
.update('enable', value);
}

get trace(): TraceLevel {
return this._trace;
}

set trace(value: TraceLevel) {
this._trace = value;
workspace
.getConfiguration(ConfigService._namespace)
.update('trace.server', value);
}

get configPath(): string {
return this._configPath;
}

set configPath(value: string) {
this._configPath = value;
workspace
.getConfiguration(ConfigService._namespace)
.update('configPath', value);
}

get binPath(): string | undefined {
return this._binPath;
}

set binPath(value: string | undefined) {
this._binPath = value;
workspace
.getConfiguration(ConfigService._namespace)
.update('path.server', value);
}

private onVscodeConfigChange(event: ConfigurationChangeEvent): void {
if (event.affectsConfiguration(ConfigService._namespace)) {
this._runTrigger = this._inner.get<Trigger>('lint.run') || 'onType';
this._enable = this._inner.get<boolean>('enable') ?? true;
this._trace = this._inner.get<TraceLevel>('trace.server') || 'off';
this._configPath = this._inner.get<string>('configPath') || '.eslintrc';
this._binPath = this._inner.get<string>('path.server');
this.onConfigChange?.call(this, event);
}
}

get rawConfig(): WorkspaceConfiguration {
return this._inner
}

get runTrigger(): Trigger {
return this._runTrigger
}

set runTrigger(value: Trigger) {
this._runTrigger = value
workspace
.getConfiguration(ConfigService._namespace)
.update('lint.run', value)
}

get enable(): boolean {
return this._enable
}

set enable(value: boolean) {
this._enable = value
workspace
.getConfiguration(ConfigService._namespace)
.update('enable', value)
}

get trace(): TraceLevel {
return this._trace
}

set trace(value: TraceLevel) {
this._trace = value
workspace
.getConfiguration(ConfigService._namespace)
.update('trace.server', value)
}

get configPath(): string {
return this._configPath
}

set configPath(value: string) {
this._configPath = value
workspace
.getConfiguration(ConfigService._namespace)
.update('configPath', value)
}

get binPath(): string | undefined {
return this._binPath
}

set binPath(value: string | undefined) {
this._binPath = value
workspace
.getConfiguration(ConfigService._namespace)
.update('path.server', value)
}

private onVscodeConfigChange(event: ConfigurationChangeEvent): void {
if (event.affectsConfiguration(ConfigService._namespace)) {
this._runTrigger = this._inner.get<Trigger>('lint.run') || 'onType'
this._enable = this._inner.get<boolean>('enable') ?? true
this._trace = this._inner.get<TraceLevel>('trace.server') || 'off'
this._configPath =
this._inner.get<string>('configPath') || '.eslintrc'
this._binPath = this._inner.get<string>('path.server')
this.onConfigChange?.call(this, event)
}
}

dispose() {
for (const disposable of this._disposables) {
disposable.dispose()
}
}

public toJSON(): Config {
return {
runTrigger: this.runTrigger,
enable: this.enable,
trace: this.trace,
configPath: this.configPath,
binPath: this.binPath,
}
dispose() {
for (const disposable of this._disposables) {
disposable.dispose();
}
}

public toJSON(): Config {
return {
runTrigger: this.runTrigger,
enable: this.enable,
trace: this.trace,
configPath: this.configPath,
binPath: this.binPath,
};
}
}

type Trigger = 'onSave' | 'onType'
type TraceLevel = 'off' | 'messages' | 'verbose'
type Trigger = 'onSave' | 'onType';
type TraceLevel = 'off' | 'messages' | 'verbose';

/**
* See `"contributes.configuration"` in `package.json`
*/
interface Config {
/**
* When to run the linter and generate diagnostics
* `oxc.lint.run`
*
* @default 'onType'
*/
runTrigger: Trigger
/**
* `oxc.enable`
*
* @default true
*/
enable: boolean
/**
* Trace VSCode <-> Oxc Language Server communication
* `oxc.trace.server`
*
* @default 'off'
*/
trace: TraceLevel
/**
* oxlint config path
*
* `oxc.configPath`
*
* @default ".eslintrc"
*/
configPath: string
/**
* Path to LSP binary
* `oxc.path.server`
* @default undefined
*/
binPath: string | undefined
/**
* When to run the linter and generate diagnostics
* `oxc.lint.run`
*
* @default 'onType'
*/
runTrigger: Trigger;
/**
* `oxc.enable`
*
* @default true
*/
enable: boolean;
/**
* Trace VSCode <-> Oxc Language Server communication
* `oxc.trace.server`
*
* @default 'off'
*/
trace: TraceLevel;
/**
* oxlint config path
*
* `oxc.configPath`
*
* @default ".eslintrc"
*/
configPath: string;
/**
* Path to LSP binary
* `oxc.path.server`
* @default undefined
*/
binPath: string | undefined;
}
16 changes: 4 additions & 12 deletions editors/vscode/client/extension.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { promises as fsPromises } from 'node:fs';

import {
commands,
ExtensionContext,
StatusBarAlignment,
StatusBarItem,
ThemeColor,
window,
workspace,
} from 'vscode';
import { commands, ExtensionContext, StatusBarAlignment, StatusBarItem, ThemeColor, window, workspace } from 'vscode';

import { Executable, LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node';

Expand Down Expand Up @@ -74,7 +66,7 @@ export async function activate(context: ExtensionContext) {
const toggleEnable = commands.registerCommand(
OxcCommands.ToggleEnable,
() => {
config.enable = !config.enable
config.enable = !config.enable;
},
);

Expand All @@ -90,7 +82,7 @@ export async function activate(context: ExtensionContext) {
const traceOutputChannel = window.createOutputChannel(traceOutputChannelName);

async function findBinary(): Promise<string> {
let bin = config.binPath
let bin = config.binPath;
if (bin) {
try {
await fsPromises.access(bin);
Expand Down Expand Up @@ -187,7 +179,7 @@ export async function activate(context: ExtensionContext) {
let settings: any = JSON.parse(JSON.stringify(this));
updateStatsBar(settings.enable);
client.sendNotification('workspace/didChangeConfiguration', { settings });
}
};

function updateStatsBar(enable: boolean) {
if (!myStatusBarItem) {
Expand Down
4 changes: 2 additions & 2 deletions editors/vscode/client/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* A type with a destructor for releasing resources when de-registered by an LSP client.
*
*
* There's a newer {@link Disposable} interface that works with `using`, but
* VSCode uses this in its APIs.
*/
export interface IDisposable {
dispose(): void | Promise<void>;
dispose(): void | Promise<void>;
}

0 comments on commit 213ee2b

Please sign in to comment.