mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-31 03:54:42 +00:00 
			
		
		
		
	Make rust-analyzer.files.excludeDirs work, actually
				
					
				
			I have no idea what the original writer of the code thought but the logic just seems backwards. We should not exclude a file/directory if it is equal to an include! This also meant that we had to add a `root == path` check so this stuff will actually work, which in turn meant excludes (of root files) no longer worked... Also rename if to `rust-analyzer.files.exclude`, because it can exclude files as well.
This commit is contained in:
		
							parent
							
								
									0fd4fc3522
								
							
						
					
					
						commit
						ac6b054ca5
					
				
					 5 changed files with 46 additions and 11 deletions
				
			
		|  | @ -84,10 +84,10 @@ config_data! { | |||
|         completion_snippets_custom: FxHashMap<String, SnippetDef> = Config::completion_snippets_default(), | ||||
| 
 | ||||
| 
 | ||||
|         /// These directories will be ignored by rust-analyzer. They are
 | ||||
|         /// These paths (file/directories) will be ignored by rust-analyzer. They are
 | ||||
|         /// relative to the workspace root, and globs are not supported. You may
 | ||||
|         /// also need to add the folders to Code's `files.watcherExclude`.
 | ||||
|         files_excludeDirs: Vec<Utf8PathBuf> = vec![], | ||||
|         files_exclude | files_excludeDirs: Vec<Utf8PathBuf> = vec![], | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|  | @ -1787,7 +1787,7 @@ impl Config { | |||
| 
 | ||||
|     fn discovered_projects(&self) -> Vec<ManifestOrProjectJson> { | ||||
|         let exclude_dirs: Vec<_> = | ||||
|             self.files_excludeDirs().iter().map(|p| self.root_path.join(p)).collect(); | ||||
|             self.files_exclude().iter().map(|p| self.root_path.join(p)).collect(); | ||||
| 
 | ||||
|         let mut projects = vec![]; | ||||
|         for fs_proj in &self.discovered_projects_from_filesystem { | ||||
|  | @ -1909,7 +1909,7 @@ impl Config { | |||
|                 } | ||||
|                 _ => FilesWatcher::Server, | ||||
|             }, | ||||
|             exclude: self.files_excludeDirs().iter().map(|it| self.root_path.join(it)).collect(), | ||||
|             exclude: self.files_exclude().iter().map(|it| self.root_path.join(it)).collect(), | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1372,6 +1372,40 @@ pub fn foo() {} | |||
| name = "bar" | ||||
| version = "0.0.0" | ||||
| 
 | ||||
| [dependencies] | ||||
| foo = { path = "../foo" } | ||||
| 
 | ||||
| //- /bar/src/lib.rs
 | ||||
| "#,
 | ||||
|     ) | ||||
|     .root("foo") | ||||
|     .root("bar") | ||||
|     .root("baz") | ||||
|     .with_config(json!({ | ||||
|        "files": { | ||||
|            "exclude": ["foo"] | ||||
|         } | ||||
|     })) | ||||
|     .server() | ||||
|     .wait_until_workspace_is_loaded(); | ||||
| 
 | ||||
|     server.request::<WorkspaceSymbolRequest>(Default::default(), json!([])); | ||||
| 
 | ||||
|     let server = Project::with_fixture( | ||||
|         r#" | ||||
| //- /foo/Cargo.toml
 | ||||
| [package] | ||||
| name = "foo" | ||||
| version = "0.0.0" | ||||
| 
 | ||||
| //- /foo/src/lib.rs
 | ||||
| pub fn foo() {} | ||||
| 
 | ||||
| //- /bar/Cargo.toml
 | ||||
| [package] | ||||
| name = "bar" | ||||
| version = "0.0.0" | ||||
| 
 | ||||
| //- /bar/src/lib.rs
 | ||||
| pub fn bar() {} | ||||
| 
 | ||||
|  | @ -1388,7 +1422,7 @@ version = "0.0.0" | |||
|     .root("baz") | ||||
|     .with_config(json!({ | ||||
|        "files": { | ||||
|            "excludeDirs": ["foo", "bar"] | ||||
|            "exclude": ["foo", "bar"] | ||||
|         } | ||||
|     })) | ||||
|     .server() | ||||
|  |  | |||
|  | @ -280,8 +280,9 @@ impl NotifyActor { | |||
|                                 return false; | ||||
|                             } | ||||
| 
 | ||||
|                             root == path | ||||
|                                 || dirs.exclude.iter().chain(&dirs.include).all(|it| it != path) | ||||
|                             // We want to filter out subdirectories that are roots themselves, because they will be visited separately.
 | ||||
|                             dirs.exclude.iter().all(|it| it != path) | ||||
|                                 && (root == path || dirs.include.iter().all(|it| it != path)) | ||||
|                         }); | ||||
| 
 | ||||
|                     let files = walkdir.filter_map(|it| it.ok()).filter_map(|entry| { | ||||
|  |  | |||
|  | @ -470,9 +470,9 @@ The warnings will be indicated by a blue squiggly underline in code | |||
| and a blue icon in the `Problems Panel`. | ||||
| 
 | ||||
| 
 | ||||
| **rust-analyzer.files.excludeDirs** (default: []) | ||||
| **rust-analyzer.files.exclude** (default: []) | ||||
| 
 | ||||
|  These directories will be ignored by rust-analyzer. They are | ||||
|  These paths (file/directories) will be ignored by rust-analyzer. They are | ||||
| relative to the workspace root, and globs are not supported. You may | ||||
| also need to add the folders to Code's `files.watcherExclude`. | ||||
| 
 | ||||
|  |  | |||
|  | @ -1473,8 +1473,8 @@ | |||
|             { | ||||
|                 "title": "files", | ||||
|                 "properties": { | ||||
|                     "rust-analyzer.files.excludeDirs": { | ||||
|                         "markdownDescription": "These directories will be ignored by rust-analyzer. They are\nrelative to the workspace root, and globs are not supported. You may\nalso need to add the folders to Code's `files.watcherExclude`.", | ||||
|                     "rust-analyzer.files.exclude": { | ||||
|                         "markdownDescription": "These paths (file/directories) will be ignored by rust-analyzer. They are\nrelative to the workspace root, and globs are not supported. You may\nalso need to add the folders to Code's `files.watcherExclude`.", | ||||
|                         "default": [], | ||||
|                         "type": "array", | ||||
|                         "items": { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Chayim Refael Friedman
						Chayim Refael Friedman