Skip to content

Commit ad704dd

Browse files
committed
generated,rust-analyzer: Handle objects with defined properties
They are implemented as submodules instead of an attrset of anything
1 parent f823d01 commit ad704dd

File tree

3 files changed

+146
-4
lines changed

3 files changed

+146
-4
lines changed

generated/rust-analyzer.nix

Lines changed: 128 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
targets and features, with the following base command line:
173173
174174
```bash
175-
cargo check --quiet --workspace --message-format=json --all-targets
175+
cargo check --quiet --workspace --message-format=json --all-targets --keep-going
176176
```
177177
.
178178
'';
@@ -1323,7 +1323,7 @@
13231323
description = ''
13241324
Whether to show const generic parameter name inlay hints.
13251325
'';
1326-
pluginDefault = false;
1326+
pluginDefault = true;
13271327
type = {
13281328
kind = "boolean";
13291329
};
@@ -1332,7 +1332,7 @@
13321332
description = ''
13331333
Whether to show generic lifetime parameter name inlay hints.
13341334
'';
1335-
pluginDefault = true;
1335+
pluginDefault = false;
13361336
type = {
13371337
kind = "boolean";
13381338
};
@@ -1649,7 +1649,7 @@
16491649
pluginDefault = null;
16501650
type = {
16511651
kind = "integer";
1652-
maximum = null;
1652+
maximum = 65535;
16531653
minimum = 0;
16541654
};
16551655
};
@@ -1985,6 +1985,130 @@
19851985
kind = "boolean";
19861986
};
19871987
};
1988+
"rust-analyzer.workspace.discoverConfig" = {
1989+
description = ''
1990+
Enables automatic discovery of projects using [`DiscoverWorkspaceConfig::command`].
1991+
1992+
[`DiscoverWorkspaceConfig`] also requires setting `progress_label` and `files_to_watch`.
1993+
`progress_label` is used for the title in progress indicators, whereas `files_to_watch`
1994+
is used to determine which build system-specific files should be watched in order to
1995+
reload rust-analyzer.
1996+
1997+
Below is an example of a valid configuration:
1998+
```json
1999+
"rust-analyzer.workspace.discoverConfig": {
2000+
"command": [
2001+
"rust-project",
2002+
"develop-json",
2003+
{arg}
2004+
],
2005+
"progressLabel": "rust-analyzer",
2006+
"filesToWatch": [
2007+
"BUCK",
2008+
],
2009+
}
2010+
```
2011+
2012+
## On `DiscoverWorkspaceConfig::command`
2013+
2014+
**Warning**: This format is provisional and subject to change.
2015+
2016+
[`DiscoverWorkspaceConfig::command`] *must* return a JSON object
2017+
corresponding to `DiscoverProjectData::Finished`:
2018+
2019+
```norun
2020+
#[derive(Debug, Clone, Deserialize, Serialize)]
2021+
#[serde(tag = "kind")]
2022+
#[serde(rename_all = "snake_case")]
2023+
enum DiscoverProjectData {
2024+
Finished { buildfile: Utf8PathBuf, project: ProjectJsonData },
2025+
Error { error: String, source: Option<String> },
2026+
Progress { message: String },
2027+
}
2028+
```
2029+
2030+
As JSON, `DiscoverProjectData::Finished` is:
2031+
2032+
```json
2033+
{
2034+
// the internally-tagged representation of the enum.
2035+
"kind": "finished",
2036+
// the file used by a non-Cargo build system to define
2037+
// a package or target.
2038+
"buildfile": "rust-analyzer/BUILD",
2039+
// the contents of a rust-project.json, elided for brevity
2040+
"project": {
2041+
"sysroot": "foo",
2042+
"crates": []
2043+
}
2044+
}
2045+
```
2046+
2047+
It is encouraged, but not required, to use the other variants on
2048+
`DiscoverProjectData` to provide a more polished end-user experience.
2049+
2050+
`DiscoverWorkspaceConfig::command` may *optionally* include an `{arg}`,
2051+
which will be substituted with the JSON-serialized form of the following
2052+
enum:
2053+
2054+
```norun
2055+
#[derive(PartialEq, Clone, Debug, Serialize)]
2056+
#[serde(rename_all = "camelCase")]
2057+
pub enum DiscoverArgument {
2058+
Path(AbsPathBuf),
2059+
Buildfile(AbsPathBuf),
2060+
}
2061+
```
2062+
2063+
The JSON representation of `DiscoverArgument::Path` is:
2064+
2065+
```json
2066+
{
2067+
"path": "src/main.rs"
2068+
}
2069+
```
2070+
2071+
Similarly, the JSON representation of `DiscoverArgument::Buildfile` is:
2072+
2073+
```
2074+
{
2075+
"buildfile": "BUILD"
2076+
}
2077+
```
2078+
2079+
`DiscoverArgument::Path` is used to find and generate a `rust-project.json`,
2080+
and therefore, a workspace, whereas `DiscoverArgument::buildfile` is used to
2081+
to update an existing workspace. As a reference for implementors,
2082+
buck2's `rust-project` will likely be useful:
2083+
https://github.com/facebook/buck2/tree/main/integrations/rust-project.
2084+
'';
2085+
pluginDefault = null;
2086+
type = {
2087+
kind = "oneOf";
2088+
subTypes = [
2089+
{
2090+
kind = "submodule";
2091+
options = {
2092+
command = {
2093+
item = {
2094+
kind = "string";
2095+
};
2096+
kind = "list";
2097+
};
2098+
filesToWatch = {
2099+
item = {
2100+
kind = "string";
2101+
};
2102+
kind = "list";
2103+
};
2104+
progressLabel = {
2105+
kind = "string";
2106+
};
2107+
};
2108+
}
2109+
];
2110+
};
2111+
};
19882112
"rust-analyzer.workspace.symbol.search.kind" = {
19892113
description = ''
19902114
Workspace symbol search kind.

plugins/lsp/language-servers/rust-analyzer-config.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ let
3737
lib.types.int
3838
else if kind == "object" then
3939
lib.types.attrsOf lib.types.anything
40+
else if kind == "submodule" then
41+
lib.types.submodule {
42+
options = lib.mapAttrs (
43+
_: ty:
44+
lib.mkOption {
45+
type = mkRustAnalyzerType ty;
46+
description = "";
47+
}
48+
) typeInfo.options;
49+
}
4050
else if kind == "string" then
4151
lib.types.str
4252
else if kind == "boolean" then

update-scripts/rust-analyzer.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ let
4343
maximum ? null,
4444
items ? null,
4545
anyOf ? null,
46+
properties ? null,
4647
# Not used in the function, but anyOf values contain it
4748
enumDescriptions ? null,
4849
}@property:
@@ -96,6 +97,13 @@ let
9697
kind = type;
9798
inherit minimum maximum;
9899
}
100+
else if type == "object" && properties != null then
101+
{
102+
kind = "submodule";
103+
options = lib.mapAttrs (
104+
name: value: mkRustAnalyzerOptionType false "${property_name}.${name}" value
105+
) properties;
106+
}
99107
else if
100108
lib.elem type [
101109
"object"

0 commit comments

Comments
 (0)