Skip to content

Commit fdcad40

Browse files
authored
Merge pull request #220 from MoiraeSoftware/docs/update-2026-03-02-56a54f49447f922c
[docs] Update documentation for features from 2026-03-01
2 parents d8842b9 + d8e859c commit fdcad40

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
### Added
1212
- `SynType.CreateFromLongIdent` helper in `Myriad.Core.AstExtensions`. Plugin authors can now convert a `LongIdent` to a `SynType` using this single convenience method instead of manually chaining `SynLongIdent.Create` and `SynType.CreateLongIdent`.
13+
- Generated code is now formatted using `.editorconfig` settings applicable to the output file. Myriad previously formatted all generated code with `FormatConfig.Default`, ignoring any Fantomas settings in `.editorconfig`. The new `Myriad.Core.EditorConfig.readConfiguration` function reads the `.editorconfig` file for the output path and maps `indent_size`, `max_line_length`, `end_of_line`, `insert_final_newline`, and all `fsharp_*` Fantomas properties to the corresponding `FormatConfig` values. If no `.editorconfig` is present, `FormatConfig.Default` is used as before.
14+
- `Ast.extractLiteralBindings` and `Ast.getAttributeConstantsWithBindings` helpers in `Myriad.Core`. Plugin authors can now resolve `[<Literal>]`-attributed identifier references in attribute arguments to their actual string values — for example when a type is annotated with `[<MyAttr(MyConst)>]` where `let [<Literal>] MyConst = "Hello"` is defined elsewhere in the same file.
1315

1416
### Fixed
1517
- Myriad now correctly processes input files that contain F# 8 dot-lambda (`_.property`) shorthand syntax. Previously, types using `_.` in `with member` bodies would cause a parse error:

docs/content/docs/Tutorials/configuration.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,18 @@ ValidInputExtensions is used so a plugin is tied to certain file types as input,
7676
While we are discussing the `IMyriadGenerator` interface lets discuss the `Generate` member:
7777

7878
Generate takes a `GeneratorContext` which contains the `ConfigKey` as mentioned above, the `ConfigGetter` : `string -> (string * obj) seq` which is a mean to allow access to the `myriad.toml` file, you give the function the configuration ket you wish to receive and it returns the configuration. Finally a `InputFilename` is also passed in so you can load or parse your input files ready to generate an AST. If you look at the included plugins you can see the mechanism for extracting and building AST fragments for reference.
79+
80+
# Code Formatting and .editorconfig
81+
82+
Myriad formats generated code using the [Fantomas](https://fsprojects.github.io/fantomas/) code formatter. By default it uses `FormatConfig.Default`, but if an `.editorconfig` file exists in or above the output file's directory, Myriad will automatically apply those settings.
83+
84+
Any standard Fantomas `.editorconfig` properties are supported, for example:
85+
86+
```ini
87+
[*.fs]
88+
indent_size = 2
89+
max_line_length = 100
90+
fsharp_space_before_colon = true
91+
```
92+
93+
This means generated files will match your project's formatting conventions without requiring them to be listed in `.fantomasignore`. The `.editorconfig` lookup is scoped to the output file path, so different output files in different directories can use different formatting settings.

docs/content/docs/Tutorials/external-plugins.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,34 @@ Myriad supports loading plugins built against a **different target framework** t
7474
The plugin loader uses `PreferSharedTypes = true`, which means assemblies already loaded by the Myriad host — such as `FSharp.Core` and `Fantomas.FCS` — are shared with the plugin rather than loaded again from the plugin's output directory. This prevents `System.Reflection.ReflectionTypeLoadException` that would otherwise occur due to type identity mismatches across `AssemblyLoadContext` boundaries.
7575

7676
> **Note:** While cross-framework plugin loading is supported, it is still recommended to target the same framework version as the Myriad tool for the most predictable behaviour.
77+
78+
## Resolving Literal Constant References in Attribute Arguments
79+
80+
When a type uses a `[<Literal>]`-attributed identifier as an attribute argument, the standard `Ast.getAttributeConstants` helper returns the identifier name rather than the constant value. For example:
81+
82+
```fsharp
83+
module A =
84+
let [<Literal>] MyConst = "Hello"
85+
86+
[<MyAttribute(MyConst)>]
87+
type Thing = { Foo: string }
88+
```
89+
90+
To resolve `MyConst` to `"Hello"` in your plugin, use the two-step API in `Myriad.Core.Ast`:
91+
92+
1. **`Ast.extractLiteralBindings`** — scans the entire parsed AST and returns a `Map<string, SynConst>` of all `[<Literal>]` bindings.
93+
2. **`Ast.getAttributeConstantsWithBindings`** — works like `getAttributeConstants` but also looks up any identifier arguments in the bindings map.
94+
95+
```fsharp
96+
open Myriad.Core
97+
98+
// In your Generate implementation:
99+
let bindings = Ast.extractLiteralBindings ast // ast : ParsedInput from GeneratorContext
100+
101+
let constants =
102+
someAttribute
103+
|> Ast.getAttributeConstantsWithBindings bindings
104+
// constants : string list — identifier references are now resolved to their literal values
105+
```
106+
107+
This avoids the need for type-checking (which would be significantly slower) and works entirely from the parsed AST available to every Myriad plugin.

0 commit comments

Comments
 (0)