diff options
Diffstat (limited to 'crates/ide/src/diagnostics/fixes')
-rw-r--r-- | crates/ide/src/diagnostics/fixes/unresolved_module.rs | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/crates/ide/src/diagnostics/fixes/unresolved_module.rs b/crates/ide/src/diagnostics/fixes/unresolved_module.rs deleted file mode 100644 index b3d0283bb..000000000 --- a/crates/ide/src/diagnostics/fixes/unresolved_module.rs +++ /dev/null | |||
@@ -1,89 +0,0 @@ | |||
1 | use hir::{db::AstDatabase, diagnostics::UnresolvedModule, Semantics}; | ||
2 | use ide_assists::{Assist, AssistResolveStrategy}; | ||
3 | use ide_db::{base_db::AnchoredPathBuf, source_change::FileSystemEdit, RootDatabase}; | ||
4 | use syntax::AstNode; | ||
5 | |||
6 | use crate::diagnostics::{fix, DiagnosticWithFixes}; | ||
7 | |||
8 | impl DiagnosticWithFixes for UnresolvedModule { | ||
9 | fn fixes( | ||
10 | &self, | ||
11 | sema: &Semantics<RootDatabase>, | ||
12 | _resolve: &AssistResolveStrategy, | ||
13 | ) -> Option<Vec<Assist>> { | ||
14 | let root = sema.db.parse_or_expand(self.file)?; | ||
15 | let unresolved_module = self.decl.to_node(&root); | ||
16 | Some(vec![fix( | ||
17 | "create_module", | ||
18 | "Create module", | ||
19 | FileSystemEdit::CreateFile { | ||
20 | dst: AnchoredPathBuf { | ||
21 | anchor: self.file.original_file(sema.db), | ||
22 | path: self.candidate.clone(), | ||
23 | }, | ||
24 | initial_contents: "".to_string(), | ||
25 | } | ||
26 | .into(), | ||
27 | unresolved_module.syntax().text_range(), | ||
28 | )]) | ||
29 | } | ||
30 | } | ||
31 | |||
32 | #[cfg(test)] | ||
33 | mod tests { | ||
34 | use expect_test::expect; | ||
35 | |||
36 | use crate::diagnostics::tests::check_expect; | ||
37 | |||
38 | #[test] | ||
39 | fn test_unresolved_module_diagnostic() { | ||
40 | check_expect( | ||
41 | r#"mod foo;"#, | ||
42 | expect![[r#" | ||
43 | [ | ||
44 | Diagnostic { | ||
45 | message: "unresolved module", | ||
46 | range: 0..8, | ||
47 | severity: Error, | ||
48 | fixes: Some( | ||
49 | [ | ||
50 | Assist { | ||
51 | id: AssistId( | ||
52 | "create_module", | ||
53 | QuickFix, | ||
54 | ), | ||
55 | label: "Create module", | ||
56 | group: None, | ||
57 | target: 0..8, | ||
58 | source_change: Some( | ||
59 | SourceChange { | ||
60 | source_file_edits: {}, | ||
61 | file_system_edits: [ | ||
62 | CreateFile { | ||
63 | dst: AnchoredPathBuf { | ||
64 | anchor: FileId( | ||
65 | 0, | ||
66 | ), | ||
67 | path: "foo.rs", | ||
68 | }, | ||
69 | initial_contents: "", | ||
70 | }, | ||
71 | ], | ||
72 | is_snippet: false, | ||
73 | }, | ||
74 | ), | ||
75 | }, | ||
76 | ], | ||
77 | ), | ||
78 | unused: false, | ||
79 | code: Some( | ||
80 | DiagnosticCode( | ||
81 | "unresolved-module", | ||
82 | ), | ||
83 | ), | ||
84 | }, | ||
85 | ] | ||
86 | "#]], | ||
87 | ); | ||
88 | } | ||
89 | } | ||