Skip to content

Commit

Permalink
feat(psl): moved psl-builtin-connectors within psl-core (#4630)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkomyno authored Jan 11, 2024
1 parent 989f667 commit a98377e
Show file tree
Hide file tree
Showing 28 changed files with 74 additions and 107 deletions.
17 changes: 1 addition & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions psl/builtin-connectors/Cargo.toml

This file was deleted.

1 change: 1 addition & 0 deletions psl/psl-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ serde.workspace = true
serde_json.workspace = true
enumflags2 = "0.7"
indoc.workspace = true
either = "1.8.1"

# For the connector API.
lsp-types = "0.91.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ mod validations;

pub use native_types::CockroachType;

use chrono::*;
use enumflags2::BitFlags;
use lsp_types::{CompletionItem, CompletionItemKind, CompletionList};
use psl_core::{
use crate::{
datamodel_connector::{
Connector, ConnectorCapabilities, ConnectorCapability, ConstraintScope, Flavour, NativeTypeConstructor,
NativeTypeInstance, RelationMode, StringFilter,
Expand All @@ -21,9 +18,12 @@ use psl_core::{
},
PreviewFeature,
};
use chrono::*;
use enumflags2::BitFlags;
use lsp_types::{CompletionItem, CompletionItemKind, CompletionList};
use std::borrow::Cow;

use crate::completions;
use super::completions;

const CONSTRAINT_SCOPES: &[ConstraintScope] = &[ConstraintScope::ModelPrimaryKeyKeyIndexForeignKey];

Expand Down Expand Up @@ -294,7 +294,7 @@ impl Connector for CockroachDatamodelConnector {
}
}

fn datasource_completions(&self, config: &psl_core::Configuration, completion_list: &mut CompletionList) {
fn datasource_completions(&self, config: &crate::Configuration, completion_list: &mut CompletionList) {
let ds = match config.datasources.first() {
Some(ds) => ds,
None => return,
Expand All @@ -318,11 +318,11 @@ impl Connector for CockroachDatamodelConnector {

match native_type {
Some(ct) => match ct {
CockroachType::Timestamptz(_) => crate::utils::parse_timestamptz(str),
CockroachType::Timestamp(_) => crate::utils::parse_timestamp(str),
CockroachType::Date => crate::utils::parse_date(str),
CockroachType::Time(_) => crate::utils::parse_time(str),
CockroachType::Timetz(_) => crate::utils::parse_timetz(str),
CockroachType::Timestamptz(_) => super::utils::parse_timestamptz(str),
CockroachType::Timestamp(_) => super::utils::parse_timestamp(str),
CockroachType::Date => super::utils::parse_date(str),
CockroachType::Time(_) => super::utils::parse_time(str),
CockroachType::Timetz(_) => super::utils::parse_timetz(str),
_ => unreachable!(),
},
None => self.parse_json_datetime(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use psl_core::{
use crate::{
diagnostics::{DatamodelError, Diagnostics},
parser_database::{
walkers::{IndexWalker, ModelWalker},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::datamodel_connector::format_completion_docs;
use lsp_types::{
CompletionItem, CompletionItemKind, CompletionList, Documentation, InsertTextFormat, MarkupContent, MarkupKind,
};
use psl_core::datamodel_connector::format_completion_docs;

pub(crate) fn extensions_completion(completion_list: &mut CompletionList) {
completion_list.items.push(CompletionItem {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![deny(rust_2018_idioms, unsafe_code)]
#![allow(clippy::derive_partial_eq_without_eq)]

pub mod cockroach_datamodel_connector;
pub mod completions;

Expand All @@ -18,7 +15,7 @@ mod postgres_datamodel_connector;
mod sqlite_datamodel_connector;
mod utils;

use psl_core::{datamodel_connector::Connector, ConnectorRegistry};
use crate::{datamodel_connector::Connector, ConnectorRegistry};

pub const POSTGRES: &'static dyn Connector = &postgres_datamodel_connector::PostgresDatamodelConnector;
pub const COCKROACH: &'static dyn Connector = &cockroach_datamodel_connector::CockroachDatamodelConnector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ mod validations;

pub use mongodb_types::MongoDbType;

use enumflags2::BitFlags;
use mongodb_types::*;
use psl_core::{
use crate::{
datamodel_connector::{
Connector, ConnectorCapabilities, ConnectorCapability, ConstraintScope, Flavour, NativeTypeConstructor,
NativeTypeInstance, RelationMode,
},
diagnostics::{Diagnostics, Span},
parser_database::{walkers::*, ReferentialAction, ScalarType},
};
use enumflags2::BitFlags;
use mongodb_types::*;
use std::result::Result as StdResult;

const CAPABILITIES: ConnectorCapabilities = enumflags2::make_bitflags!(ConnectorCapability::{
Expand Down Expand Up @@ -82,7 +82,7 @@ impl Connector for MongoDbDatamodelConnector {

fn validate_relation_field(
&self,
field: psl_core::parser_database::walkers::RelationFieldWalker<'_>,
field: crate::parser_database::walkers::RelationFieldWalker<'_>,
errors: &mut Diagnostics,
) {
validations::relation_same_native_type(field, errors);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::parser_database::ScalarType;
use once_cell::sync::Lazy;
use psl_core::parser_database::ScalarType;
use std::collections::HashMap;

crate::native_type_definition! {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use psl_core::{
use crate::{
diagnostics::{DatamodelError, DatamodelWarning, Diagnostics},
parser_database::{
ast::{WithName, WithSpan},
Expand Down Expand Up @@ -214,7 +214,7 @@ pub(crate) fn field_name_uses_valid_characters(field: ScalarFieldWalker<'_>, err

/// Makes sure underlying fields of a relation have the same native types.
pub(crate) fn relation_same_native_type(
field: psl_core::parser_database::walkers::RelationFieldWalker<'_>,
field: crate::parser_database::walkers::RelationFieldWalker<'_>,
errors: &mut Diagnostics,
) {
let references = field.referenced_fields();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ mod validations;

pub use native_types::{MsSqlType, MsSqlTypeParameter};

use enumflags2::BitFlags;
use lsp_types::{CompletionItem, CompletionItemKind, CompletionList};
use psl_core::{
use crate::{
datamodel_connector::{
Connector, ConnectorCapabilities, ConnectorCapability, ConstraintScope, Flavour, NativeTypeConstructor,
NativeTypeInstance, RelationMode,
Expand All @@ -14,11 +12,13 @@ use psl_core::{
parser_database::{self, ast, ParserDatabase, ReferentialAction, ScalarType},
PreviewFeature,
};
use enumflags2::BitFlags;
use lsp_types::{CompletionItem, CompletionItemKind, CompletionList};

use MsSqlType::*;
use MsSqlTypeParameter::*;

use crate::completions;
use super::completions;

const CONSTRAINT_SCOPES: &[ConstraintScope] = &[
ConstraintScope::GlobalPrimaryKeyForeignKeyDefault,
Expand Down Expand Up @@ -269,7 +269,7 @@ impl Connector for MsSqlDatamodelConnector {
}
}

fn datasource_completions(&self, config: &psl_core::Configuration, completion_list: &mut CompletionList) {
fn datasource_completions(&self, config: &crate::Configuration, completion_list: &mut CompletionList) {
let ds = match config.datasources.first() {
Some(ds) => ds,
None => return,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub enum MsSqlTypeParameter {
Max,
}

impl psl_core::datamodel_connector::NativeTypeArguments for MsSqlTypeParameter {
impl crate::datamodel_connector::NativeTypeArguments for MsSqlTypeParameter {
const DESCRIPTION: &'static str = "an integer or `Max`";
const OPTIONAL_ARGUMENTS_COUNT: usize = 0;
const REQUIRED_ARGUMENTS_COUNT: usize = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::MsSqlType;
use psl_core::{
use crate::{
datamodel_connector::{walker_ext_traits::ScalarFieldWalkerExt, Connector},
diagnostics::{DatamodelError, Diagnostics},
parser_database::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ mod validations;

pub use native_types::MySqlType;

use crate::completions;
use enumflags2::BitFlags;
use lsp_types::CompletionList;
use psl_core::{
use super::completions;
use crate::{
datamodel_connector::{
Connector, ConnectorCapabilities, ConnectorCapability, ConstraintScope, Flavour, NativeTypeConstructor,
NativeTypeInstance, RelationMode,
Expand All @@ -15,6 +13,8 @@ use psl_core::{
parser_database::{walkers, ReferentialAction, ScalarType},
PreviewFeature,
};
use enumflags2::BitFlags;
use lsp_types::CompletionList;
use MySqlType::*;

const TINY_BLOB_TYPE_NAME: &str = "TinyBlob";
Expand Down Expand Up @@ -270,7 +270,7 @@ impl Connector for MySqlDatamodelConnector {
Ok(())
}

fn datasource_completions(&self, config: &psl_core::Configuration, completion_list: &mut CompletionList) {
fn datasource_completions(&self, config: &crate::Configuration, completion_list: &mut CompletionList) {
let ds = match config.datasources.first() {
Some(ds) => ds,
None => return,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use indoc::formatdoc;
use psl_core::diagnostics::{DatamodelWarning, Span};
use psl_core::parser_database::ast::WithSpan;
use psl_core::parser_database::ReferentialAction;
use psl_core::{
use crate::{
datamodel_connector::{walker_ext_traits::ScalarFieldWalkerExt, Connector},
diagnostics::Diagnostics,
parser_database::walkers::{IndexWalker, PrimaryKeyWalker, RelationFieldWalker},
diagnostics::{DatamodelWarning, Span},
parser_database::{
ast::WithSpan,
walkers::{IndexWalker, PrimaryKeyWalker, RelationFieldWalker},
ReferentialAction,
},
};
use indoc::formatdoc;

const LENGTH_GUIDE: &str = " Please use the `length` argument to the field in the index definition to allow this.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ macro_rules! native_type_definition {
pub fn from_parts(
name: &str,
arguments: &[String],
span: psl_core::parser_database::ast::Span,
diagnostics: &mut psl_core::diagnostics::Diagnostics
span: $crate::parser_database::ast::Span,
diagnostics: &mut $crate::diagnostics::Diagnostics
) -> Option<Self> {
use $enumName::*;

Expand Down Expand Up @@ -130,7 +130,7 @@ macro_rules! native_type_definition {
$self,
{
$($body)*
$variant(arg) => (stringify!($variant), <$param as psl_core::datamodel_connector::NativeTypeArguments>::to_parts(arg)),
$variant(arg) => (stringify!($variant), <$param as $crate::datamodel_connector::NativeTypeArguments>::to_parts(arg)),
}
$($tail)*
}
Expand Down Expand Up @@ -163,7 +163,7 @@ macro_rules! native_type_definition {
match $name {
$($body)*
_ => {
$diagnostics.push_error(psl_core::diagnostics::DatamodelError::new_native_type_parser_error($name, $span));
$diagnostics.push_error($crate::diagnostics::DatamodelError::new_native_type_parser_error($name, $span));
None
},
}
Expand All @@ -182,12 +182,12 @@ macro_rules! native_type_definition {
{
$($body)*
name if name == stringify!($variant) => {
let args = <$params as psl_core::datamodel_connector::NativeTypeArguments>::from_parts($arguments);
let args = <$params as $crate::datamodel_connector::NativeTypeArguments>::from_parts($arguments);
match args {
Some(args) => Some($variant(args)),
None => {
let rendered_args = format!("({})", $arguments.join(", "));
$diagnostics.push_error(psl_core::diagnostics::DatamodelError::new_value_parser_error(<$params as psl_core::datamodel_connector::NativeTypeArguments>::DESCRIPTION, &rendered_args, $span));
$diagnostics.push_error($crate::diagnostics::DatamodelError::new_value_parser_error(<$params as $crate::datamodel_connector::NativeTypeArguments>::DESCRIPTION, &rendered_args, $span));
None
}
}
Expand Down Expand Up @@ -221,7 +221,7 @@ macro_rules! native_type_definition {
{ $($body:tt)* }
) => {
#[allow(unused_imports)]
use psl_core::datamodel_connector::NativeTypeConstructor;
use $crate::datamodel_connector::NativeTypeConstructor;

pub(crate) const CONSTRUCTORS: &[NativeTypeConstructor] = &[
$( $body )*
Expand All @@ -242,7 +242,7 @@ macro_rules! native_type_definition {
name: stringify!($variant),
number_of_args: 0,
number_of_optional_args: 0,
prisma_types: &[$(psl_core::parser_database::ScalarType::$scalar),*],
prisma_types: &[$($crate::parser_database::ScalarType::$scalar),*],
},
}
$($tail)*
Expand All @@ -261,9 +261,9 @@ macro_rules! native_type_definition {
$($body)*
NativeTypeConstructor {
name: stringify!($variant),
number_of_args: <$params as psl_core::datamodel_connector::NativeTypeArguments>::REQUIRED_ARGUMENTS_COUNT,
number_of_optional_args: <$params as psl_core::datamodel_connector::NativeTypeArguments>::OPTIONAL_ARGUMENTS_COUNT,
prisma_types: &[$(psl_core::parser_database::ScalarType::$scalar),*],
number_of_args: <$params as $crate::datamodel_connector::NativeTypeArguments>::REQUIRED_ARGUMENTS_COUNT,
number_of_optional_args: <$params as $crate::datamodel_connector::NativeTypeArguments>::OPTIONAL_ARGUMENTS_COUNT,
prisma_types: &[$($crate::parser_database::ScalarType::$scalar),*],
},
}
$($tail)*
Expand Down
Loading

0 comments on commit a98377e

Please sign in to comment.