mirror of
https://github.com/latex-lsp/texlab.git
synced 2025-12-23 09:19:21 +00:00
Only provide snippets if the client supports them
This commit is contained in:
parent
36a2a30c10
commit
426a1ec488
3 changed files with 50 additions and 14 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue