mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:49:50 +00:00
Add knot.toml schema (#15735)
## Summary Adds a JSON schema generation step for Red Knot. This PR doesn't yet add a publishing step because it's still a bit early for that ## Test plan I tested the schema in Zed, VS Code and PyCharm: * PyCharm: You have to manually add a schema mapping (settings JSON Schema Mappings) * Zed and VS code support the inline schema specification ```toml #:schema /Users/micha/astral/ruff/knot.schema.json [environment] extra-paths = [] [rules] call-possibly-unbound-method = "error" unknown-rule = "error" # duplicate-base = "error" ``` ```json { "$schema": "file:///Users/micha/astral/ruff/knot.schema.json", "environment": { "python-version": "3.13", "python-platform": "linux2" }, "rules": { "unknown-rule": "error" } } ``` https://github.com/user-attachments/assets/a18fcd96-7cbe-4110-985b-9f1935584411 The Schema overall works but all editors have their own quirks: * PyCharm: Hovering a name always shows the section description instead of the description of the specific setting. But it's the same for other settings in `pyproject.toml` files 🤷 * VS Code (JSON): Using the generated schema in a JSON file gives exactly the experience I want * VS Code (TOML): * Properties with multiple possible values are repeated during auto-completion without giving any hint how they're different.  * The property description mushes together the description of the property and the value, which looks sort of ridiculous.  * Autocompletion and documentation hovering works (except the limitations mentioned above) * Zed: * Very similar to VS Code with the exception that it uses the description attribute to distinguish settings with multiple possible values  I don't think there's much we can do here other than hope (or help) editors improve their auto completion. The same short comings also apply to ruff, so this isn't something new. For now, I think this is good enough
This commit is contained in:
parent
7db5a924af
commit
26c37b1e0e
17 changed files with 1087 additions and 96 deletions
|
@ -30,6 +30,7 @@ glob = { workspace = true }
|
|||
ignore = { workspace = true, optional = true }
|
||||
matchit = { workspace = true }
|
||||
salsa = { workspace = true }
|
||||
schemars = { workspace = true, optional = true }
|
||||
serde = { workspace = true, optional = true }
|
||||
path-slash = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
|
|
|
@ -471,7 +471,13 @@ impl ToOwned for SystemPath {
|
|||
/// The path is guaranteed to be valid UTF-8.
|
||||
#[repr(transparent)]
|
||||
#[derive(Eq, PartialEq, Clone, Hash, PartialOrd, Ord)]
|
||||
pub struct SystemPathBuf(Utf8PathBuf);
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
derive(serde::Serialize, serde::Deserialize),
|
||||
serde(transparent)
|
||||
)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
pub struct SystemPathBuf(#[cfg_attr(feature = "schemars", schemars(with = "String"))] Utf8PathBuf);
|
||||
|
||||
impl SystemPathBuf {
|
||||
pub fn new() -> Self {
|
||||
|
@ -658,27 +664,6 @@ impl ruff_cache::CacheKey for SystemPathBuf {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl serde::Serialize for SystemPath {
|
||||
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
self.0.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl serde::Serialize for SystemPathBuf {
|
||||
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
self.0.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl<'de> serde::Deserialize<'de> for SystemPathBuf {
|
||||
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||
Utf8PathBuf::deserialize(deserializer).map(SystemPathBuf)
|
||||
}
|
||||
}
|
||||
|
||||
/// A slice of a virtual path on [`System`](super::System) (akin to [`str`]).
|
||||
#[repr(transparent)]
|
||||
pub struct SystemVirtualPath(str);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue