-
Notifications
You must be signed in to change notification settings - Fork 17
Allow linter configuration to filter graph diagnostics #1000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| use crate::graph_api::{GraphPointer, with_graph}; | ||
| use crate::location_api::{Location, create_location_for_uri_and_offset}; | ||
| use libc::c_char; | ||
| use rubydex::diagnostic::Severity; | ||
| use rubydex::diagnostic::{Rule, Severity}; | ||
| use std::{ffi::CString, mem, ptr}; | ||
|
|
||
| /// C-compatible enum representing diagnostic severity levels. | ||
|
|
@@ -52,6 +52,39 @@ impl DiagnosticArray { | |
| } | ||
| } | ||
|
|
||
| /// Writes a Rust-allocated array containing every graph diagnostic rule name to `out_names` and returns its length. | ||
| /// The caller must free the array with `free_c_string_array`. Writes null and returns zero when there are no names. | ||
| /// | ||
| /// # Panics | ||
| /// | ||
| /// Panics if a generated rule name contains `\0`, which C strings cannot represent. | ||
| /// | ||
| /// # Safety | ||
| /// | ||
| /// - `out_names` must be a valid, writable pointer. | ||
| #[unsafe(no_mangle)] | ||
| pub unsafe extern "C" fn rdx_graph_diagnostic_names(out_names: *mut *const *const c_char) -> usize { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it belongs to If we want the names of the rules, so that they can be filtered, then shouldn't this method be in |
||
| let c_strings: Vec<*const c_char> = Rule::ALL | ||
| .iter() | ||
| .map(ToString::to_string) | ||
| .map(|name| { | ||
| CString::new(name) | ||
| .expect("generated graph diagnostic rule names cannot contain null bytes") | ||
| .into_raw() | ||
| .cast_const() | ||
| }) | ||
| .collect(); | ||
| let count = c_strings.len(); | ||
|
|
||
| if count == 0 { | ||
| unsafe { *out_names = ptr::null() }; | ||
| return 0; | ||
| } | ||
|
|
||
| unsafe { *out_names = Box::into_raw(c_strings.into_boxed_slice()).cast::<*const c_char>() }; | ||
| count | ||
| } | ||
|
|
||
| /// Returns all diagnostics currently recorded in the global graph. | ||
| /// | ||
| /// # Safety | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we ever reach this point from the CLI if
known_rule_classesis empty?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a test where the CLI without a rule should at least show the built-in diagnostics?