diff --git a/src/features/completion.rs b/src/features/completion.rs index 2a01c94b..13c7aad2 100644 --- a/src/features/completion.rs +++ b/src/features/completion.rs @@ -281,16 +281,43 @@ fn convert_internal_items( ..CompletionItem::default() } } - InternalCompletionItemData::BeginCommand => CompletionItem { - kind: Some(adjust_kind( - &context.request, - Structure::Snippet.completion_kind(), - )), - data: Some(serde_json::to_value(CompletionItemData::CommandSnippet).unwrap()), - insert_text: Some("begin{$1}\n\t$0\n\\end{$1}".into()), - insert_text_format: Some(InsertTextFormat::Snippet), - ..CompletionItem::new_simple("begin".into(), component_detail(&[])) - }, + InternalCompletionItemData::BeginCommand => { + if context + .request + .context + .client_capabilities + .lock() + .unwrap() + .text_document + .as_ref() + .and_then(|cap| cap.completion.as_ref()) + .and_then(|cap| cap.completion_item.as_ref()) + .and_then(|cap| cap.snippet_support) + == Some(true) + { + CompletionItem { + kind: Some(adjust_kind( + &context.request, + Structure::Snippet.completion_kind(), + )), + data: Some(serde_json::to_value(CompletionItemData::CommandSnippet).unwrap()), + insert_text: Some("begin{$1}\n\t$0\n\\end{$1}".into()), + insert_text_format: Some(InsertTextFormat::Snippet), + ..CompletionItem::new_simple("begin".into(), component_detail(&[])) + } + } else { + let text_edit = TextEdit::new(range, "begin".to_string()); + CompletionItem { + kind: Some(adjust_kind( + &context.request, + Structure::Command.completion_kind(), + )), + data: Some(serde_json::to_value(CompletionItemData::Command).unwrap()), + text_edit: Some(CompletionTextEdit::Edit(text_edit)), + ..CompletionItem::new_simple("begin".to_string(), component_detail(&[])) + } + } + } InternalCompletionItemData::Citation { uri, key, text, ty } => { let text_edit = TextEdit::new(range, key.to_string()); CompletionItem { diff --git a/src/features/completion/begin_command.rs b/src/features/completion/begin_command.rs index e04c7e1b..ebd27271 100644 --- a/src/features/completion/begin_command.rs +++ b/src/features/completion/begin_command.rs @@ -11,14 +11,12 @@ pub fn complete_begin_command( cancellation_token: &CancellationToken, ) -> Option<()> { cancellation_token.result().ok()?; - let range = context.cursor.command_range(context.offset)?; items.push(InternalCompletionItem::new( range, InternalCompletionItemData::BeginCommand, )); - Some(()) } diff --git a/tests/integration/snapshots/integration__completion__latex__begin_command.snap b/tests/integration/snapshots/integration__completion__latex__begin_command.snap index 95749433..ab5ea776 100644 --- a/tests/integration/snapshots/integration__completion__latex__begin_command.snap +++ b/tests/integration/snapshots/integration__completion__latex__begin_command.snap @@ -12,8 +12,19 @@ expression: "complete_and_resolve(&server, uri, 0, 1)?" "detail": "built-in", "preselect": false, "sortText": "00", - "insertText": "begin{$1}\n\t$0\n\\end{$1}", - "insertTextFormat": 2 + "textEdit": { + "range": { + "start": { + "line": 0, + "character": 1 + }, + "end": { + "line": 0, + "character": 2 + } + }, + "newText": "begin" + } }, { "label": "b",