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.3.0
exports
25
values
17
types
8
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(): 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

MIGRATE_CODES

const
const MIGRATE_CODES

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

16

SourceMap

const
const SourceMap
17

STATE_MACRO_COMPLETIONS

const
const STATE_MACRO_COMPLETIONS: LspCompletionItem[]

v2 macro-kind snippet completions (triggered by ' in

18

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.

19

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).

20

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

21

CompileResult

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

LspCompletionItem

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

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
}
24

AihuCodeMapping

type
type AihuCodeMapping = Mapping<CodeInformation>

Alias for clarity: a Volar CodeMapping carrying CodeInformation data.

25

AihuVirtualCode

type
type AihuVirtualCode