Skip to content

Commit

Permalink
chore(core): implement pull_diagnostics for graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Jun 21, 2024
1 parent ad7881a commit a96d464
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
13 changes: 11 additions & 2 deletions crates/biome_service/src/file_handlers/graphql.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{DocumentFileSource, ExtensionHandler, ParseResult};
use super::{DocumentFileSource, ExtensionHandler, LintParams, LintResults, ParseResult};
use crate::file_handlers::DebugCapabilities;
use crate::file_handlers::{
AnalyzerCapabilities, Capabilities, FormatterCapabilities, ParserCapabilities,
Expand Down Expand Up @@ -66,7 +66,7 @@ impl ExtensionHandler for GraphqlFileHandler {
debug_formatter_ir: None,
},
analyzer: AnalyzerCapabilities {
lint: None,
lint: Some(lint),
code_actions: None,
rename: None,
fix_all: None,
Expand Down Expand Up @@ -110,3 +110,12 @@ fn debug_syntax_tree(_rome_path: &BiomePath, parse: AnyParse) -> GetSyntaxTreeRe
ast: format!("{tree:#?}"),
}
}

fn lint(params: LintParams) -> LintResults {
let diagnostics = params.parse.into_diagnostics();
LintResults {
errors: diagnostics.len(),
diagnostics,
skipped_diagnostics: 0,
}
}
10 changes: 4 additions & 6 deletions crates/biome_service/src/file_handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl DocumentFileSource {
if let Ok(file_source) = CssFileSource::try_from_well_known(file_name) {
return Ok(file_source.into());
}
if cfg!(feature = "graphql") {
if cfg!(feature = "graphql") || cfg!(debug_assertions) {
if let Ok(file_source) = GraphqlFileSource::try_from_well_known(file_name) {
return Ok(file_source.into());
}
Expand All @@ -120,7 +120,7 @@ impl DocumentFileSource {
if let Ok(file_source) = CssFileSource::try_from_extension(extension) {
return Ok(file_source.into());
}
if cfg!(feature = "graphql") {
if cfg!(feature = "graphql") || cfg!(debug_assertions) {
if let Ok(file_source) = GraphqlFileSource::try_from_extension(extension) {
return Ok(file_source.into());
}
Expand All @@ -147,7 +147,7 @@ impl DocumentFileSource {
if let Ok(file_source) = CssFileSource::try_from_language_id(language_id) {
return Ok(file_source.into());
}
if cfg!(feature = "graphql") {
if cfg!(feature = "graphql") || cfg!(debug_assertions) {
if let Ok(file_source) = GraphqlFileSource::try_from_language_id(language_id) {
return Ok(file_source.into());
}
Expand Down Expand Up @@ -297,9 +297,7 @@ impl DocumentFileSource {
EmbeddingKind::None => true,
},
DocumentFileSource::Json(_) | DocumentFileSource::Css(_) => true,
DocumentFileSource::Graphql(_) => {
cfg!(feature = "graphql")
}
DocumentFileSource::Graphql(_) => cfg!(feature = "graphql") || cfg!(debug_assertions),
DocumentFileSource::Unknown => false,
}
}
Expand Down
29 changes: 29 additions & 0 deletions crates/biome_service/tests/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,33 @@ mod test {
.format_file()
.is_ok());
}

#[test]
fn correctly_parses_graphql_files() {
let workspace = create_server();

let graphql_file = FileGuard::open(
workspace.as_ref(),
OpenFileParams {
path: BiomePath::new("file.graphql"),
content: r#"type Query {
me: User
}
type User {
id: ID
name: String
}"#
.into(),
version: 0,
document_file_source: None,
},
)
.unwrap();
let result = graphql_file.get_syntax_tree();
assert!(result.is_ok());
let syntax = result.unwrap().ast;

assert!(syntax.starts_with("GraphqlRoot"))
}
}

0 comments on commit a96d464

Please sign in to comment.