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(fmt): cleanup text_document_completion #4837

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 4 additions & 13 deletions prisma-fmt/src/text_document_completion.rs
Expand Up @@ -13,6 +13,8 @@ use std::sync::Arc;
use crate::position_to_offset;

mod datasource;
mod multi_schema;
mod referential_actions;

pub(crate) fn empty_completion_list() -> CompletionList {
CompletionList {
Expand Down Expand Up @@ -97,13 +99,7 @@ fn push_ast_completions(ctx: CompletionContext<'_>, completion_list: &mut Comple
ast::ModelPosition::Field(_, ast::FieldPosition::Attribute("relation", _, Some(attr_name))),
) if attr_name == "onDelete" || attr_name == "onUpdate" => {
for referential_action in ctx.connector().referential_actions().iter() {
completion_list.items.push(CompletionItem {
label: referential_action.as_str().to_owned(),
kind: Some(CompletionItemKind::ENUM),
// what is the difference between detail and documentation?
detail: Some(referential_action.documentation().to_owned()),
..Default::default()
});
referential_actions::referential_action_completion(completion_list, referential_action)
}
}

Expand Down Expand Up @@ -196,12 +192,7 @@ fn push_namespaces(ctx: CompletionContext<'_>, completion_list: &mut CompletionL
namespace.to_string()
};

completion_list.items.push(CompletionItem {
label: String::from(namespace),
insert_text: Some(insert_text),
kind: Some(CompletionItemKind::PROPERTY),
..Default::default()
})
multi_schema::schema_namespace_completion(completion_list, namespace, insert_text);
}
}

Expand Down
14 changes: 14 additions & 0 deletions prisma-fmt/src/text_document_completion/multi_schema.rs
@@ -0,0 +1,14 @@
use lsp_types::{CompletionItem, CompletionItemKind, CompletionList};

pub(super) fn schema_namespace_completion(
completion_list: &mut CompletionList,
namespace: &String,
insert_text: String,
) {
completion_list.items.push(CompletionItem {
label: String::from(namespace),
insert_text: Some(insert_text),
kind: Some(CompletionItemKind::PROPERTY),
..Default::default()
})
}
15 changes: 15 additions & 0 deletions prisma-fmt/src/text_document_completion/referential_actions.rs
@@ -0,0 +1,15 @@
use lsp_types::{CompletionItem, CompletionItemKind, CompletionList};
use psl::parser_database::ReferentialAction;

pub(super) fn referential_action_completion(
completion_list: &mut CompletionList,
referential_action: ReferentialAction,
) {
completion_list.items.push(CompletionItem {
label: referential_action.as_str().to_owned(),
kind: Some(CompletionItemKind::ENUM),
// ? (@tomhoule) what is the difference between detail and documentation?
detail: Some(referential_action.documentation().to_owned()),
..Default::default()
})
}