Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions prisma-fmt/src/code_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use psl::{
walkers::{ModelWalker, RefinedRelationWalker, ScalarFieldWalker},
SourceFile,
},
schema_ast::ast::{self, Attribute, IndentationType, NewlineType, WithSpan},
schema_ast::ast::{self, Attribute, IndentationType, NewlineType, WithAttributes, WithSpan},
PreviewFeature,
};
use std::collections::HashMap;
Expand Down Expand Up @@ -181,7 +181,7 @@ fn create_missing_attribute<'a>(
&attribute,
model.indentation(),
model.newline(),
&model.ast_model().attributes,
model.ast_model().attributes(),
);

let range = range_after_span(model.ast_model().span(), schema);
Expand Down
2 changes: 1 addition & 1 deletion prisma-fmt/src/code_actions/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(super) fn add_missing_opposite_relation(

let name_arg = field
.ast_field()
.attributes
.attributes()
.iter()
.find(|attr| attr.name() == "relation")
.and_then(|attr| attr.arguments.arguments.iter().find(|arg| arg.value.is_string()));
Expand Down
4 changes: 2 additions & 2 deletions prisma-fmt/src/code_actions/multi_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use lsp_types::{CodeAction, CodeActionKind, CodeActionOrCommand};
use psl::{
diagnostics::Span,
parser_database::walkers::{EnumWalker, ModelWalker},
schema_ast::ast::WithSpan,
schema_ast::ast::{WithAttributes, WithSpan},
};

use super::CodeActionsContext;
Expand Down Expand Up @@ -42,7 +42,7 @@ pub(super) fn add_schema_block_attribute_model(
"schema()",
model.indentation(),
model.newline(),
&model.ast_model().attributes,
model.ast_model().attributes(),
);

let Ok(edit) = super::create_text_edit(
Expand Down
4 changes: 2 additions & 2 deletions prisma-fmt/src/code_actions/relation_mode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use lsp_types::{CodeAction, CodeActionKind, CodeActionOrCommand};
use psl::{
parser_database::walkers::CompleteInlineRelationWalker,
schema_ast::ast::{SourceConfig, WithIdentifier, WithName},
schema_ast::ast::{SourceConfig, WithIdentifier, WithName, WithSpan},
};

use super::CodeActionsContext;
Expand All @@ -24,7 +24,7 @@ pub(crate) fn edit_referential_integrity(
context.initiating_file_source(),
"relationMode".to_owned(),
false,
prop.identifier().span,
prop.identifier().span(),
) else {
return;
};
Expand Down
11 changes: 7 additions & 4 deletions prisma-fmt/src/code_actions/relations.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use lsp_types::{CodeAction, CodeActionKind, CodeActionOrCommand, TextEdit, WorkspaceEdit};
use psl::parser_database::{
ast::WithSpan,
walkers::{CompleteInlineRelationWalker, InlineRelationWalker, RelationFieldWalker},
use psl::{
parser_database::{
ast::WithSpan,
walkers::{CompleteInlineRelationWalker, InlineRelationWalker, RelationFieldWalker},
},
schema_ast::ast::WithAttributes,
};
use std::collections::HashMap;

Expand Down Expand Up @@ -471,7 +474,7 @@ pub(super) fn add_index_for_relation_fields(
&attribute,
relation.model().indentation(),
relation.model().newline(),
&relation.model().ast_model().attributes,
relation.model().ast_model().attributes(),
);

let range = super::range_after_span(relation.model().ast_model().span(), context.initiating_file_source());
Expand Down
4 changes: 2 additions & 2 deletions prisma-fmt/src/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ fn find_where_used_for_native_type<'ast>(
Box::new(fields.filter_map(move |field| {
field
.1
.attributes
.attributes()
.iter()
.find(|attr| extract_ds_from_native_type(attr.name()) == Some(name))
.map(|attr| attr.identifier().span())
Expand All @@ -289,7 +289,7 @@ fn find_where_used_as_field_type<'ast>(
fn get_relevent_identifiers<'a>(fields: impl Iterator<Item = (FieldId, &'a Field)>, name: &str) -> Vec<Span> {
fields
.filter_map(|(_id, field)| match &field.field_type {
FieldType::Supported(id) if id.name == name => Some(id.span()),
FieldType::Supported(id) if id.name() == name => Some(id.span()),
_ => None,
})
.collect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ model TestB {
}

model Test {
id Int @id
id Int @id
bId Int
// The user started typing Casc
b TestB @relation(fields: [testBId], references: [id], onDelete: <|>,)
testBId Int
}

16 changes: 8 additions & 8 deletions psl/parser-database/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ fn model_unique(data: &mut ModelAttributes, model_id: crate::ModelId, ctx: &mut
};

if let Some(name) = name {
validate_client_name(current_attribute.span, ast_model.name(), name, "@@unique", ctx);
validate_client_name(current_attribute.span(), ast_model.name(), name, "@@unique", ctx);
}

mapped_name
Expand All @@ -595,7 +595,7 @@ fn common_index_validations(
}
};

match resolve_field_array_with_args(fields, current_attribute.span, model_id, resolving, ctx) {
match resolve_field_array_with_args(fields, current_attribute.span(), model_id, resolving, ctx) {
Ok(fields) => {
index_data.fields = fields;
}
Expand Down Expand Up @@ -625,7 +625,7 @@ fn common_index_validations(
fields.join(", "),
);
let model_name = ctx.asts[model_id].name();
DatamodelError::new_model_validation_error(message, "model", model_name, current_attribute.span)
DatamodelError::new_model_validation_error(message, "model", model_name, current_attribute.span())
});
}

Expand Down Expand Up @@ -668,7 +668,7 @@ fn common_index_validations(
),
"model",
ctx.asts[model_id].name(),
current_attribute.span,
current_attribute.span(),
));
}
}
Expand All @@ -681,7 +681,7 @@ fn visit_relation(model_id: crate::ModelId, relation_field_id: RelationFieldId,
ctx.types[relation_field_id].relation_attribute = Some(ctx.current_attribute_id().1);

if let Some(fields) = ctx.visit_optional_arg("fields") {
let fields = match resolve_field_array_without_args(fields, attr.span, model_id, ctx) {
let fields = match resolve_field_array_without_args(fields, attr.span(), model_id, ctx) {
Ok(fields) => fields,
Err(FieldResolutionError::AlreadyDealtWith) => Vec::new(),
Err(FieldResolutionError::ProblematicFields {
Expand Down Expand Up @@ -722,7 +722,7 @@ fn visit_relation(model_id: crate::ModelId, relation_field_id: RelationFieldId,
if let Some(references) = ctx.visit_optional_arg("references") {
let references = match resolve_field_array_without_args(
references,
attr.span,
attr.span(),
ctx.types[relation_field_id].referenced_model,
ctx,
) {
Expand All @@ -745,7 +745,7 @@ fn visit_relation(model_id: crate::ModelId, relation_field_id: RelationFieldId,
"The argument `references` must refer only to existing fields in the related model `{model_name}`. The following fields do not exist in the related model: {field_names}",
);

ctx.push_error(DatamodelError::new_validation_error(&msg, attr.span));
ctx.push_error(DatamodelError::new_validation_error(&msg, attr.span()));
}

if !relation_fields.is_empty() {
Expand All @@ -754,7 +754,7 @@ fn visit_relation(model_id: crate::ModelId, relation_field_id: RelationFieldId,
ctx.asts[ctx.types[relation_field_id].referenced_model].name(),
relation_fields.iter().map(|(f, _)| f.name()).collect::<Vec<_>>().join(", "),
);
ctx.push_error(DatamodelError::new_validation_error(&msg, attr.span));
ctx.push_error(DatamodelError::new_validation_error(&msg, attr.span()));
}

Vec::new()
Expand Down
4 changes: 3 additions & 1 deletion psl/parser-database/src/attributes/default.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use schema_ast::ast::WithSpan;

use crate::{
ast::{self, WithName},
coerce,
Expand Down Expand Up @@ -336,7 +338,7 @@ fn validate_default_value_on_composite_type(
"Defaults on fields of type composite are not supported. Please remove the `@default` attribute.",
ct_name,
ast_field.name(),
attr.span,
attr.span(),
));
}

Expand Down
8 changes: 4 additions & 4 deletions psl/parser-database/src/attributes/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(super) fn model(model_data: &mut ModelAttributes, model_id: crate::ModelId,

let resolving = FieldResolvingSetup::OnlyTopLevel;

let resolved_fields = match resolve_field_array_with_args(fields, attr.span, model_id, resolving, ctx) {
let resolved_fields = match resolve_field_array_with_args(fields, attr.span(), model_id, resolving, ctx) {
Ok(fields) => fields,
Err(FieldResolutionError::AlreadyDealtWith) => return,
Err(FieldResolutionError::ProblematicFields {
Expand Down Expand Up @@ -61,7 +61,7 @@ pub(super) fn model(model_data: &mut ModelAttributes, model_id: crate::ModelId,
&msg,
"model",
ctx.asts[model_id].name(),
attr.span,
attr.span(),
));
}

Expand Down Expand Up @@ -105,7 +105,7 @@ pub(super) fn model(model_data: &mut ModelAttributes, model_id: crate::ModelId,
),
"model",
ast_model.name(),
attr.span,
attr.span(),
))
}

Expand Down Expand Up @@ -222,7 +222,7 @@ pub(super) fn validate_id_field_arities(
ctx.push_error(DatamodelError::new_attribute_validation_error(
"Fields that are marked as id must be required.",
"@id",
ctx.asts[pk.source_attribute].span,
ctx.asts[pk.source_attribute].span(),
))
}
}
Expand Down
6 changes: 4 additions & 2 deletions psl/parser-database/src/attributes/native_types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use schema_ast::ast::WithSpan;

use crate::{ast, context::Context, ScalarFieldId, StringId};

pub(super) fn visit_model_field_native_type_attribute(
Expand All @@ -10,7 +12,7 @@ pub(super) fn visit_model_field_native_type_attribute(
let args = &attr.arguments;
let args: Vec<String> = args.arguments.iter().map(|arg| arg.value.to_string()).collect();

ctx.types[id].native_type = Some((datasource_name, type_name, args, attr.span))
ctx.types[id].native_type = Some((datasource_name, type_name, args, attr.span()))
}

pub(super) fn visit_composite_type_field_native_type_attribute(
Expand All @@ -24,6 +26,6 @@ pub(super) fn visit_composite_type_field_native_type_attribute(
let args: Vec<String> = args.arguments.iter().map(|arg| arg.value.to_string()).collect();

if let Some(composite_type_field) = ctx.types.composite_type_fields.get_mut(&id) {
composite_type_field.native_type = Some((datasource_name, type_name, args, attr.span))
composite_type_field.native_type = Some((datasource_name, type_name, args, attr.span()))
}
}
Loading