(state)
| 121 | } |
| 122 | |
| 123 | function readLspAnnotations(state) { |
| 124 | const diagnostics = getLspDiagnostics(state); |
| 125 | if (!diagnostics.length) return []; |
| 126 | |
| 127 | const doc = state.doc; |
| 128 | if (!doc || typeof doc.lineAt !== "function") return []; |
| 129 | |
| 130 | return diagnostics |
| 131 | .map((diagnostic) => { |
| 132 | const start = clampPosition(diagnostic.from, doc.length); |
| 133 | const line = doc.lineAt(start); |
| 134 | const row = Math.max(0, line.number - 1); |
| 135 | const column = Math.max(0, start - line.from); |
| 136 | |
| 137 | let message = diagnostic.message || ""; |
| 138 | if (diagnostic.source) { |
| 139 | message = message |
| 140 | ? `${message} (${diagnostic.source})` |
| 141 | : diagnostic.source; |
| 142 | } |
| 143 | |
| 144 | return { |
| 145 | row: normalizeIndex(row), |
| 146 | column: normalizeIndex(column), |
| 147 | text: message, |
| 148 | type: normalizeSeverity(diagnostic.severity), |
| 149 | }; |
| 150 | }) |
| 151 | .filter((annotation) => annotation.text); |
| 152 | } |
| 153 | |
| 154 | function clampPosition(pos, length) { |
| 155 | if (typeof pos !== "number" || Number.isNaN(pos)) return 0; |
no test coverage detected