# code/editor/diagnostics (zidane-ui/code/editor)

Import: `import { … } from 'zidane-ui/code/editor'`. Source: [ui/src/code/editor/diagnostics.ts](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/diagnostics.ts).

## Functions

### `countBySeverity`

Function.

How many findings are errors, warnings, and anything else (info and hints together).

```ts
function countBySeverity(
  items: readonly EditorDiagnostic[],
): { errors: number; other: number; warnings: number }
```

**Parameters**

- `items` (`readonly EditorDiagnostic[]`): The findings to count.

**Returns** `{ errors: number; other: number; warnings: number }`

Source: [ui/src/code/editor/diagnostics.ts:96](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/diagnostics.ts#L96)

### `diagnosticMarkers`

Function.

The editor's squiggles (pierre markers, 0-based) for a set of findings. Each marker's message
carries the source and code after the text.

```ts
function diagnosticMarkers(items: readonly EditorDiagnostic[]): Marker[]
```

**Parameters**

- `items` (`readonly EditorDiagnostic[]`): The findings to mark.

**Returns** `Marker[]`

Source: [ui/src/code/editor/diagnostics.ts:118](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/diagnostics.ts#L118)

### `diagnosticsAt`

Function.

Diagnostics whose range covers a 1-based (line, column), such as the findings under the pointer.

```ts
function diagnosticsAt<D extends EditorDiagnostic>(
  items: readonly D[],
  line: number,
  column: number,
): D[]
```

**Type parameters**

- `D` (`extends EditorDiagnostic`)

**Parameters**

- `items` (`readonly D[]`): The findings to filter.
- `line` (`number`): 1-based line.
- `column` (`number`): 1-based column.

**Returns** `D[]`

Source: [ui/src/code/editor/diagnostics.ts:81](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/diagnostics.ts#L81)

### `diagnosticsByLine`

Function.

Findings grouped per line, in first-seen order: one annotation row each.

```ts
function diagnosticsByLine<D extends EditorDiagnostic>(
  items: readonly D[],
): Map<number, D[]>
```

**Type parameters**

- `D` (`extends EditorDiagnostic`)

**Parameters**

- `items` (`readonly D[]`): The findings to group, keyed by their start line.

**Returns** `Map<number, D[]>`

Source: [ui/src/code/editor/diagnostics.ts:136](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/diagnostics.ts#L136)

## Constants

### `DIAGNOSTIC_GLYPH`

Constant.

Icon class and text colour class each severity is drawn with, shared by the annotations, the chip and the hover card.

```ts
const DIAGNOSTIC_GLYPH: Record<DiagnosticSeverity, { icon: string; tone: string }>
```

Source: [ui/src/code/editor/diagnostics.ts:67](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/diagnostics.ts#L67)

## Interfaces

### `EditorDefinition`

Interface.

Where a symbol is defined, and the extent of the symbol it was asked from.

```ts
interface EditorDefinition extends EditorLocation
```

**Properties**

- `column` (`number`, from `EditorLocation`): 1-based column.
- `line` (`number`, from `EditorLocation`): 1-based line.
- `origin?` (`EditorRange`): The symbol the definition was asked from, in the asking file, as the
  language service delimits it (LSP `originSelectionRange`): a whole
  import path rather than the word under the pointer. Cmd/Ctrl-hover
  underlines it. Absent when the service doesn't say.
- `path` (`string`, from `EditorLocation`): Relative to the editor's root.

Source: [ui/src/code/editor/diagnostics.ts:56](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/diagnostics.ts#L56)

### `EditorDiagnostic`

Interface.

One finding on a file: where it sits, how serious it is, what it says and which tool raised it.

```ts
interface EditorDiagnostic
```

**Properties**

- `code?` (`string`): Rule / error code (`TS2322`, `no-unused-vars`).
- `column` (`number`): 1-based column the range starts at.
- `endColumn?` (`number`): 1-based column the range ends before (exclusive). Defaults to one character past `column`.
- `endLine?` (`number`): 1-based line the range ends on. Defaults to `line`.
- `line` (`number`): 1-based line the range starts on.
- `message` (`string`): The finding's text, as the tool wrote it.
- `path` (`string`): Relative to the editor's root.
- `severity` (`DiagnosticSeverity`): How serious the finding is.
- `source` (`string`): Tool id (`tsc`, `eslint`, ...).

Source: [ui/src/code/editor/diagnostics.ts:12](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/diagnostics.ts#L12)

### `EditorLocation`

Interface.

A position in a file a language service points at (a definition, a reference).

```ts
interface EditorLocation
```

**Properties**

- `column` (`number`): 1-based column.
- `line` (`number`): 1-based line.
- `path` (`string`): Relative to the editor's root.

Source: [ui/src/code/editor/diagnostics.ts:34](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/diagnostics.ts#L34)

### `EditorRange`

Interface.

A span of a file's text, 1-based.

```ts
interface EditorRange
```

**Properties**

- `column` (`number`): 1-based column the span starts at.
- `endColumn` (`number`): 1-based column the span ends before (exclusive).
- `endLine` (`number`): 1-based line the span ends on.
- `line` (`number`): 1-based line the span starts on.

Source: [ui/src/code/editor/diagnostics.ts:44](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/diagnostics.ts#L44)

## Types

### `DiagnosticSeverity`

Type.

How serious a finding is; picks its glyph, colour and which count it adds to.

```ts
type DiagnosticSeverity = 'error' | 'warning' | 'info' | 'hint'
```

Source: [ui/src/code/editor/diagnostics.ts:9](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/diagnostics.ts#L9)
