Skip to content
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

chore(core): implement pull_diagnostics for graphql #3248

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"))
}
}