Skip to content

Commit b40e97d

Browse files
Enable running extension on-save only (#220)
## Summary Now supported in the LSP (astral-sh/ruff-lsp#146): The API exactly mimics that of the [ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint): we have a new setting, `run`, that accepts either `onType` (default) or `onSave`. Closes #110.
1 parent bd82724 commit b40e97d

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ per workspace in Visual Studio Code.
4545
| path | `[]` | Path to a custom `ruff` executable, e.g., `["/path/to/ruff"]`. |
4646
| interpreter | `[]` | Path to a Python interpreter to use to run the linter server. |
4747
| importStrategy | `fromEnvironment` | 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. |
48+
| run | `onType` | Run Ruff on every keystroke (`onType`) or on save (`onSave`). |
4849
| showNotification | `off` | Setting to control when a notification is shown. |
4950
| organizeImports | `true` | Whether to register Ruff as capable of handling `source.organizeImports` actions. |
5051
| fixAll | `true` | Whether to register Ruff as capable of handling `source.fixAll` actions. |

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@
100100
"scope": "window",
101101
"type": "string"
102102
},
103+
"ruff.run": {
104+
"default": "onType",
105+
"description": "Run Ruff on every keystroke (`onType`) or on save (`onSave`).",
106+
"enum": [
107+
"onType",
108+
"onSave"
109+
],
110+
"enumDescriptions": [
111+
"Run Ruff on every keystroke.",
112+
"Run Ruff on save."
113+
],
114+
"scope": "window",
115+
"type": "string"
116+
},
103117
"ruff.interpreter": {
104118
"default": [],
105119
"description": "When set to a path to python executable, extension will use that to launch the server and any subprocess.",

src/common/server.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ export async function createServer(
7575
const cwd = getProjectRoot()?.uri.fsPath;
7676
const newEnv = { ...process.env };
7777

78-
// Set import strategy.
79-
newEnv.LS_IMPORT_STRATEGY = settings.importStrategy;
80-
8178
// Set notification type.
8279
newEnv.LS_SHOW_NOTIFICATION = settings.showNotifications;
8380

src/common/settings.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ import { getInterpreterDetails } from "./python";
33
import { LoggingLevelSettingType } from "./log/types";
44
import { getConfiguration, getWorkspaceFolders } from "./vscodeapi";
55

6+
type ImportStrategy = "fromEnvironment" | "useBundled";
7+
8+
type Run = "onType" | "onSave";
9+
610
export interface ISettings {
711
workspace: string;
812
logLevel: LoggingLevelSettingType;
913
args: string[];
1014
path: string[];
1115
interpreter: string[];
12-
importStrategy: string;
16+
importStrategy: ImportStrategy;
17+
run: Run;
1318
showNotifications: string;
1419
organizeImports: boolean;
1520
fixAll: boolean;
@@ -51,7 +56,8 @@ export async function getWorkspaceSettings(
5156
args: config.get<string[]>(`args`) ?? [],
5257
path: config.get<string[]>(`path`) ?? [],
5358
interpreter: interpreter ?? [],
54-
importStrategy: config.get<string>(`importStrategy`) ?? "fromEnvironment",
59+
importStrategy: config.get<ImportStrategy>(`importStrategy`) ?? "fromEnvironment",
60+
run: config.get<Run>(`run`) ?? "onType",
5561
showNotifications: config.get<string>(`showNotifications`) ?? "off",
5662
organizeImports: config.get<boolean>(`organizeImports`) ?? true,
5763
fixAll: config.get<boolean>(`fixAll`) ?? true,
@@ -68,7 +74,8 @@ export async function getGlobalSettings(namespace: string): Promise<Omit<ISettin
6874
args: config.get<string[]>(`args`) ?? [],
6975
path: config.get<string[]>(`path`) ?? [],
7076
interpreter: interpreter ?? [],
71-
importStrategy: config.get<string>(`importStrategy`) ?? "fromEnvironment",
77+
importStrategy: config.get<ImportStrategy>(`importStrategy`) ?? "fromEnvironment",
78+
run: config.get<Run>(`run`) ?? "onType",
7279
showNotifications: config.get<string>(`showNotifications`) ?? "off",
7380
organizeImports: config.get<boolean>(`organizeImports`) ?? true,
7481
fixAll: config.get<boolean>(`fixAll`) ?? true,
@@ -85,6 +92,7 @@ export function checkIfConfigurationChanged(
8592
`${namespace}.path`,
8693
`${namespace}.interpreter`,
8794
`${namespace}.importStrategy`,
95+
`${namespace}.run`,
8896
`${namespace}.showNotifications`,
8997
`${namespace}.organizeImports`,
9098
`${namespace}.fixAll`,

0 commit comments

Comments
 (0)