API / @aihu/language-server

@aihu/language-server

Compiler & tooling

Cross-editor Language Server (aihu-language-server) for .aihu Single File Components — diagnostics, hover, completion, and quick-fix code actions.

version
0.4.1
exports
28
values
19
types
9
01

buildMigrateFix

function
function buildMigrateFix(source: string): MigrateFix | null

Run the macro-simplification codemod over `source` and return the fix payload.

02

compileWithDiagnostics

function
async function compileWithDiagnostics( source: string, filePath: string, ): Promise<CompileResult>

Compile a .aihu source string via stdin, returning structured diagnostics.

03

createAihuLanguagePlugin

function
function createAihuLanguagePlugin(options?: { strictTemplates?: boolean target?: 'client' | 'server' | 'universal' }): LanguagePlugin<URI, AihuVirtualCode>

Create the Volar LanguagePlugin for .aihu files.

04

createAihuLanguageServicePlugin

function
function createAihuLanguageServicePlugin(): LanguageServicePlugin

Create the Volar LanguageServicePlugin for aihu.

05

createTestServer

function
function createTestServer()

Create and wire the test seam for integration / unit tests.

06

getBlockContext

function
function getBlockContext( lines: string[], lineIndex: number, ): 'state' | 'template' | 'style' | 'agent' | 'route' | 'unknown'
07

getHoverContent

function
function getHoverContent(macro: string): string | null
08

getMacroAtPosition

function
function getMacroAtPosition(lineText: string, character: number): string | null
09

mapToOriginal

function
function mapToOriginal( virtualOffset: number, map: SourceMap<CodeInformation>, ): AihuSourcePosition | null

Map a virtual-file offset back to the original .aihu source offset.

10

mapToVirtual

function
function mapToVirtual( originalOffset: number, _block: '@state', map: SourceMap<CodeInformation>, ): AihuVirtualPosition | null

Map an original .aihu source offset to the virtual-file offset.

11

parseMachineErrors

function
function parseMachineErrors(stderr: string, filePath: string): AihuDiagnostic[]

Parse the Rust binary's `--machine-errors` stderr stream into structured diagnostics.

12

startServer

function
function startServer(): void

Start the language server on stdio and begin listening.

13

withAihuDiagnosticParity

function
function withAihuDiagnosticParity(plugin: LanguageServicePlugin): LanguageServicePlugin

Wrap a TypeScript LanguageServicePlugin (volar-service-typescript) so its diagnostics apply the SAME implicit-`any` suppression `aihu-tsc` applies to `.aihu` files by default (`IMPLICIT_ANY_CODES`, packages/tsc/src/index.ts).

14

BLOCK_COMPLETIONS

const
const BLOCK_COMPLETIONS: LspCompletionItem[]

Top-level block completions (triggered by '@' at top level).

15

COMPOSABLE_COMPLETIONS

const
const COMPOSABLE_COMPLETIONS: LspCompletionItem[]

`@aihu/use` composable completions, offered inside `@state` (FEL-342): the compiler auto-imports a bare `useMouse()`-style call (`use_registry.rs`), which previously meant no completion suggested the name existed at all, and TypeScript had no declaration for it until the sidecar's ambient decl landed — the two together made auto-import look like a red squiggle, invisible build magic instead of a feature.

16

COMPOSABLE_REGISTRY

const
const COMPOSABLE_REGISTRY: readonly ComposableRegistryEntry[]
17

MIGRATE_CODES

const
const MIGRATE_CODES

Compiler diagnostic codes whose QuickFix is the v2 macro migration codemod.

18

SourceMap

const
const SourceMap
19

STATE_MACRO_COMPLETIONS

const
const STATE_MACRO_COMPLETIONS: LspCompletionItem[]

v2 macro-kind snippet completions (triggered by '$' in

20

AihuDiagnostic

interface
interface AihuDiagnostic {
  code: string
  message: string
  // `| undefined` is explicit so the raw compiler error's optional hint/fix
  // (which may be undefined) assign cleanly under exactOptionalPropertyTypes.
  hint?: string | undefined
  fix?: string | undefined
  /** Original source text to replace (for code-action text edits). */
  fromText: string | null
  /** Replacement text (for code-action text edits). */
  toText: string | null
  /** 0-based LSP range. null when position is unknown. */
  range: {
    start: { line: number; character: number }
    end: { line: number; character: number }
  } | null
}

Normalised diagnostic with 0-based LSP positions.

21

AihuSourcePosition

interface
interface AihuSourcePosition {
  /** Character offset from the start of the .aihu source string. */
  offset: number
}

An offset within a .aihu source file (character offset from start of file).

22

AihuVirtualPosition

interface
interface AihuVirtualPosition {
  /** Character offset in the __state__.ts virtual file. */
  offset: number
}

An offset within a virtual __state__.ts file generated from the

23

CompileResult

interface
interface CompileResult {
  code: string | null
  diagnostics: AihuDiagnostic[]
}
24

ComposableRegistryEntry

interface
interface ComposableRegistryEntry {
  /** Bare call name, e.g. `useMouse`. */
  name: string
  /** Module specifier the compiler auto-imports, e.g. `@aihu/use/useMouse`. */
  specifier: string
  /** One-line purpose, extracted from the composable's doc comment. */
  description: string
}

packages/language-server/src/core/composable-registry.ts GENERATED — do not hand-edit.

25

LspCompletionItem

interface
interface LspCompletionItem {
  label: string
  kind: number
  insertTextFormat: number
  detail: string
  sortText: string
  insertText: string
}
26

MigrateFix

interface
interface MigrateFix {
  /** The full-document rewritten source. */
  rewritten: string
  /** Codemod warnings (e.g. @agent referencing unknown @state name). */
  warnings: readonly string[]
  /** Human-readable action title (includes warning count when non-zero). */
  title: string
}
27

AihuCodeMapping

type
type AihuCodeMapping = Mapping<CodeInformation>

Alias for clarity: a Volar CodeMapping carrying CodeInformation data.

28

AihuVirtualCode

type
type AihuVirtualCode