( view: EditorView, data: LspSignatureHelp, active: number, )
| 518 | }); |
| 519 | |
| 520 | function drawSignatureTooltip( |
| 521 | view: EditorView, |
| 522 | data: LspSignatureHelp, |
| 523 | active: number, |
| 524 | ) { |
| 525 | const dom = document.createElement("div"); |
| 526 | dom.className = "cm-lsp-signature-tooltip"; |
| 527 | |
| 528 | if (data.signatures.length > 1) { |
| 529 | dom.classList.add("cm-lsp-signature-multiple"); |
| 530 | const num = dom.appendChild(document.createElement("div")); |
| 531 | num.className = "cm-lsp-signature-num"; |
| 532 | num.textContent = `${active + 1}/${data.signatures.length}`; |
| 533 | } |
| 534 | |
| 535 | const signature = data.signatures[active]; |
| 536 | if (!signature) { |
| 537 | return { dom }; |
| 538 | } |
| 539 | |
| 540 | const sig = dom.appendChild(document.createElement("div")); |
| 541 | sig.className = "cm-lsp-signature"; |
| 542 | let activeFrom = 0; |
| 543 | let activeTo = 0; |
| 544 | const activeParamIndex = signature.activeParameter ?? data.activeParameter; |
| 545 | const activeParam = |
| 546 | activeParamIndex != null && signature.parameters |
| 547 | ? signature.parameters[activeParamIndex] |
| 548 | : null; |
| 549 | |
| 550 | if (activeParam && Array.isArray(activeParam.label)) { |
| 551 | [activeFrom, activeTo] = activeParam.label; |
| 552 | } else if (activeParam) { |
| 553 | const found = signature.label.indexOf(activeParam.label as string); |
| 554 | if (found > -1) { |
| 555 | activeFrom = found; |
| 556 | activeTo = found + activeParam.label.length; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | if (activeTo) { |
| 561 | sig.appendChild( |
| 562 | document.createTextNode(signature.label.slice(0, activeFrom)), |
| 563 | ); |
| 564 | const activeElt = sig.appendChild(document.createElement("span")); |
| 565 | activeElt.className = "cm-lsp-active-parameter"; |
| 566 | activeElt.textContent = signature.label.slice(activeFrom, activeTo); |
| 567 | sig.appendChild(document.createTextNode(signature.label.slice(activeTo))); |
| 568 | } else { |
| 569 | sig.textContent = signature.label; |
| 570 | } |
| 571 | |
| 572 | if (signature.documentation) { |
| 573 | const plugin = LSPPlugin.get(view); |
| 574 | if (plugin) { |
| 575 | const docs = dom.appendChild(document.createElement("div")); |
| 576 | docs.className = "cm-lsp-signature-documentation cm-lsp-documentation"; |
| 577 | docs.innerHTML = plugin.docToHTML(signature.documentation); |
no test coverage detected