Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 14 additions & 38 deletions packages/oxc/src/app/components/LineError.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,14 @@ const fileExt = computed(() => getFileExt(props.filename))
// Compute the error marker height
const errorHeight = computed(() => calculateErrorHeight(props.lineData.messages))

// Get the sorted labels
const sortedLabels = computed(() => {
const sortedMarkers = computed(() => {
return props.lineData.messages
.flatMap(m => m.labels || [])
.sort((a, b) => a.span.column - b.span.column)
.flatMap(message => (message.labels ?? []).map(label => ({ label, message })))
.sort((a, b) => a.label.span.column - b.label.span.column)
})

// Get the message associated with a label
function getMessageForLabel(column: number) {
for (const message of props.lineData.messages) {
if (message.labels) {
for (const label of message.labels) {
if (label.span.column === column) {
return message
}
}
}
}
return null
}

// Compute the label's vertical position style
function getLabelVerticalStyle(labelIndex: number, baseLeft = 0) {
const label = sortedLabels.value[labelIndex]
if (!label) {
return { left: '0ch' }
}

function getLabelVerticalStyle(label: Label, baseLeft = 0) {
return {
left: `calc(${Math.floor((label.span.length - 1) / 2) + baseLeft}ch)`,
}
Expand Down Expand Up @@ -87,10 +67,10 @@ function severityClass(severity: string | undefined) {

<div class="flex relative" :style="{ minHeight: `${errorHeight}px`, top: '-10px' }">
<a
v-for="(label, labelIndex) in sortedLabels"
v-for="({ label, message }, labelIndex) in sortedMarkers"
:key="labelIndex"
target="_blank"
:href="getMessageForLabel(label.span.column)?.url"
:href="message.url"
class="absolute whitespace-pre text-neutral-300 dark:text-neutral-600 hover:text-neutral-800 dark:hover:text-neutral-200 cursor-pointer"
group
:style="{ left: `calc(${label.span.column - 1}ch)` }"
Expand All @@ -107,33 +87,29 @@ function severityClass(severity: string | undefined) {
>
</div>
<div
v-for="i in (sortedLabels.length - labelIndex - 1) * 2"
v-for="i in (sortedMarkers.length - labelIndex - 1) * 2"
:key="`bar-${i}`"
class="relative"
:style="getLabelVerticalStyle(labelIndex, -1)"
:style="getLabelVerticalStyle(label, -1)"
>
│
</div>
<div class="relative flex" :style="getLabelVerticalStyle(labelIndex)">
<div class="relative flex" :style="getLabelVerticalStyle(label)">
<div>╰─</div>
<div
v-if="(label as any).label"
v-if="label.label"
class="ml1"
v-html="`${processLabelHtml((label as any).label)}.`"
v-html="`${processLabelHtml(label.label)}.`"
/>
<div
class="ml1"
:class="severityClass(getMessageForLabel(label.span.column)?.severity)"
>
{{ getMessageForLabel(label.span.column)?.code }}
<div class="ml1" :class="severityClass(message.severity)">
{{ message.code }}
</div>
</div>
</div>
<template #popper>
<div class="max-w-sm">
<ErrorTooltip
v-if="getMessageForLabel(label.span.column)"
:message="getMessageForLabel(label.span.column)!"
:message="message"
:filename="filename"
:line="lineData.line"
:column="label.span.column"
Expand Down
Loading