Skip to content

Commit 4ddcf8c

Browse files
committed
feat: add code to dianostic
1 parent a9b6859 commit 4ddcf8c

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

crates/cli/tests/json/hql_file.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"tests/lint/hql_file.hql":[{"range":{"start":{"line":1,"character":7},"end":{"line":1,"character":7}},"message":"Expected only single space before \"1\". Found \" \".","severity":"Error","source":"sqruff"},{"range":{"start":{"line":1,"character":11},"end":{"line":1,"character":11}},"message":"Files must end with a single trailing newline.","severity":"Error","source":"sqruff"}]}
1+
{"tests/lint/hql_file.hql":[{"range":{"start":{"line":1,"character":7},"end":{"line":1,"character":7}},"message":"Expected only single space before \"1\". Found \" \".","severity":"Error","source":"sqruff","code":"LT01"},{"range":{"start":{"line":1,"character":11},"end":{"line":1,"character":11}},"message":"Files must end with a single trailing newline.","severity":"Error","source":"sqruff","code":"LT12"}]}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"tests/lint/test_fail_whitespace_before_comma.sql":[{"range":{"start":{"line":1,"character":8},"end":{"line":1,"character":8}},"message":"Column expression without alias. Use explicit `AS` clause.","severity":"Error","source":"sqruff"},{"range":{"start":{"line":1,"character":11},"end":{"line":1,"character":11}},"message":"Column expression without alias. Use explicit `AS` clause.","severity":"Error","source":"sqruff"},{"range":{"start":{"line":1,"character":9},"end":{"line":1,"character":9}},"message":"Unexpected whitespace before comma.","severity":"Error","source":"sqruff"},{"range":{"start":{"line":1,"character":11},"end":{"line":1,"character":11}},"message":"Expected single whitespace between \",\" and \"4\".","severity":"Error","source":"sqruff"},{"range":{"start":{"line":1,"character":12},"end":{"line":1,"character":12}},"message":"Files must end with a single trailing newline.","severity":"Error","source":"sqruff"}]}
1+
{"tests/lint/test_fail_whitespace_before_comma.sql":[{"range":{"start":{"line":1,"character":8},"end":{"line":1,"character":8}},"message":"Column expression without alias. Use explicit `AS` clause.","severity":"Error","source":"sqruff","code":"AL03"},{"range":{"start":{"line":1,"character":11},"end":{"line":1,"character":11}},"message":"Column expression without alias. Use explicit `AS` clause.","severity":"Error","source":"sqruff","code":"AL03"},{"range":{"start":{"line":1,"character":9},"end":{"line":1,"character":9}},"message":"Unexpected whitespace before comma.","severity":"Error","source":"sqruff","code":"LT01"},{"range":{"start":{"line":1,"character":11},"end":{"line":1,"character":11}},"message":"Expected single whitespace between \",\" and \"4\".","severity":"Error","source":"sqruff","code":"LT01"},{"range":{"start":{"line":1,"character":12},"end":{"line":1,"character":12}},"message":"Files must end with a single trailing newline.","severity":"Error","source":"sqruff","code":"LT12"}]}

crates/lib/src/cli/json_types.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use sqruff_lib_core::errors::SQLBaseError;
55

66
impl From<SQLBaseError> for Diagnostic {
77
fn from(value: SQLBaseError) -> Self {
8+
let code = value.rule.map(|rule| rule.code.to_string());
89
Diagnostic {
910
range: Range {
1011
start: Position::new(value.line_no as u32, value.line_pos as u32),
@@ -17,6 +18,7 @@ impl From<SQLBaseError> for Diagnostic {
1718
DiagnosticSeverity::Error
1819
},
1920
source: Some("sqruff".to_string()),
21+
code,
2022
// code: todo!(),
2123
// source: Some(value.get_source().to_string()),
2224
// code: Some(DiagnosticCode {
@@ -65,15 +67,24 @@ pub struct Diagnostic {
6567
pub severity: DiagnosticSeverity,
6668
/// A human-readable string describing the source of this diagnostic, e.g. 'typescript' or 'super lint'.
6769
source: Option<String>,
68-
// A code or identifier for this diagnostic. Should be used for later processing, e.g. when providing {@link CodeActionContext code actions}.
69-
// code: Option<DiagnosticCode>,
70+
// The diagnostic's code, which might appear in the user interface.
71+
code: Option<String>,
72+
// An optional property to describe the error code.
73+
// code_description: Option<CodeDescription>,
7074
// TODO Maybe implement
7175
// An array of related diagnostic information, e.g. when symbol-names within a scope collide all definitions can be marked via this property.
7276
// related_information: Vec<DiagnosticRelatedInformation>,
7377
// Additional metadata about the diagnostic.
7478
// tags: Vec<DiagnosticTag>,
7579
}
7680

81+
// Structure to capture a description for an error code.
82+
// #[derive(Serialize)]
83+
// pub struct CodeDescription {
84+
// /// An URI to open with more information about the diagnostic error.
85+
// href: String,
86+
// }
87+
7788
// /// Represents a related message and source code location for a diagnostic. This should be used to point to code locations that cause or are related to a diagnostics, e.g when duplicating a symbol in a scope.
7889
// #[derive(Serialize)]
7990
// struct DiagnosticCode {

0 commit comments

Comments
 (0)