src/goLanguageServer.ts: handle missing filterText in completion items

According to LSP spec, VS Code should use the `label` if `filterText`
is falsy, but it doesn't seem to work that way.
Now gopls can send completion items without `filterText`. So, make
sure to have something reasonable as the filterText if the value
is undefined.

Fixes golang/vscode-go#441

Change-Id: Ie682e8232c09dbd547897002064b478ed1692a1c
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/246297
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts
index 116bfb9..c003d60 100644
--- a/src/goLanguageServer.ts
+++ b/src/goLanguageServer.ts
@@ -351,7 +351,16 @@
 					if (!Array.isArray(list) && list.isIncomplete && list.items.length > 1) {
 						let hardcodedFilterText = items[0].filterText;
 						if (!hardcodedFilterText) {
-							hardcodedFilterText = '';
+							// tslint:disable:max-line-length
+							// According to LSP spec,
+							// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
+							// if filterText is falsy, the `label` should be used.
+							// But we observed that's not the case.
+							// Even if vscode picked the label value, that would
+							// cause to reorder candiates, which is not ideal.
+							// Force to use non-empty `label`.
+							// https://github.com/golang/vscode-go/issues/441
+							hardcodedFilterText = items[0].label;
 						}
 						for (const item of items) {
 							item.filterText = hardcodedFilterText;