Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move args and run settings to lint.args and lint.run #292

Merged
merged 1 commit into from
Oct 2, 2023
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
51 changes: 38 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,37 +63,39 @@
"properties": {
"ruff.args": {
"default": [],
"markdownDescription": "Additional command-line arguments to pass to `ruff`, e.g., `\"args\": [\"--config=/path/to/pyproject.toml\"]`. Supports a subset of Ruff's command-line arguments, ignoring those that are required to operate the LSP, like `--force-exclude` and `--verbose`.",
"markdownDescription": "Additional command-line arguments to pass to `ruff check`, e.g., `\"args\": [\"--config=/path/to/pyproject.toml\"]`. Supports a subset of Ruff's command-line arguments, ignoring those that are required to operate the LSP, like `--force-exclude` and `--verbose`.",
"markdownDeprecationMessage": "**Deprecated**: Please use `#ruff.lint.args` instead.",
"items": {
"type": "string"
},
"scope": "resource",
"type": "array"
},
"ruff.path": {
"ruff.lint.args": {
"default": [],
"markdownDescription": "Path to a custom `ruff` executable, e.g., `[\"/path/to/ruff\"]`.",
"scope": "resource",
"markdownDescription": "Additional command-line arguments to pass to `ruff check`, e.g., `\"args\": [\"--config=/path/to/pyproject.toml\"]`. Supports a subset of Ruff's command-line arguments, ignoring those that are required to operate the LSP, like `--force-exclude` and `--verbose`.",
"items": {
"type": "string"
},
"scope": "resource",
"type": "array"
},
"ruff.importStrategy": {
"default": "fromEnvironment",
"markdownDescription": "Strategy for loading the `ruff` executable. `fromEnvironment` picks up Ruff from the environment, falling back to the bundled version if needed. `useBundled` uses the version bundled with the extension.",
"ruff.run": {
"default": "onType",
"markdownDescription": "Run Ruff on every keystroke (`onType`) or on save (`onSave`).",
"markdownDeprecationMessage": "**Deprecated**: Please use `#ruff.lint.run` instead.",
"enum": [
"fromEnvironment",
"useBundled"
"onType",
"onSave"
],
"enumDescriptions": [
"Use `ruff` from environment, falling back to the bundled version if `ruff` is not found.",
"Always use the bundled version of `ruff`."
"Run Ruff on every keystroke.",
"Run Ruff on save."
],
"scope": "window",
"type": "string"
},
"ruff.run": {
"ruff.lint.run": {
"default": "onType",
"markdownDescription": "Run Ruff on every keystroke (`onType`) or on save (`onSave`).",
"enum": [
Expand All @@ -107,9 +109,32 @@
"scope": "window",
"type": "string"
},
"ruff.path": {
"default": [],
"markdownDescription": "Path to a custom `ruff` executable, e.g., `[\"/path/to/ruff\"]`.",
"scope": "resource",
"items": {
"type": "string"
},
"type": "array"
},
"ruff.importStrategy": {
"default": "fromEnvironment",
"markdownDescription": "Strategy for loading the `ruff` executable. `fromEnvironment` picks up Ruff from the environment, falling back to the bundled version if needed. `useBundled` uses the version bundled with the extension.",
"enum": [
"fromEnvironment",
"useBundled"
],
"enumDescriptions": [
"Use `ruff` from environment, falling back to the bundled version if `ruff` is not found.",
"Always use the bundled version of `ruff`."
],
"scope": "window",
"type": "string"
},
"ruff.interpreter": {
"default": [],
"markdownDescription": "Path to a Python interpreter to use to run the linter server.",
"markdownDescription": "Path to a Python interpreter to use to run the LSP server.",
"scope": "window",
"items": {
"type": "string"
Expand Down
35 changes: 26 additions & 9 deletions src/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,28 @@ type CodeAction = {
};
};

type Lint = {
args?: string[];
run?: Run;
};

export interface ISettings {
cwd: string;
workspace: string;
args: string[];
path: string[];
interpreter: string[];
importStrategy: ImportStrategy;
run: Run;
codeAction: CodeAction;
enable: boolean;
enableExperimentalFormatter: boolean;
showNotifications: string;
organizeImports: boolean;
fixAll: boolean;
lint: Lint;

// Deprecated settings (prefer `lint.args`, etc.).
args: string[];
run: Run;
}

export function getExtensionSettings(namespace: string): Promise<ISettings[]> {
Expand Down Expand Up @@ -86,17 +94,20 @@ export async function getWorkspaceSettings(
return {
cwd: workspace.uri.fsPath,
workspace: workspace.uri.toString(),
args: resolveVariables(config.get<string[]>("args") ?? [], workspace),
path: resolveVariables(config.get<string[]>("path") ?? [], workspace),
interpreter: resolveVariables(interpreter, workspace),
importStrategy: config.get<ImportStrategy>("importStrategy") ?? "fromEnvironment",
run: config.get<Run>("run") ?? "onType",
codeAction: config.get<CodeAction>("codeAction") ?? {},
lint: config.get<Lint>("lint") ?? {},
enable: config.get<boolean>("enable") ?? true,
organizeImports: config.get<boolean>("organizeImports") ?? true,
fixAll: config.get<boolean>("fixAll") ?? true,
showNotifications: config.get<string>("showNotifications") ?? "off",
enableExperimentalFormatter: config.get<boolean>("enableExperimentalFormatter") ?? false,

// Deprecated settings (prefer `lint.args`, etc.).
args: resolveVariables(config.get<string[]>("args") ?? [], workspace),
run: config.get<Run>("run") ?? "onType",
};
}

Expand All @@ -110,12 +121,11 @@ export async function getGlobalSettings(namespace: string): Promise<ISettings> {
return {
cwd: process.cwd(),
workspace: process.cwd(),
args: getGlobalValue<string[]>(config, "args", []),
path: getGlobalValue<string[]>(config, "path", []),
interpreter: [],
importStrategy: getGlobalValue<ImportStrategy>(config, "importStrategy", "fromEnvironment"),
run: getGlobalValue<Run>(config, "run", "onType"),
codeAction: getGlobalValue<CodeAction>(config, "codeAction", {}),
lint: getGlobalValue<Lint>(config, "lint", {}),
enable: getGlobalValue<boolean>(config, "enable", true),
organizeImports: getGlobalValue<boolean>(config, "organizeImports", true),
fixAll: getGlobalValue<boolean>(config, "fixAll", true),
Expand All @@ -125,6 +135,10 @@ export async function getGlobalSettings(namespace: string): Promise<ISettings> {
"enableExperimentalFormatter",
false,
),

// Deprecated settings (prefer `lint.args`, etc.).
args: getGlobalValue<string[]>(config, "args", []),
run: getGlobalValue<Run>(config, "run", "onType"),
};
}

Expand All @@ -133,17 +147,20 @@ export function checkIfConfigurationChanged(
namespace: string,
): boolean {
const settings = [
`${namespace}.args`,
`${namespace}.codeAction`,
`${namespace}.enableExperimentalFormatter`,
`${namespace}.enable`,
`${namespace}.fixAll`,
`${namespace}.importStrategy`,
`${namespace}.interpreter`,
`${namespace}.lint`,
`${namespace}.organizeImports`,
`${namespace}.path`,
`${namespace}.run`,
`${namespace}.showNotifications`,
`${namespace}.enableExperimentalFormatter`,

// Deprecated settings (prefer `lint.args`, etc.).
`${namespace}.args`,
`${namespace}.run`,
];
return settings.some((s) => e.affectsConfiguration(s));
}