Skip to content

Commit

Permalink
Add dmypy status file setting (#347)
Browse files Browse the repository at this point in the history
* Add dmypy status file setting

* Mark setting as experimental
  • Loading branch information
ivirabyan authored Feb 25, 2025
1 parent 0bf12cc commit befef1d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ There are several settings you can configure to customize the behavior of this e
<td><code>true</code></td>
<td>(experimental) Whether the Mypy daemon (<code>dmypy</code>) will take precedence over <code>mypy</code> for type checking. Note: if <code>mypy-type-checker.reportingScope</code> is set to <code>workspace</code>, enabling the Mypy daemon will offer a faster type checking experience. This setting will be overridden if <code>mypy-type-checker.path</code> is set.
</tr>
<tr>
<td>mypy-type-checker.daemonStatusFile</td>
<td><code>""</code></td>
<td>(experimental) Path to the status file used by the Mypy daemon (<code>dmypy</code>).
</tr>
<tr>
<td>mypy-type-checker.ignorePatterns</td>
<td><code>[]</code></td>
Expand Down
10 changes: 7 additions & 3 deletions bundled/tool/lsp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ def _get_global_defaults():
"extraPaths": GLOBAL_SETTINGS.get("extraPaths", []),
"reportingScope": GLOBAL_SETTINGS.get("reportingScope", "file"),
"preferDaemon": GLOBAL_SETTINGS.get("preferDaemon", True),
"daemonStatusFile": GLOBAL_SETTINGS.get("daemonStatusFile", ""),
}


Expand Down Expand Up @@ -611,9 +612,12 @@ def _get_dmypy_args(settings: Dict[str, Any], command: str) -> List[str]:
raise ValueError(f"Invalid dmypy command: {command}")

if key not in DMYPY_ARGS:
STATUS_FILE_NAME = os.fspath(
DMYPY_STATUS_FILE_ROOT / f"status-{str(uuid.uuid4())}.json"
)
if settings["daemonStatusFile"]:
STATUS_FILE_NAME = settings["daemonStatusFile"]
else:
STATUS_FILE_NAME = os.fspath(
DMYPY_STATUS_FILE_ROOT / f"status-{str(uuid.uuid4())}.json"
)
args = ["--status-file", STATUS_FILE_NAME]
DMYPY_ARGS[key] = args

Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@
"scope": "resource",
"type": "boolean"
},
"mypy-type-checker.daemonStatusFile": {
"default": "",
"markdownDescription": "%settings.daemonStatusFile.description%",
"scope": "resource",
"type": "string",
"tags": ["experimental"]
},
"mypy-type-checker.reportingScope": {
"default": "file",
"markdownDescription": "%settings.reportingScope.description%",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"settings.importStrategy.fromEnvironment.description": "Use Mypy from the selected environment. If the extension fails to find a valid Mypy binary, it will fallback to using the bundled version of Mypy.",
"settings.interpreter.description": "Path to a Python executable or a command that will be used to launch the Mypy server and any subprocess. Accepts an array of a single or multiple strings. When set to `[]`, the extension will use the path to the selected Python interpreter. If passing a command, each argument should be provided as a separate string in the array.",
"settings.preferDaemon.description": "Whether the Mypy daemon (`dmypy`) will take precedence over `mypy`for type checking. <br> Note: if `mypy-type-checker.reportingScope`is set to `workspace`, enabling the Mypy daemon will offer a faster type checking experience. This setting will be overridden if `mypy-type-checker.path`is set.",
"settings.daemonStatusFile.description": "Path to the status file used by the Mypy daemon (`dmypy`).",
"settings.reportingScope.description": "Controls the scope of Mypy's problem reporting. If set to `file`, Mypy will limit its problem reporting to the files currently open in the editor. If set to `workspace`, Mypy will extend its problem reporting to include all files within the workspace. ",
"settings.reportingScope.file.description": "Problems are reported for the files open in the editor only.",
"settings.reportingScope.workspace.description": "Problems are reported for all files within the workspace.",
Expand Down
4 changes: 4 additions & 0 deletions src/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface ISettings {
extraPaths: string[];
reportingScope: string;
preferDaemon: boolean;
daemonStatusFile: string;
}

export function getExtensionSettings(namespace: string, includeInterpreter?: boolean): Promise<ISettings[]> {
Expand Down Expand Up @@ -120,6 +121,7 @@ export async function getWorkspaceSettings(
extraPaths: resolveVariables(extraPaths, workspace),
reportingScope: config.get<string>('reportingScope', 'file'),
preferDaemon: config.get<boolean>('preferDaemon', true),
daemonStatusFile: config.get<string>('daemonStatusFile', ''),
};
return workspaceSetting;
}
Expand Down Expand Up @@ -153,6 +155,7 @@ export async function getGlobalSettings(namespace: string, includeInterpreter?:
extraPaths: getGlobalValue<string[]>(config, 'extraPaths', []),
reportingScope: config.get<string>('reportingScope', 'file'),
preferDaemon: config.get<boolean>('preferDaemon', true),
daemonStatusFile: config.get<string>('daemonStatusFile', ''),
};
return setting;
}
Expand All @@ -169,6 +172,7 @@ export function checkIfConfigurationChanged(e: ConfigurationChangeEvent, namespa
`${namespace}.reportingScope`,
`${namespace}.preferDaemon`,
`${namespace}.ignorePatterns`,
`${namespace}.daemonStatusFile`,
'python.analysis.extraPaths',
];
const changed = settings.map((s) => e.affectsConfiguration(s));
Expand Down

0 comments on commit befef1d

Please sign in to comment.