Get Diagnostics
The getDiagnostics action retrieves diagnostics (errors, warnings, info, hints) from the host IDE. You can optionally filter by file path or limit results to currently open files.
import { getDiagnostics } from '@unextension/bridge'getDiagnostics(options?)
Section titled “getDiagnostics(options?)”Returns diagnostics from the IDE workspace.
const result = await getDiagnostics()console.log(result.diagnostics.length) // number of diagnosticsParameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options | GetDiagnosticsOptions | Optional configuration |
GetDiagnosticsOptions
Section titled “GetDiagnosticsOptions”| Option | Type | Default | Description |
|---|---|---|---|
path | string | undefined | Filter diagnostics to a specific file (relative to project root) |
openFilesOnly | boolean | false | When true, returns diagnostics only for currently open files |
Return value
Section titled “Return value”Promise<GetDiagnosticsResult>
Returns an object containing a diagnostics array. The array is empty when no diagnostics match the requested scope.
GetDiagnosticsResult
Section titled “GetDiagnosticsResult”| Field | Type | Description |
|---|---|---|
diagnostics | Diagnostic[] | Array of diagnostic entries |
Diagnostic
Section titled “Diagnostic”Each diagnostic entry describes a single issue reported by the IDE.
| Field | Type | Required | Description |
|---|---|---|---|
file | string | Yes | File path relative to the project root |
line | number | Yes | Start line of the diagnostic (1-based) |
column | number | Yes | Start column of the diagnostic (1-based) |
endLine | number | No | End line of the diagnostic range (1-based, present when range spans a region) |
endColumn | number | No | End column of the diagnostic range (1-based, present when range spans a region) |
message | string | Yes | The diagnostic message text |
severity | Severity | Yes | One of 'error', 'warning', 'info', or 'hint' |
source | string | No | The tool that produced the diagnostic (e.g. 'typescript', 'eslint') |
Usage examples
Section titled “Usage examples”Get all diagnostics
Section titled “Get all diagnostics”const result = await getDiagnostics()
for (const diag of result.diagnostics) { console.log(`[${diag.severity}] ${diag.file}:${diag.line}:${diag.column} — ${diag.message}`)}Filter by file path
Section titled “Filter by file path”const result = await getDiagnostics({ path: 'src/index.ts' })
console.log(`${result.diagnostics.length} issue(s) in src/index.ts`)Only open files
Section titled “Only open files”const result = await getDiagnostics({ openFilesOnly: true })
console.log(`${result.diagnostics.length} issue(s) in open files`)Handling the empty state
Section titled “Handling the empty state”When no diagnostics exist for the requested scope, the diagnostics array is empty — no null checks needed:
const result = await getDiagnostics({ path: 'src/clean-file.ts' })
if (result.diagnostics.length === 0) { console.log('No issues found')}All types are exported from @unextension/bridge:
import type { Diagnostic, GetDiagnosticsOptions, GetDiagnosticsResult, Severity,} from '@unextension/bridge'Severity
Section titled “Severity”type Severity = 'error' | 'warning' | 'info' | 'hint'Diagnostic
Section titled “Diagnostic”interface Diagnostic { file: string line: number column: number endLine?: number endColumn?: number message: string severity: Severity source?: string}GetDiagnosticsOptions
Section titled “GetDiagnosticsOptions”interface GetDiagnosticsOptions { path?: string openFilesOnly?: boolean}GetDiagnosticsResult
Section titled “GetDiagnosticsResult”interface GetDiagnosticsResult { diagnostics: Diagnostic[]}