Skip to content

Commit dbf6f7b

Browse files
committed
update-script/rust-analyzer: Filter out headers from option descriptions
Headers are not allowed in nixpkgs option descriptions.
1 parent ad704dd commit dbf6f7b

File tree

4 files changed

+44
-24
lines changed

4 files changed

+44
-24
lines changed

generated/rust-analyzer.nix

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,15 +1987,18 @@
19871987
};
19881988
"rust-analyzer.workspace.discoverConfig" = {
19891989
description = ''
1990-
Enables automatic discovery of projects using [`DiscoverWorkspaceConfig::command`].
1990+
Enables automatic discovery of projects using
1991+
\[`DiscoverWorkspaceConfig::command`\].
19911992
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.
1993+
\[`DiscoverWorkspaceConfig`\] also requires setting `progress_label` and
1994+
`files_to_watch`. `progress_label` is used for the title in progress
1995+
indicators, whereas `files_to_watch` is used to determine which build
1996+
system-specific files should be watched in order to reload
1997+
rust-analyzer.
19961998
19971999
Below is an example of a valid configuration:
1998-
```json
2000+
2001+
``` json
19992002
"rust-analyzer.workspace.discoverConfig": {
20002003
"command": [
20012004
"rust-project",
@@ -2009,14 +2012,14 @@
20092012
}
20102013
```
20112014
2012-
## On `DiscoverWorkspaceConfig::command`
2015+
**On `DiscoverWorkspaceConfig::command`**
20132016
20142017
**Warning**: This format is provisional and subject to change.
20152018
2016-
[`DiscoverWorkspaceConfig::command`] *must* return a JSON object
2019+
\[`DiscoverWorkspaceConfig::command`\] *must* return a JSON object
20172020
corresponding to `DiscoverProjectData::Finished`:
20182021
2019-
```norun
2022+
``` norun
20202023
#[derive(Debug, Clone, Deserialize, Serialize)]
20212024
#[serde(tag = "kind")]
20222025
#[serde(rename_all = "snake_case")]
@@ -2029,7 +2032,7 @@
20292032
20302033
As JSON, `DiscoverProjectData::Finished` is:
20312034
2032-
```json
2035+
``` json
20332036
{
20342037
// the internally-tagged representation of the enum.
20352038
"kind": "finished",
@@ -2051,7 +2054,7 @@
20512054
which will be substituted with the JSON-serialized form of the following
20522055
enum:
20532056
2054-
```norun
2057+
``` norun
20552058
#[derive(PartialEq, Clone, Debug, Serialize)]
20562059
#[serde(rename_all = "camelCase")]
20572060
pub enum DiscoverArgument {
@@ -2062,25 +2065,25 @@
20622065
20632066
The JSON representation of `DiscoverArgument::Path` is:
20642067
2065-
```json
2068+
``` json
20662069
{
20672070
"path": "src/main.rs"
20682071
}
20692072
```
20702073
20712074
Similarly, the JSON representation of `DiscoverArgument::Buildfile` is:
20722075
2073-
```
2074-
{
2075-
"buildfile": "BUILD"
2076-
}
2077-
```
2076+
{
2077+
"buildfile": "BUILD"
2078+
}
20782079
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:
2080+
`DiscoverArgument::Path` is used to find and generate a
2081+
`rust-project.json`, and therefore, a workspace, whereas
2082+
`DiscoverArgument::buildfile` is used to to update an existing
2083+
workspace. As a reference for implementors, buck2's `rust-project` will
2084+
likely be useful:
20832085
https://github.com/facebook/buck2/tree/main/integrations/rust-project.
2086+
20842087
'';
20852088
pluginDefault = null;
20862089
type = {

update-scripts/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ lib.fix (self: {
2525
# Derivations that build the generated files
2626
efmls-configs-sources = pkgs.callPackage ./efmls-configs.nix { };
2727
none-ls-builtins = pkgs.callPackage ./none-ls.nix { };
28-
rust-analyzer-options = pkgs.callPackage ./rust-analyzer.nix { };
28+
rust-analyzer-options = pkgs.callPackage ./rust-analyzer { };
2929
})

update-scripts/rust-analyzer.nix renamed to update-scripts/rust-analyzer/default.nix

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
lib,
1818
rust-analyzer,
1919
writeText,
20+
pandoc,
21+
runCommand,
2022
}:
2123
let
2224
packageJSON = "${rust-analyzer.src}/editors/code/package.json";
@@ -132,6 +134,18 @@ let
132134
type ? null,
133135
}:
134136
let
137+
filteredMarkdownDesc =
138+
# If there is a risk that the string contains an heading filter it out
139+
if lib.hasInfix "# " markdownDescription then
140+
builtins.readFile (
141+
runCommand "filtered-documentation" { inherit markdownDescription; } ''
142+
${lib.getExe pandoc} -o $out -t markdown \
143+
--lua-filter=${./heading_filter.lua} <<<"$markdownDescription"
144+
''
145+
)
146+
else
147+
markdownDescription;
148+
135149
enumDesc =
136150
values: descriptions:
137151
let
@@ -140,7 +154,7 @@ let
140154
);
141155
in
142156
''
143-
${markdownDescription}
157+
${filteredMarkdownDesc}
144158
145159
Values:
146160
${builtins.concatStringsSep "\n" valueDesc}
@@ -164,7 +178,7 @@ let
164178
enum == null && (anyOf == null || builtins.all (subProp: !(lib.hasAttr "enum" subProp)) anyOf)
165179
then
166180
''
167-
${markdownDescription}
181+
${filteredMarkdownDesc}
168182
''
169183
else if enum != null then
170184
assert lib.assertMsg (anyOf == null) "enum + anyOf types are not yet handled";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function Header(elem)
2+
return pandoc.Strong(elem.content)
3+
end

0 commit comments

Comments
 (0)