@@ -12,6 +12,7 @@ import semver = require('semver');
12
12
import util = require( 'util' ) ;
13
13
import vscode = require( 'vscode' ) ;
14
14
import {
15
+ Command ,
15
16
FormattingOptions ,
16
17
HandleDiagnosticsSignature ,
17
18
LanguageClient ,
@@ -143,6 +144,55 @@ export async function registerLanguageFeatures(ctx: vscode.ExtensionContext) {
143
144
return null ;
144
145
}
145
146
return next ( document , token ) ;
147
+ } ,
148
+ provideCompletionItem : (
149
+ document : vscode . TextDocument ,
150
+ position : vscode . Position ,
151
+ context : vscode . CompletionContext ,
152
+ token : vscode . CancellationToken ,
153
+ next : ProvideCompletionItemsSignature
154
+ ) => {
155
+ // TODO(hyangah): when v1.42+ api is available, we can simplify
156
+ // language-specific configuration lookup using the new
157
+ // ConfigurationScope.
158
+ // const paramHintsEnabled = vscode.workspace.getConfiguration(
159
+ // 'editor.parameterHints',
160
+ // { languageId: 'go', uri: document.uri });
161
+
162
+ const editorParamHintsEnabled = vscode . workspace . getConfiguration (
163
+ 'editor.parameterHints' , document . uri ) [ 'enabled' ] ;
164
+ const goParamHintsEnabled = vscode . workspace . getConfiguration (
165
+ '[go]' , document . uri ) [ 'editor.parameterHints.enabled' ] ;
166
+
167
+ let paramHintsEnabled : boolean = false ;
168
+ if ( typeof goParamHintsEnabled === 'undefined' ) {
169
+ paramHintsEnabled = editorParamHintsEnabled ;
170
+ } else {
171
+ paramHintsEnabled = goParamHintsEnabled ;
172
+ }
173
+ let cmd : Command ;
174
+ if ( paramHintsEnabled ) {
175
+ cmd = { title : 'triggerParameterHints' , command : 'editor.action.triggerParameterHints' } ;
176
+ }
177
+
178
+ function configureCommands (
179
+ r : vscode . CompletionItem [ ] | vscode . CompletionList | null | undefined ) :
180
+ vscode . CompletionItem [ ] | vscode . CompletionList | null | undefined {
181
+ if ( r ) {
182
+ ( Array . isArray ( r ) ? r : r . items ) . forEach ( ( i : vscode . CompletionItem ) => {
183
+ i . command = cmd ;
184
+ } ) ;
185
+ }
186
+ return r ;
187
+ }
188
+ const ret = next ( document , position , context , token ) ;
189
+
190
+ const isThenable = < T > ( obj : vscode . ProviderResult < T > ) : obj is Thenable < T > => obj && ( < any > obj ) [ 'then' ] ;
191
+ if ( isThenable < vscode . CompletionItem [ ] | vscode . CompletionList | null | undefined > ( ret ) ) {
192
+ return ret . then ( configureCommands ) ;
193
+ }
194
+ return configureCommands ( ret ) ;
195
+
146
196
}
147
197
}
148
198
}
0 commit comments