Skip to content

Commit

Permalink
add positioning for enum value names
Browse files Browse the repository at this point in the history
hover enum value + doc
  • Loading branch information
Druue committed Jul 3, 2024
1 parent 65a4220 commit 8ef551c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
16 changes: 15 additions & 1 deletion prisma-fmt/src/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ fn hover(ctx: HoverContext<'_>) -> Option<Hover> {
None,
))
}
SchemaPosition::Enum(enm_id, EnumPosition::Value(value_id, EnumValuePosition::Name(name))) => {
let value = ctx
.db
.walk((ctx.initiating_file_id, enm_id))
.value(value_id)
.ast_value();

Some(format_hover_content(
value.documentation().unwrap_or_default(),
"value",
name,
None,
))
}

// --- Block Field Types ---
SchemaPosition::Model(model_id, ModelPosition::Field(field_id, FieldPosition::Type(name))) => {
Expand Down Expand Up @@ -189,7 +203,7 @@ fn format_hover_content(
"model" | "enum" | "view" | "type" => {
format!("```prisma\n{variant} {name} {{{field}}}\n```{fancy_line_break}{relation_kind}")
}
"field" => format!("```prisma\n{name}\n```{fancy_line_break}"),
"field" | "value" => format!("```prisma\n{name}\n```{fancy_line_break}"),
_ => "".to_owned(),
};
let full_signature = format!("{prisma_display}{documentation}");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"contents": {
"kind": "markdown",
"value": "```prisma\nRedPanda\n```\n___\nRedpandas are super cute."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
generator js {
provider = "prisma-client-js"
}

datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}

/// enum doc
enum Pet {
/// Redpandas are super cute.
RedP<|>anda
Cat
}
1 change: 1 addition & 0 deletions prisma-fmt/tests/hover/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ scenarios! {
model_from_block_name
model_from_view_type
one_to_many_self_relation
value_from_enum_value_name
}
4 changes: 3 additions & 1 deletion psl/schema-ast/src/ast/find_at_position/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ pub enum EnumValuePosition<'ast> {

impl<'ast> EnumValuePosition<'ast> {
fn new(value: &'ast ast::EnumValue, position: usize) -> EnumValuePosition<'ast> {
if value.name.span().contains(position) {}
if value.name.span().contains(position) {
return EnumValuePosition::Name(value.name());
}
for (attr_idx, attr) in value.attributes.iter().enumerate() {
if attr.span().contains(position) {
// We can't go by Span::contains() because we also care about the empty space
Expand Down

0 comments on commit 8ef551c

Please sign in to comment.