Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/tombi-extension/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl CompletionContent {

pub fn new_type_hint_string(
kind: CompletionKind,
quote: char,
quote: &str,
detail: impl Into<String>,
edit: Option<CompletionEdit>,
schema_uri: Option<&SchemaUri>,
Expand Down
2 changes: 1 addition & 1 deletion crates/tombi-extension/src/completion/completion_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl CompletionEdit {
}

pub fn new_string_literal(
quote: char,
quote: &str,
position: tombi_text::Position,
completion_hint: Option<CompletionHint>,
) -> Option<Self> {
Expand Down
34 changes: 21 additions & 13 deletions crates/tombi-lsp/src/completion/value/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ impl FindCompletionContents for tombi_document_tree::String {
return None;
}

if completion_content.label == "\"\"" || completion_content.label == "''" {
if matches!(
completion_content.label.as_str(),
"\"\"" | "''" | "\"\"\"\"\"\"" | "''''''"
) {
return None;
}

Expand Down Expand Up @@ -230,16 +233,21 @@ pub fn type_hint_string(
schema_uri: Option<&SchemaUri>,
completion_hint: Option<CompletionHint>,
) -> Vec<CompletionContent> {
[('\"', "BasicString"), ('\'', "LiteralString")]
.into_iter()
.map(|(quote, detail)| {
CompletionContent::new_type_hint_string(
CompletionKind::String,
quote,
detail,
CompletionEdit::new_string_literal(quote, position, completion_hint),
schema_uri,
)
})
.collect()
[
("\"", "BasicString"),
("'", "LiteralString"),
("\"\"\"", "MultiLineBasicString"),
("'''", "MultiLineLiteralString"),
]
.into_iter()
.map(|(quote, detail)| {
CompletionContent::new_type_hint_string(
CompletionKind::String,
quote,
detail,
CompletionEdit::new_string_literal(quote, position, completion_hint),
schema_uri,
)
})
.collect()
}
20 changes: 20 additions & 0 deletions crates/tombi-lsp/tests/test_completion_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,26 @@ mod completion_edit {
);
}

test_completion_edit! {
#[tokio::test]
async fn key_dot_select_multi_line_basic_string(
"key.█",
Select("\"\"\"\"\"\""),
) -> Ok(
"key = \"\"\"$1\"\"\"$0"
);
}

test_completion_edit! {
#[tokio::test]
async fn key_dot_select_multi_line_literal_string(
"key.█",
Select("''''''"),
) -> Ok(
"key = '''$1'''$0"
);
}

test_completion_edit! {
#[tokio::test]
async fn key_dot_select_today_offset_date_time(
Expand Down
46 changes: 45 additions & 1 deletion crates/tombi-lsp/tests/test_completion_labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,9 @@ mod completion_labels {
"\"https://www.schemastore.org/api/json/catalog.json\"",
"\"tombi://www.schemastore.org/api/json/catalog.json\"",
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
]);
}

Expand All @@ -481,7 +483,9 @@ mod completion_labels {
"\"https://www.schemastore.org/api/json/catalog.json\"",
"\"tombi://www.schemastore.org/api/json/catalog.json\"",
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
]);
}

Expand Down Expand Up @@ -704,7 +708,9 @@ mod completion_labels {
"\"tombi://www.schemastore.org/pyproject.json\"",
"\"tombi://www.schemastore.org/tombi.json\"",
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
]);
}

Expand Down Expand Up @@ -1011,7 +1017,7 @@ mod completion_labels {
]
"#,
SchemaPath(adjacent_one_of_hover_test_schema_path()),
) -> Ok(["\"builtin-hook\"", "\"\"", "''"]);
) -> Ok(["\"builtin-hook\"", "\"\"", "\"\"\"\"\"\"", "''", "''''''"]);
}
}

Expand Down Expand Up @@ -1134,7 +1140,9 @@ mod completion_labels {
},
) -> Ok([
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
]);
}
}
Expand Down Expand Up @@ -1362,7 +1370,9 @@ mod completion_labels {
) -> Ok([
"include-group",
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
"{}",
]);
}
Expand Down Expand Up @@ -1905,7 +1915,9 @@ mod completion_labels {
"\"chrono\"",
"\"serde\"",
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
]);
}

Expand Down Expand Up @@ -1934,7 +1946,9 @@ mod completion_labels {
"version",
"workspace = true",
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
"{}",
]);
}
Expand Down Expand Up @@ -1964,7 +1978,9 @@ mod completion_labels {
"version",
"workspace = true",
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
"{}",
]);
}
Expand Down Expand Up @@ -1998,7 +2014,9 @@ mod completion_labels {
"\"0.1.0\"",
"\"*\"",
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
]);
}

Expand Down Expand Up @@ -2045,7 +2063,9 @@ mod completion_labels {
"\"0.1.0\"",
"\"*\"",
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
]);
}

Expand Down Expand Up @@ -2165,7 +2185,9 @@ mod completion_labels {
"\"chrono\"",
"\"serde\"",
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
]);
}

Expand All @@ -2183,7 +2205,9 @@ mod completion_labels {
"\"chrono\"",
"\"serde\"",
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
]);
}

Expand All @@ -2203,7 +2227,9 @@ mod completion_labels {
"\"extras\"",
"\"flag\"",
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
]);
}

Expand All @@ -2220,7 +2246,9 @@ mod completion_labels {
SchemaPath(cargo_schema_path()),
) -> Ok([
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
]);
}

Expand Down Expand Up @@ -2290,7 +2318,9 @@ mod completion_labels {
"\"chrono\"",
"\"serde\"",
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
]);
}

Expand Down Expand Up @@ -2323,7 +2353,9 @@ mod completion_labels {
"\"MIT\"",
"workspace = true",
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
"{}",
]);
}
Expand Down Expand Up @@ -2681,7 +2713,9 @@ mod completion_labels {
SchemaPath(string_format_test_schema_path()),
) -> Ok([
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
today_local_date(),
]);
}
Expand All @@ -2695,7 +2729,9 @@ mod completion_labels {
SchemaPath(string_format_test_schema_path()),
) -> Ok([
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
today_local_time(),
]);
}
Expand All @@ -2709,7 +2745,9 @@ mod completion_labels {
SchemaPath(string_format_test_schema_path()),
) -> Ok([
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
today_local_date_time(),
]);
}
Expand All @@ -2723,7 +2761,9 @@ mod completion_labels {
SchemaPath(string_format_test_schema_path()),
) -> Ok([
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
today_offset_date_time(),
]);
}
Expand All @@ -2737,7 +2777,9 @@ mod completion_labels {
SchemaPath(string_format_test_schema_path()),
) -> Ok([
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
]);
}
}
Expand All @@ -2752,7 +2794,9 @@ mod completion_labels {
#[tokio::test]
async fn $name($source $(, $arg)*) -> Ok([
"\"\"",
"\"\"\"\"\"\"",
"''",
"''''''",
today_local_time(),
today_local_date(),
today_local_date_time(),
Expand Down
Loading