Repository: rust-lang/rust-analyzer (rust)

Issue:
Support `.rust-project.json` (i.e. hidden)
In the Linux kernel, we use rust-analyzer with a `rust-project.json` file.

However, it appears that there is no support for a hidden version of that configuration file, i.e. `.rust-project.json`, which means it is very visible when listing the root directory of the kernel sources (though only when generated, since the file is not committed into the repository and thus only visible when using rust-analyzer).

While this is only an issue for kernel developers that use Rust (i.e. so far a very small number compared to the total), since the file is normally not there, the file is not really something most kernel developers need to see, care or modify while working, so it is not really needed to show it in listings, and so a hidden `.rust-project.json` file would be better. I guess for other projects that may be the case as well.

This would follow other files like `.clang-format`, `.gitignore`, `.gitattributes`, `.mailmap`, `.rustfmt.toml`, etc. where configuration is not directly related to the project (say, a `Kconfig` file) but to tooling.

Pull request description:
Allow rust-project.json to be hidden
Closes #17816 

Patch:
diff --git a/crates/project-model/src/lib.rs b/crates/project-model/src/lib.rs
index 6510ced66a..32280d5c76 100644
--- a/crates/project-model/src/lib.rs
+++ b/crates/project-model/src/lib.rs
@@ -68,6 +68,9 @@ impl ProjectManifest {
         if path.file_name().unwrap_or_default() == "rust-project.json" {
             return Ok(ProjectManifest::ProjectJson(path));
         }
+        if path.file_name().unwrap_or_default() == ".rust-project.json" {
+            return Ok(ProjectManifest::ProjectJson(path));
+        }
         if path.file_name().unwrap_or_default() == "Cargo.toml" {
             return Ok(ProjectManifest::CargoToml(path));
         }
@@ -94,6 +97,9 @@ impl ProjectManifest {
         if let Some(project_json) = find_in_parent_dirs(path, "rust-project.json") {
             return Ok(vec![ProjectManifest::ProjectJson(project_json)]);
         }
+        if let Some(project_json) = find_in_parent_dirs(path, ".rust-project.json") {
+            return Ok(vec![ProjectManifest::ProjectJson(project_json)]);
+        }
         return find_cargo_toml(path)
             .map(|paths| paths.into_iter().map(ProjectManifest::CargoToml).collect());
 
diff --git a/editors/code/package.json b/editors/code/package.json
index abb40ac35e..bf9c4a366d 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -71,7 +71,9 @@
         "workspaceContains:Cargo.toml",
         "workspaceContains:*/Cargo.toml",
         "workspaceContains:rust-project.json",
-        "workspaceContains:*/rust-project.json"
+        "workspaceContains:*/rust-project.json",
+        "workspaceContains:.rust-project.json",
+        "workspaceContains:*/.rust-project.json"
     ],
     "main": "./out/main",
     "contributes": {
@@ -3211,6 +3213,10 @@
             {
                 "fileMatch": "rust-project.json",
                 "url": "https://json.schemastore.org/rust-project.json"
+            },
+            {
+                "fileMatch": ".rust-project.json",
+                "url": "https://json.schemastore.org/rust-project.json"
             }
         ],
         "walkthroughs": [


Test patch:
diff --git a/crates/rust-analyzer/tests/slow-tests/main.rs b/crates/rust-analyzer/tests/slow-tests/main.rs
index 9d292c0411..54cd27f4b3 100644
--- a/crates/rust-analyzer/tests/slow-tests/main.rs
+++ b/crates/rust-analyzer/tests/slow-tests/main.rs
@@ -750,7 +750,7 @@ fn test_missing_module_code_action_in_json_project() {
 
     let code = format!(
         r#"
-//- /rust-project.json
+//- /.rust-project.json
 {project}
 
 //- /src/lib.rs