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

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

## Functions

### `useDefinition`

Function.

Wires go to definition into a code view: returns token enter/leave/click handlers for
`FileView` or `CodeEditor`, `linking` for the pointer cursor, and `goTo` for a hover-card action.

```ts
function useDefinition<T extends { origin?: EditorRange }>(
  scope: string,
  enabled: boolean,
  resolve: (line: number, column: number) => Promise<readonly T[]>,
  navigate: (target: T) => void,
): { enabled: boolean; goTo: (line: number, column: number) => Promise<boolean>; linking: boolean; onClick: (t: CodeToken, e: MouseEvent) => void; onEnter: (t: CodeToken) => void; onLeave: () => void }
```

**Type parameters**

- `T` (`extends { origin?: EditorRange }`)

**Parameters**

- `scope` (`string`): Changes with the file shown: a slow answer for the previous one never navigates.
- `enabled` (`boolean`): Off: no underline, clicks pass through.
- `resolve` (`(line: number, column: number) => Promise<readonly T[]>`): Where the symbol at a 1-based (line, column) is defined, with the symbol's extent (`origin`) when known.
- `navigate` (`(target: T) => void`): Opens the first target.

**Returns** `{ enabled: boolean; goTo: (line: number, column: number) => Promise<boolean>; linking: boolean; onClick: (t: CodeToken, e: MouseEvent) => void; onEnter: (t: CodeToken) => void; onLeave: () => void }`

Source: [ui/src/code/editor/useDefinition.ts:33](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/useDefinition.ts#L33)
