Janiczek/elm-syntax-type-inference/1.1.1

NOTE: the latest version is 2.0.1

Elm.TypeInference

Type inference for elm-syntax ASTs.

Optimized for lazy queries Range -> Maybe Type.

The process:

{ directDependencies : List PackageName
, allDependencies : List Dependency
, sourcesToResolveAmbiguity : Dict PackageName (List File)
}

Build a DependencyEnv.

Initially you can run with sourcesToResolveAmbiguity = Dict.empty. If you get NeedPackageSources back, read and parse those Elm files from the dependencies in your ELM_HOME (usually ~/.elm) and supply them in sourcesToResolveAmbiguity in the next call.

= Ready DependencyEnv
| NeedPackageSources (Dict PackageName (List String))
| Failed Error

Possible outcomes of running dependencyEnv.

An example NeedPackageSources:

Dict.fromList
    [ ( "example/css", [ "src/Css/Internal.elm" ] ) ]

Data parsed from dependencies' docs.json files.

This cache doesn't change as user's project code changes - only invalidate it and Project when elm.json changes.

type alias Dependency =
{ name : PackageName
, dependencies : List PackageName
, modules : List Module
}

Input to dependencyEnv.

A dependency package with its type information, parsed from the dependency's elm.json (via Elm.Project.decoder) and docs.json (via elm/project-metadata-utils Elm.Docs.decoder):

  • name: the package identifier (e.g. "elm/html").
  • dependencies: names of the package's immediate elm.json dependencies (eg. "elm/virtual-dom").
  • modules: the decoded docs.json modules.
Maybe PackageName
-> Dict ModuleName File
-> Result Error Project

Analyze the import graph of the project source code, producing a Project.

type Project

An indexed project: every file has been assigned a ModuleId and its imports resolved, but nothing has been solved yet. Cheap to build.

inferModule : ModuleName -> Project -> ( Result Error TypeLookupTable, Project )

Infer types in the given module.

Dict ModuleName File
-> ( { tables : Dict ModuleName TypeLookupTable
, errors : Dict ModuleName Error
}
)

Helper. Run inferModule for each of the given modules, collecting successes and errors into separate Dicts.