(
documentUri: string,
languageId: string,
connection: ProtocolConnection,
initResponse: InitializeResult<any>
)
| 245 | }); |
| 246 | } |
| 247 | function setupCompletion( |
| 248 | documentUri: string, |
| 249 | languageId: string, |
| 250 | connection: ProtocolConnection, |
| 251 | initResponse: InitializeResult<any> |
| 252 | ) { |
| 253 | if (!initResponse.capabilities.completionProvider) { |
| 254 | return; |
| 255 | } |
| 256 | |
| 257 | // TODO: registration is global, this will break with multiple editors |
| 258 | monaco.languages.registerCompletionItemProvider(languageId, { |
| 259 | triggerCharacters: initResponse.capabilities.completionProvider!.triggerCharacters, |
| 260 | async provideCompletionItems(_, position, context, token) { |
| 261 | const params: CompletionParams = { |
| 262 | position: { |
| 263 | line: position.lineNumber - 1, |
| 264 | character: position.column - 1 |
| 265 | }, |
| 266 | textDocument: { |
| 267 | uri: documentUri |
| 268 | }, |
| 269 | context: { |
| 270 | triggerKind: monacoToLspCompletionTriggerKind(context.triggerKind), |
| 271 | triggerCharacter: context.triggerCharacter |
| 272 | } |
| 273 | }; |
| 274 | const response = await connection.sendRequest(CompletionRequest.type, params, token); |
| 275 | if (response === null) { |
| 276 | return null; |
| 277 | } |
| 278 | const range: monaco.Range = new monaco.Range( |
| 279 | position.lineNumber, |
| 280 | position.column, |
| 281 | position.lineNumber, |
| 282 | position.column |
| 283 | ); |
| 284 | |
| 285 | return Array.isArray(response) |
| 286 | ? { |
| 287 | suggestions: response.map(r => lspToMonacoCompletionItem(r, range)), |
| 288 | incomplete: false |
| 289 | } |
| 290 | : { |
| 291 | suggestions: response.items.map(r => lspToMonacoCompletionItem(r, range)), |
| 292 | incomplete: response.isIncomplete |
| 293 | }; |
| 294 | }, |
| 295 | async resolveCompletionItem(item, token) { |
| 296 | const response = await connection.sendRequest( |
| 297 | CompletionResolveRequest.type, |
| 298 | monacoToLspCompletionItem(item), |
| 299 | token |
| 300 | ); |
| 301 | return lspToMonacoCompletionItem(response, item.range); |
| 302 | } |
| 303 | }); |
| 304 | } |
no outgoing calls
no test coverage detected