Skip to content

Commit 49e8916

Browse files
Refactor and reorganize tag specs (#233)
1 parent b1419bb commit 49e8916

File tree

11 files changed

+1256
-898
lines changed

11 files changed

+1256
-898
lines changed

crates/djls-ide/src/completions.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
//! and generating appropriate completion items for Django templates.
55
66
use djls_project::TemplateTags;
7-
use djls_semantic::ArgType;
8-
use djls_semantic::SimpleArgType;
7+
use djls_semantic::TagArg;
98
use djls_semantic::TagSpecs;
109
use djls_workspace::FileKind;
1110
use djls_workspace::PositionEncoding;
@@ -410,15 +409,15 @@ fn generate_tag_name_completions(
410409
}
411410

412411
completions.push(lsp_types::CompletionItem {
413-
label: end_tag.name.clone(),
412+
label: end_tag.name.to_string(),
414413
kind: Some(lsp_types::CompletionItemKind::KEYWORD),
415414
detail: Some(format!("End tag for {opener_name}")),
416415
text_edit: Some(tower_lsp_server::lsp_types::CompletionTextEdit::Edit(
417416
lsp_types::TextEdit::new(replacement_range, insert_text.clone()),
418417
)),
419418
insert_text_format: Some(lsp_types::InsertTextFormat::PLAIN_TEXT),
420-
filter_text: Some(end_tag.name.clone()),
421-
sort_text: Some(format!("0_{}", end_tag.name)), // Priority sort
419+
filter_text: Some(end_tag.name.to_string()),
420+
sort_text: Some(format!("0_{}", end_tag.name.as_ref())), // Priority sort
422421
..Default::default()
423422
});
424423
}
@@ -534,11 +533,11 @@ fn generate_argument_completions(
534533
let arg = &spec.args[position];
535534
let mut completions = Vec::new();
536535

537-
match &arg.arg_type {
538-
ArgType::Simple(SimpleArgType::Literal) => {
536+
match arg {
537+
TagArg::Literal { lit, .. } => {
539538
// For literals, complete the exact text
540-
if arg.name.starts_with(partial) {
541-
let mut insert_text = arg.name.clone();
539+
if lit.starts_with(partial) {
540+
let mut insert_text = lit.to_string();
542541

543542
// Add closing if needed
544543
match closing {
@@ -547,7 +546,7 @@ fn generate_argument_completions(
547546
}
548547

549548
completions.push(lsp_types::CompletionItem {
550-
label: arg.name.clone(),
549+
label: lit.to_string(),
551550
kind: Some(lsp_types::CompletionItemKind::KEYWORD),
552551
detail: Some("literal argument".to_string()),
553552
insert_text: Some(insert_text),
@@ -556,11 +555,11 @@ fn generate_argument_completions(
556555
});
557556
}
558557
}
559-
ArgType::Choice { choice } => {
558+
TagArg::Choice { name, choices, .. } => {
560559
// For choices, offer each option
561-
for option in choice {
560+
for option in choices.iter() {
562561
if option.starts_with(partial) {
563-
let mut insert_text = option.clone();
562+
let mut insert_text = option.to_string();
564563

565564
// Add closing if needed
566565
match closing {
@@ -570,22 +569,22 @@ fn generate_argument_completions(
570569
}
571570

572571
completions.push(lsp_types::CompletionItem {
573-
label: option.clone(),
572+
label: option.to_string(),
574573
kind: Some(lsp_types::CompletionItemKind::ENUM_MEMBER),
575-
detail: Some(format!("choice for {}", arg.name)),
574+
detail: Some(format!("choice for {}", name.as_ref())),
576575
insert_text: Some(insert_text),
577576
insert_text_format: Some(lsp_types::InsertTextFormat::PLAIN_TEXT),
578577
..Default::default()
579578
});
580579
}
581580
}
582581
}
583-
ArgType::Simple(SimpleArgType::Variable) => {
582+
TagArg::Var { name, .. } => {
584583
// For variables, we could offer variable completions from context
585584
// For now, just provide a hint
586585
if partial.is_empty() {
587586
completions.push(lsp_types::CompletionItem {
588-
label: format!("<{}>", arg.name),
587+
label: format!("<{}>", name.as_ref()),
589588
kind: Some(lsp_types::CompletionItemKind::VARIABLE),
590589
detail: Some("variable argument".to_string()),
591590
insert_text: None, // Don't insert placeholder
@@ -594,12 +593,12 @@ fn generate_argument_completions(
594593
});
595594
}
596595
}
597-
ArgType::Simple(SimpleArgType::String) => {
596+
TagArg::String { name, .. } => {
598597
// For strings, could offer template name completions
599598
// For now, just provide a hint
600599
if partial.is_empty() {
601600
completions.push(lsp_types::CompletionItem {
602-
label: format!("\"{}\"", arg.name),
601+
label: format!("\"{}\"", name.as_ref()),
603602
kind: Some(lsp_types::CompletionItemKind::TEXT),
604603
detail: Some("string argument".to_string()),
605604
insert_text: None, // Don't insert placeholder
@@ -608,8 +607,8 @@ fn generate_argument_completions(
608607
});
609608
}
610609
}
611-
ArgType::Simple(_) => {
612-
// Other argument types not handled yet
610+
_ => {
611+
// Other argument types (Expr, Assignment, VarArgs) not handled yet
613612
}
614613
}
615614

0 commit comments

Comments
 (0)