Debian Codegraph @

src/term.rs

raw symbols SCIP
1 //! Terminal back-end for emitting diagnostics.
2
3 #[cfg(feature = "termcolor")]
4 use termcolorrust-analyzer cargo termcolor 1.4.1 crate/::WriteColorrust-analyzer cargo termcolor 1.4.1 WriteColor#;
5
6 use craterust-analyzer cargo codespan-reporting 0.12.0 crate/::diagnosticrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/::Diagnosticrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#;
7 use craterust-analyzer cargo codespan-reporting 0.12.0 crate/::filesrust-analyzer cargo codespan-reporting 0.12.0 files/::Filesrust-analyzer cargo codespan-reporting 0.12.0 files/Files#;
8
9 mod configrust-analyzer cargo codespan-reporting 0.12.0 term/config/;
10 mod rendererrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/;
11 mod viewsrust-analyzer cargo codespan-reporting 0.12.0 term/views/;
12
13 #[cfg(feature = "termcolor")]
14 pub use termcolorrust-analyzer cargo termcolor 1.4.1 crate/;
15
16 pub use selfrust-analyzer cargo codespan-reporting 0.12.0 term/::configrust-analyzer cargo codespan-reporting 0.12.0 term/config/::{Charsrust-analyzer cargo codespan-reporting 0.12.0 term/config/Chars#, Configrust-analyzer cargo codespan-reporting 0.12.0 term/config/Config#, DisplayStylerust-analyzer cargo codespan-reporting 0.12.0 term/config/DisplayStyle#};
17
18 #[cfg(feature = "termcolor")]
19 pub use selfrust-analyzer cargo codespan-reporting 0.12.0 term/::configrust-analyzer cargo codespan-reporting 0.12.0 term/config/::Stylesrust-analyzer cargo codespan-reporting 0.12.0 term/config/Styles#;
20
21 /// Emit a diagnostic using the given writer, context, config, and files.
22 ///
23 /// The return value covers all error cases. These error case can arise if:
24 /// * a file was removed from the file database.
25 /// * a file was changed so that it is too small to have an index
26 /// * IO fails
27 pub fn emitrust-analyzer cargo codespan-reporting 0.12.0 term/emit().<'files, F: Filesrust-analyzer cargo codespan-reporting 0.12.0 files/Files#<'files> + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(
28 #[cfg(feature = "termcolor")] writer: &mut dyn WriteColorrust-analyzer cargo termcolor 1.4.1 WriteColor#,
29 #[cfg(all(not(feature = "termcolor"), feature = "std"))] writer: &mut dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#,
30 #[cfg(all(not(feature = "termcolor"), not(feature = "std")))] writer: &mut dyn corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#,
31 config: &Configrust-analyzer cargo codespan-reporting 0.12.0 term/config/Config#,
32 files: &'files F,
33 diagnostic: &Diagnosticrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#<F::FileIdrust-analyzer cargo codespan-reporting 0.12.0 files/Files#FileId#>,
34 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), superrust-analyzer cargo codespan-reporting 0.12.0 crate/::filesrust-analyzer cargo codespan-reporting 0.12.0 files/::Errorrust-analyzer cargo codespan-reporting 0.12.0 files/Error#> {
35 use selfrust-analyzer cargo codespan-reporting 0.12.0 term/::rendererrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/::Rendererrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/Renderer#;
36 use selfrust-analyzer cargo codespan-reporting 0.12.0 term/::viewsrust-analyzer cargo codespan-reporting 0.12.0 term/views/::{RichDiagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#, ShortDiagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#};
37
38 let mut renderer = Rendererrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/Renderer#::newrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/impl#[`Renderer<'writer, 'config>`]new().(writer, config);
39 match config.display_stylerust-analyzer cargo codespan-reporting 0.12.0 term/config/Config#display_style. {
40 DisplayStylerust-analyzer cargo codespan-reporting 0.12.0 term/config/DisplayStyle#::Richrust-analyzer cargo codespan-reporting 0.12.0 term/config/DisplayStyle#Rich# => RichDiagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#::newrust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`RichDiagnostic<'diagnostic, 'config, FileId>`]new().(diagnostic, config).renderrust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`RichDiagnostic<'diagnostic, 'config, FileId>`]render().(files, &mut renderer),
41 DisplayStylerust-analyzer cargo codespan-reporting 0.12.0 term/config/DisplayStyle#::Mediumrust-analyzer cargo codespan-reporting 0.12.0 term/config/DisplayStyle#Medium# => ShortDiagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#::newrust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`ShortDiagnostic<'diagnostic, FileId>`]new().(diagnostic, true).renderrust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`ShortDiagnostic<'diagnostic, FileId>`]render().(files, &mut renderer),
42 DisplayStylerust-analyzer cargo codespan-reporting 0.12.0 term/config/DisplayStyle#::Shortrust-analyzer cargo codespan-reporting 0.12.0 term/config/DisplayStyle#Short# => ShortDiagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#::newrust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`ShortDiagnostic<'diagnostic, FileId>`]new().(diagnostic, false).renderrust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`ShortDiagnostic<'diagnostic, FileId>`]render().(files, &mut renderer),
43 }
44 }
45
46 #[cfg(all(test, feature = "termcolor"))]
47 mod testsrust-analyzer cargo codespan-reporting 0.12.0 term/tests/ {
48 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::{vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#};
49
50 use superrust-analyzer cargo codespan-reporting 0.12.0 term/::*;
51
52 use craterust-analyzer cargo codespan-reporting 0.12.0 crate/::diagnosticrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/::Labelrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#;
53 use craterust-analyzer cargo codespan-reporting 0.12.0 crate/::filesrust-analyzer cargo codespan-reporting 0.12.0 files/::SimpleFilesrust-analyzer cargo codespan-reporting 0.12.0 files/SimpleFiles#;
54
55 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
56 fn unsized_emitrust-analyzer cargo codespan-reporting 0.12.0 term/tests/unsized_emit().() {
57 let mut files = SimpleFilesrust-analyzer cargo codespan-reporting 0.12.0 files/SimpleFiles#::newrust-analyzer cargo codespan-reporting 0.12.0 files/impl#[`SimpleFiles<Name, Source>`]new().();
58
59 let id = files.addrust-analyzer cargo codespan-reporting 0.12.0 files/impl#[`SimpleFiles<Name, Source>`]add().("test", "");
60 let mut writer = termcolorrust-analyzer cargo termcolor 1.4.1 crate/::NoColorrust-analyzer cargo termcolor 1.4.1 NoColor#::newrust-analyzer cargo termcolor 1.4.1 impl#[`NoColor<W>`]new().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::<u8>::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().());
61 let diagnostic = Diagnosticrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#::bugrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Diagnostic<FileId>`]bug().().with_labelsrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Diagnostic<FileId>`]with_labels().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Labelrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#::primaryrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Label<FileId>`]primary().(id, 0..0)]);
62
63 emitrust-analyzer cargo codespan-reporting 0.12.0 term/emit().(&mut writer, &Configrust-analyzer cargo codespan-reporting 0.12.0 term/config/Config#::defaultrust-analyzer cargo codespan-reporting 0.12.0 term/config/impl#[Config][Default]default().(), &files, &diagnostic).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
64 }
65 }