Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/oxc_language_server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ This crate provides an [LSP](https://microsoft.github.io/language-server-protoco
Returns the [Server Capabilities](#server-capabilities).\
Initialization Options:

| Option Key | Value(s) | Default | Description |
| ------------ | ---------------------- | ---------------- | ---------------------------------------------------------------------------------------------------- |
| `run` | `"onSave" \| "onType"` | `"onType"` | Should the server lint the files when the user is typing or saving |
| `configPath` | `<string>` | `.oxlintrc.json` | Path to a oxlint configuration file, pass '' to enable nested configuration |
| `flags` | `Map<string, string>` | `<empty>` | Special oxc language server flags, currently only one flag key is supported: `disable_nested_config` |
| Option Key | Value(s) | Default | Description |
| ------------ | ---------------------- | ---------- | ---------------------------------------------------------------------------------------------------- |
| `run` | `"onSave" \| "onType"` | `"onType"` | Should the server lint the files when the user is typing or saving |
| `configPath` | `<string>` \| `null` | `null` | Path to a oxlint configuration file, passing a string will disable nested configuration |
| `flags` | `Map<string, string>` | `<empty>` | Special oxc language server flags, currently only one flag key is supported: `disable_nested_config` |

### [initialized](https://microsoft.github.io/language-server-protocol/specification#initialized)

Expand Down
27 changes: 5 additions & 22 deletions crates/oxc_language_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,15 @@ enum Run {
#[default]
OnType,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
struct Options {
run: Run,
config_path: String,
config_path: Option<String>,
flags: FxHashMap<String, String>,
}

impl Default for Options {
fn default() -> Self {
Self {
run: Run::default(),
config_path: OXC_CONFIG_FILE.into(),
flags: FxHashMap::default(),
}
}
}

impl Options {
fn get_config_path(&self) -> Option<PathBuf> {
if self.config_path.is_empty() { None } else { Some(PathBuf::from(&self.config_path)) }
}

fn disable_nested_configs(&self) -> bool {
self.flags.contains_key("disable_nested_config")
}
Expand Down Expand Up @@ -142,11 +128,8 @@ impl LanguageServer for Backend {
*self.options.lock().await = changed_options.clone();

// revalidate the config and all open files
if changed_options
.get_config_path()
.is_some_and(|path| path.to_str().unwrap() != current_option.config_path)
{
info!("config path change detected {:?}", &changed_options.get_config_path());
if changed_options.config_path != current_option.config_path {
info!("config path change detected {:?}", &changed_options.config_path);
self.init_linter_config().await;
self.revalidate_open_files().await;
}
Expand Down Expand Up @@ -515,7 +498,7 @@ impl Backend {
let Ok(root_path) = uri.to_file_path() else {
return None;
};
let relative_config_path = self.options.lock().await.get_config_path();
let relative_config_path = self.options.lock().await.config_path.clone();
let oxlintrc = if relative_config_path.is_some() {
let config = root_path.join(relative_config_path.unwrap());
config.try_exists().expect("Invalid config file path");
Expand Down
14 changes: 7 additions & 7 deletions editors/vscode/client/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Config implements ConfigInterface {
private _runTrigger!: Trigger;
private _enable!: boolean;
private _trace!: TraceLevel;
private _configPath!: string;
private _configPath!: string | null;
private _binPath: string | undefined;
private _flags!: Record<string, string>;

Expand All @@ -24,7 +24,7 @@ export class Config implements ConfigInterface {
this._runTrigger = conf.get<Trigger>('lint.run') || 'onType';
this._enable = conf.get<boolean>('enable') ?? true;
this._trace = conf.get<TraceLevel>('trace.server') || 'off';
this._configPath = conf.get<string>('configPath') || (useNestedConfigs ? '' : oxlintConfigFileName);
this._configPath = conf.get<string | null>('configPath') || (useNestedConfigs ? null : oxlintConfigFileName);
this._binPath = conf.get<string>('path.server');
this._flags = flags;
}
Expand Down Expand Up @@ -62,7 +62,7 @@ export class Config implements ConfigInterface {
.update('trace.server', value);
}

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

Expand Down Expand Up @@ -98,14 +98,14 @@ export class Config implements ConfigInterface {
public toLanguageServerConfig(): LanguageServerConfig {
return {
run: this.runTrigger,
configPath: this.configPath,
configPath: this.configPath ?? null,
flags: this.flags,
};
}
}

interface LanguageServerConfig {
configPath: string;
configPath: string | null;
run: Trigger;
flags: Record<string, string>;
}
Expand Down Expand Up @@ -141,9 +141,9 @@ interface ConfigInterface {
*
* `oxc.configPath`
*
* @default ".oxlintrc.json"
* @default null
*/
configPath: string;
configPath: string | null;
/**
* Path to LSP binary
* `oxc.path.server`
Expand Down
8 changes: 4 additions & 4 deletions editors/vscode/client/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ suite('Config', () => {
strictEqual(config.runTrigger, 'onType');
strictEqual(config.enable, true);
strictEqual(config.trace, 'off');
strictEqual(config.configPath, '');
strictEqual(config.configPath, null);
strictEqual(config.binPath, '');
deepStrictEqual(config.flags, {});
});

test('configPath defaults to empty string when using nested configs and configPath is empty', async () => {
test('configPath defaults to null when using nested configs and configPath is empty', async () => {
const wsConfig = workspace.getConfiguration('oxc');
await wsConfig.update('configPath', '');
await wsConfig.update('flags', {});

const config = new Config();

deepStrictEqual(config.flags, {});
strictEqual(config.configPath, '');
strictEqual(config.configPath, null);
});

test('configPath defaults to .oxlintrc.json when not using nested configs and configPath is empty', async () => {
const wsConfig = workspace.getConfiguration('oxc');
await wsConfig.update('configPath', '');
await wsConfig.update('configPath', undefined);
await wsConfig.update('flags', { disable_nested_config: '' });

const config = new Config();
Expand Down
9 changes: 7 additions & 2 deletions editors/vscode/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ export async function activate(context: ExtensionContext) {
})),
synchronize: {
// Notify the server about file config changes in the workspace
fileEvents: createFileEventWatchers(configService.config.configPath),
fileEvents: configService.config.configPath !== null
? createFileEventWatchers(configService.config.configPath)
: undefined,
},
initializationOptions: {
settings: configService.config.toLanguageServerConfig(),
Expand Down Expand Up @@ -251,7 +253,10 @@ export async function activate(context: ExtensionContext) {

if (event.affectsConfiguration('oxc.configPath')) {
client.clientOptions.synchronize = client.clientOptions.synchronize ?? {};
client.clientOptions.synchronize.fileEvents = createFileEventWatchers(configService.config.configPath);
client.clientOptions.synchronize.fileEvents = configService.config.configPath !== null
? createFileEventWatchers(configService.config.configPath)
: undefined;

client.restart().then(async () => {
const configFiles = await findOxlintrcConfigFiles();
await sendDidChangeWatchedFilesNotificationWith(client, configFiles);
Expand Down
4 changes: 2 additions & 2 deletions editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@
"description": "Traces the communication between VS Code and the language server."
},
"oxc.configPath": {
"type": "string",
"type": ["string", "null"],
"scope": "window",
"default": "",
"default": null,
"description": "Path to ESlint configuration. Keep it empty to enable nested configuration."
},
"oxc.path.server": {
Expand Down