1 /* ide-diagnostics.h
2  *
3  * Copyright 2018-2019 Christian Hergert <chergert@redhat.com>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  * SPDX-License-Identifier: GPL-3.0-or-later
19  */
20 
21 #pragma once
22 
23 #if !defined (IDE_CODE_INSIDE) && !defined (IDE_CODE_COMPILATION)
24 # error "Only <libide-code.h> can be included directly."
25 #endif
26 
27 #include <libide-core.h>
28 
29 #include "ide-code-types.h"
30 #include "ide-diagnostic.h"
31 
32 G_BEGIN_DECLS
33 
34 #define IDE_TYPE_DIAGNOSTICS (ide_diagnostics_get_type())
35 
36 IDE_AVAILABLE_IN_3_32
37 G_DECLARE_DERIVABLE_TYPE (IdeDiagnostics, ide_diagnostics, IDE, DIAGNOSTICS, IdeObject)
38 
39 /**
40  * IdeDiagnosticsLineCallback:
41  * @line: the line number, starting from 0
42  * @severity: the severity of the diagnostic
43  * @user_data: user data provided with callback
44  *
45  * This function prototype is used to notify a caller of every line that has a
46  * diagnostic, and the most severe #IdeDiagnosticSeverity for that line.
47  *
48  * Since: 3.32
49  */
50 typedef void (*IdeDiagnosticsLineCallback) (guint                 line,
51                                             IdeDiagnosticSeverity severity,
52                                             gpointer              user_data);
53 
54 struct _IdeDiagnosticsClass
55 {
56   IdeObjectClass parent_class;
57 
58   /*< private >*/
59   gpointer _reserved[16];
60 };
61 
62 IDE_AVAILABLE_IN_3_32
63 IdeDiagnostics *ide_diagnostics_new                     (void);
64 IDE_AVAILABLE_IN_3_32
65 IdeDiagnostics *ide_diagnostics_new_from_array          (GPtrArray                  *array);
66 IDE_AVAILABLE_IN_3_32
67 void            ide_diagnostics_add                     (IdeDiagnostics             *self,
68                                                          IdeDiagnostic              *diagnostic);
69 IDE_AVAILABLE_IN_3_32
70 void            ide_diagnostics_take                    (IdeDiagnostics             *self,
71                                                          IdeDiagnostic              *diagnostic);
72 IDE_AVAILABLE_IN_3_32
73 void            ide_diagnostics_merge                   (IdeDiagnostics             *self,
74                                                          IdeDiagnostics             *other);
75 IDE_AVAILABLE_IN_3_32
76 guint           ide_diagnostics_get_n_errors            (IdeDiagnostics             *self);
77 IDE_AVAILABLE_IN_3_32
78 gboolean        ide_diagnostics_get_has_errors          (IdeDiagnostics             *self);
79 IDE_AVAILABLE_IN_3_32
80 guint           ide_diagnostics_get_n_warnings          (IdeDiagnostics             *self);
81 IDE_AVAILABLE_IN_3_32
82 gboolean        ide_diagnostics_get_has_warnings        (IdeDiagnostics             *self);
83 IDE_AVAILABLE_IN_3_32
84 void            ide_diagnostics_foreach_line_in_range   (IdeDiagnostics             *self,
85                                                          GFile                      *file,
86                                                          guint                       begin_line,
87                                                          guint                       end_line,
88                                                          IdeDiagnosticsLineCallback  callback,
89                                                          gpointer                    user_data);
90 IDE_AVAILABLE_IN_3_32
91 IdeDiagnostic  *ide_diagnostics_get_diagnostic_at_line  (IdeDiagnostics             *self,
92                                                          GFile                      *file,
93                                                          guint                       line);
94 IDE_AVAILABLE_IN_3_38
95 GPtrArray      *ide_diagnostics_get_diagnostics_at_line (IdeDiagnostics             *self,
96                                                          GFile                      *file,
97                                                          guint                       line);
98 
99 #define ide_diagnostics_get_size(d) ((gsize)g_list_model_get_n_items(G_LIST_MODEL(d)))
100 
101 G_END_DECLS
102