Skip to content

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'

Returns diagnostics from the IDE workspace.

const result = await getDiagnostics()
console.log(result.diagnostics.length) // number of diagnostics
ParameterTypeDescription
optionsGetDiagnosticsOptionsOptional configuration
OptionTypeDefaultDescription
pathstringundefinedFilter diagnostics to a specific file (relative to project root)
openFilesOnlybooleanfalseWhen true, returns diagnostics only for currently open files

Promise<GetDiagnosticsResult>

Returns an object containing a diagnostics array. The array is empty when no diagnostics match the requested scope.


FieldTypeDescription
diagnosticsDiagnostic[]Array of diagnostic entries

Each diagnostic entry describes a single issue reported by the IDE.

FieldTypeRequiredDescription
filestringYesFile path relative to the project root
linenumberYesStart line of the diagnostic (1-based)
columnnumberYesStart column of the diagnostic (1-based)
endLinenumberNoEnd line of the diagnostic range (1-based, present when range spans a region)
endColumnnumberNoEnd column of the diagnostic range (1-based, present when range spans a region)
messagestringYesThe diagnostic message text
severitySeverityYesOne of 'error', 'warning', 'info', or 'hint'
sourcestringNoThe tool that produced the diagnostic (e.g. 'typescript', 'eslint')

const result = await getDiagnostics()
for (const diag of result.diagnostics) {
console.log(`[${diag.severity}] ${diag.file}:${diag.line}:${diag.column}${diag.message}`)
}
const result = await getDiagnostics({ path: 'src/index.ts' })
console.log(`${result.diagnostics.length} issue(s) in src/index.ts`)
const result = await getDiagnostics({ openFilesOnly: true })
console.log(`${result.diagnostics.length} issue(s) in open files`)

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'
type Severity = 'error' | 'warning' | 'info' | 'hint'
interface Diagnostic {
file: string
line: number
column: number
endLine?: number
endColumn?: number
message: string
severity: Severity
source?: string
}
interface GetDiagnosticsOptions {
path?: string
openFilesOnly?: boolean
}
interface GetDiagnosticsResult {
diagnostics: Diagnostic[]
}