@@ -153,10 +153,12 @@ lsp.CompletionItem declarationToCompletionItem(
153153 int replacementOffset,
154154 int replacementLength,
155155) {
156- // Build display labels and text to insert. insertText may differ from label
157- // if the label includes things like (…).
156+ // Build display labels and text to insert. insertText and filterText may
157+ // differ from label (for ex. if the label includes things like (…)). If
158+ // either are missing then label will be used by the client.
158159 String label;
159160 String insertText;
161+ String filterText;
160162 switch (declaration.kind) {
161163 case DeclarationKind .ENUM_CONSTANT :
162164 label = '${declaration .parent .name }.${declaration .name }' ;
@@ -167,11 +169,13 @@ lsp.CompletionItem declarationToCompletionItem(
167169 label += '.${declaration .name }' ;
168170 }
169171 insertText = label;
172+ filterText = label;
170173 label += declaration.parameterNames? .isNotEmpty ?? false ? '(…)' : '()' ;
171174 break ;
172175 case DeclarationKind .FUNCTION :
173176 label = declaration.name;
174177 insertText = label;
178+ filterText = label;
175179 label += declaration.parameterNames? .isNotEmpty ?? false ? '(…)' : '()' ;
176180 break ;
177181 default :
@@ -206,8 +210,8 @@ lsp.CompletionItem declarationToCompletionItem(
206210 // 10 -> 999990
207211 // 1 -> 999999
208212 (1000000 - itemRelevance).toString (),
209- null , // filterText uses label if not set
210- insertText, // insertText uses label if not set
213+ filterText != label ? filterText : null , // filterText uses label if not set
214+ insertText != label ? insertText : null , // insertText uses label if not set
211215 null , // insertTextFormat (we always use plain text so can ommit this)
212216 null , // textEdit - added on during resolve
213217 null , // additionalTextEdits, used for adding imports, etc.
@@ -564,11 +568,12 @@ lsp.CompletionItem toCompletionItem(
564568 int replacementOffset,
565569 int replacementLength,
566570) {
567- // Build display labels and text to insert. insertText may differ from label
568- // if the label includes things like (…). If insertText is left as null then
569- // label is used.
571+ // Build display labels and text to insert. insertText and filterText may
572+ // differ from label (for ex. if the label includes things like (…)) . If
573+ // either are missing then label will be used by the client .
570574 String label;
571575 String insertText;
576+ String filterText;
572577 if (suggestion.displayText != null ) {
573578 label = suggestion.displayText;
574579 insertText = suggestion.completion;
@@ -580,6 +585,7 @@ lsp.CompletionItem toCompletionItem(
580585 label = suggestion.completion;
581586 // Label is the insert text plus the parens to indicate it's callable.
582587 insertText = label;
588+ filterText = label;
583589 label += suggestion.parameterNames? .isNotEmpty ?? false ? '(…)' : '()' ;
584590 break ;
585591 default :
@@ -613,7 +619,7 @@ lsp.CompletionItem toCompletionItem(
613619 // 10 -> 999990
614620 // 1 -> 999999
615621 (1000000 - suggestion.relevance).toString (),
616- null , // filterText uses label if not set
622+ filterText != label ? filterText : null , // filterText uses label if not set
617623 insertText != label ? insertText : null , // insertText uses label if not set
618624 null , // insertTextFormat (we always use plain text so can ommit this)
619625 new lsp.TextEdit (
0 commit comments