1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::ast::{self};
use super::WithName;
#[derive(Debug)]
pub enum PropertyPosition<'ast> {
Property,
/// In the property's name.
/// ```prisma
/// datasource db {
/// provider = "mongodb"
/// // ^^^^^^^^
/// url = env("DATABASE_URL")
/// }
/// ```
Name(&'ast str),
/// In the property's value.
/// ```prisma
/// datasource db {
/// provider = "mongodb"
/// // ^^^^^^^^^
/// url = env("DATABASE_URL")
/// }
/// ```
Value(&'ast str),
/// In the property's value - specifically a function.
/// ```prisma
/// datasource db {
/// provider = "mongodb"
/// url = env("DATABASE_URL")
/// // ^^^^^^^^^^^^^^^^^^^
/// }
/// ```
FunctionValue(&'ast str),
}
impl<'ast> PropertyPosition<'ast> {
pub(crate) fn new(property: &'ast ast::ConfigBlockProperty, position: usize) -> Self {
if property.name.span.contains(position) {
return PropertyPosition::Name(property.name());
}
if let Some(val) = &property.value
&& val.span().contains(position)
&& val.is_function()
{
let func = val.as_function().unwrap();
if func.0 == "env" {
return PropertyPosition::FunctionValue("env");
}
}
if property.span.contains(position) && !property.name.span.contains(position) {
// TODO(@druue): this should actually just return the value string, not the name of the property the value is for
return PropertyPosition::Value(&property.name.name);
}
PropertyPosition::Property
}
}