Automatically trigger intellisense after inserting a snippet

Some snippets require specific completions, such as \cite{} or \ref{}
for instance. To automatically trigger these completions after inserting
snippet, we use the 'command' mechanism of CompletionItem.

In practice, you just need to add
    postAction: 'editor.action.triggerSuggest'
to every entry of data/commands.json, which need to trigger
intellisense.

This closes #744.
This commit is contained in:
Jerome Lelong 2018-08-24 14:50:23 +02:00
parent 7c05467f50
commit 25db12c9f0
2 changed files with 20 additions and 8 deletions

View File

@ -1,8 +1,9 @@
{
"begin":{
"command":"begin",
"snippet":"begin{${1:env}}\n\t$0\n\\\\end{${1:env}}",
"detail":"begin a new environment"
"snippet":"begin{$1}\n\t$0\n\\\\end{$1}",
"detail":"begin a new environment",
"postAction":"editor.action.triggerSuggest"
},
"lrparen":{
"command":"left(",
@ -90,15 +91,19 @@
"cite":{
"command":"cite",
"snippet":"cite{$1}",
"detail":"reference"
"detail":"reference",
"postAction":"editor.action.triggerSuggest"
},
"citeyear":{
"command":"citeyear",
"snippet":"citeyear{$1}"
"snippet":"citeyear{$1}",
"postAction":"editor.action.triggerSuggest"
},
"shortcite":{
"command":"shortcite",
"snippet":"shortcite{$1}"
"snippet":"shortcite{$1}",
"postAction":"editor.action.triggerSuggest"
},
"emph":{
"command":"emph",
@ -151,11 +156,13 @@
},
"ref":{
"command":"ref",
"snippet":"ref{${1}}"
"snippet":"ref{${1}}",
"postAction":"editor.action.triggerSuggest"
},
"pageref":{
"command":"pageref",
"snippet":"pageref{$1}"
"snippet":"pageref{$1}",
"postAction":"editor.action.triggerSuggest"
},
"author":{
"command":"author",
@ -175,7 +182,8 @@
},
"usepackage":{
"command":"usepackage",
"snippet":"usepackage{$1}"
"snippet":"usepackage{$1}",
"postAction":"editor.action.triggerSuggest"
},
"item":{
"command":"item",

View File

@ -130,6 +130,9 @@ export class Command {
command.documentation = item.documentation
command.detail = item.detail
command.sortText = item.sortText
if (item.postAction) {
command.command = { title: 'Post-Action', command: item.postAction }
}
return command
}
@ -193,4 +196,5 @@ interface AutocompleteEntry {
description?: string
documentation?: string
sortText?: string
postAction?: string
}