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
17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,22 @@
},
"ruff.configuration": {
"default": null,
"markdownDescription": "Path to a `ruff.toml` or `pyproject.toml` file to use for configuration. By default, Ruff will discover configuration for each project from the filesystem, mirroring the behavior of the Ruff CLI.\n\n**This setting is used only by the native server.**",
"markdownDescription": "Configuration overrides for Ruff. See [the documentation](https://docs.astral.sh/ruff/editors/settings/#configuration) for more details.\n\n**This setting is used only by the native server.**",
"scope": "window",
"type": "string"
"type": [
"string",
"object"
],
"oneOf": [
{
"type": "string",
"markdownDescription": "Path to a `ruff.toml` or `pyproject.toml` file to use for configuration."
},
{
"type": "object",
"markdownDescription": "Inline JSON configuration for Ruff settings (e.g., `{ \"line-length\": 100 }`). *Added in Ruff 0.9.8.*"
}
]
},
"ruff.args": {
"default": [],
Expand Down
3 changes: 3 additions & 0 deletions src/common/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { logger } from "./logger";
import { getDebuggerPath } from "./python";
import {
checkInlineConfigSupport,
getExtensionSettings,
getGlobalSettings,
getUserSetLegacyServerSettings,
Expand Down Expand Up @@ -189,6 +190,8 @@ async function createNativeServer(
vscode.window.showErrorMessage(message);
return Promise.reject();
}

checkInlineConfigSupport(ruffVersion, serverId);
}

let ruffServerArgs: string[];
Expand Down
33 changes: 29 additions & 4 deletions src/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import {
import { getInterpreterDetails } from "./python";
import { getConfiguration, getWorkspaceFolders } from "./vscodeapi";
import { logger } from "./logger";
import {
INLINE_CONFIGURATION_VERSION,
VersionInfo,
supportsInlineConfiguration,
versionToString,
} from "./version";

type ImportStrategy = "fromEnvironment" | "useBundled";

Expand Down Expand Up @@ -50,7 +56,7 @@ export interface ISettings {
path: string[];
ignoreStandardLibrary: boolean;
interpreter: string[];
configuration: string | null;
configuration: string | object | null;
importStrategy: ImportStrategy;
codeAction: CodeAction;
enable: boolean;
Expand Down Expand Up @@ -135,8 +141,8 @@ export async function getWorkspaceSettings(
interpreter = resolveVariables(interpreter, workspace);
}

let configuration = config.get<string>("configuration") ?? null;
if (configuration !== null) {
let configuration = config.get<string | object>("configuration") ?? null;
if (configuration !== null && typeof configuration === "string") {
configuration = resolveVariables(configuration, workspace);
}

Expand Down Expand Up @@ -199,7 +205,7 @@ export async function getGlobalSettings(namespace: string): Promise<ISettings> {
path: getGlobalValue<string[]>(config, "path", []),
ignoreStandardLibrary: getGlobalValue<boolean>(config, "ignoreStandardLibrary", true),
interpreter: [],
configuration: getGlobalValue<string | null>(config, "configuration", null),
configuration: getGlobalValue<string | object | null>(config, "configuration", null),
importStrategy: getGlobalValue<ImportStrategy>(config, "importStrategy", "fromEnvironment"),
codeAction: getGlobalValue<CodeAction>(config, "codeAction", {}),
lint: {
Expand Down Expand Up @@ -333,6 +339,25 @@ function getPreferredGlobalSetting<T>(
return newSettings?.defaultValue;
}

export function checkInlineConfigSupport(ruffVersion: VersionInfo, serverId: string) {
if (supportsInlineConfiguration(ruffVersion)) {
return;
}

getWorkspaceFolders().forEach((workspace) => {
const config = getConfiguration(serverId, workspace.uri).get<string | object>("configuration");
if (typeof config === "object") {
const message = `Inline configuration support was added in Ruff ${versionToString(
INLINE_CONFIGURATION_VERSION,
)} (current version is ${versionToString(
ruffVersion,
)}). Please update your Ruff version to use this feature.`;
logger.warn(message);
vscode.window.showWarningMessage(message);
}
});
}

/**
* Check if the user have configured `notebook.codeActionsOnSave` with non-notebook prefixed code actions.
*/
Expand Down
12 changes: 12 additions & 0 deletions src/common/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,15 @@ export const NATIVE_SERVER_STABLE_VERSION: VersionInfo = { major: 0, minor: 5, p
export function supportsStableNativeServer(version: VersionInfo): boolean {
return versionGte(version, NATIVE_SERVER_STABLE_VERSION);
}

/**
* The minimum version of the Ruff executable that supports inline configuration.
*/
export const INLINE_CONFIGURATION_VERSION: VersionInfo = { major: 0, minor: 9, patch: 8 };

/**
* Check if the given version of the Ruff executable supports inline configuration.
*/
export function supportsInlineConfiguration(version: VersionInfo): boolean {
return versionGte(version, INLINE_CONFIGURATION_VERSION);
}