Skip to content

Commit abf0c8f

Browse files
committed
Add source link generation for documentation modules
- Implement source link generation for functions, classes, and other printable entities - Update Printer module to dynamically generate GitHub source links - Modify Domain and Parser modules to support source position tracking - Refactor printing functions to use Effect for source link generation - Update test cases to validate new source link functionality
1 parent 72626ac commit abf0c8f

9 files changed

Lines changed: 174 additions & 111 deletions

File tree

docs/modules/Checker.ts.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Since v0.6.0
3434
declare const checkClasses: (_classes: ReadonlyArray<Domain.Class>) => Effect.Effect<Array<never>, never, never>
3535
```
3636
37+
[Source](https://github.com/effect-ts/docgen/blob/main/src/Checker.ts#L32)
38+
3739
Since v0.6.0
3840
3941
## checkConstants
@@ -44,6 +46,8 @@ Since v0.6.0
4446
declare const checkConstants: (_constants: ReadonlyArray<Domain.Constant>) => Effect.Effect<Array<never>, never, never>
4547
```
4648
49+
[Source](https://github.com/effect-ts/docgen/blob/main/src/Checker.ts#L39)
50+
4751
Since v0.6.0
4852
4953
## checkExports
@@ -54,6 +58,8 @@ Since v0.6.0
5458
declare const checkExports: (_exports: ReadonlyArray<Domain.Export>) => Effect.Effect<Array<never>, never, never>
5559
```
5660
61+
[Source](https://github.com/effect-ts/docgen/blob/main/src/Checker.ts#L67)
62+
5763
Since v0.6.0
5864
5965
## checkFunctions
@@ -66,6 +72,8 @@ declare const checkFunctions: (
6672
) => Effect.Effect<Array<string>, never, Parser.Source>
6773
```
6874
75+
[Source](https://github.com/effect-ts/docgen/blob/main/src/Checker.ts#L25)
76+
6977
Since v0.6.0
7078
7179
## checkInterfaces
@@ -78,6 +86,8 @@ declare const checkInterfaces: (
7886
) => Effect.Effect<Array<never>, never, never>
7987
```
8088
89+
[Source](https://github.com/effect-ts/docgen/blob/main/src/Checker.ts#L46)
90+
8191
Since v0.6.0
8292
8393
## checkModule
@@ -88,6 +98,8 @@ Since v0.6.0
8898
declare const checkModule: (_module: Domain.Module) => Effect.Effect<Array<never>, never, never>
8999
```
90100
101+
[Source](https://github.com/effect-ts/docgen/blob/main/src/Checker.ts#L74)
102+
91103
Since v0.6.0
92104
93105
## checkNamespaces
@@ -100,6 +112,8 @@ declare const checkNamespaces: (
100112
) => Effect.Effect<Array<never>, never, never>
101113
```
102114
115+
[Source](https://github.com/effect-ts/docgen/blob/main/src/Checker.ts#L60)
116+
103117
Since v0.6.0
104118
105119
## checkTypeAliases
@@ -112,4 +126,6 @@ declare const checkTypeAliases: (
112126
) => Effect.Effect<Array<never>, never, never>
113127
```
114128
129+
[Source](https://github.com/effect-ts/docgen/blob/main/src/Checker.ts#L53)
130+
115131
Since v0.6.0

docs/modules/Domain.ts.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ Since v0.6.0
2929
- [\_tag (property)](#_tag-property-4)
3030
- [Method (class)](#method-class)
3131
- [Module (class)](#module-class)
32-
- [\_tag (property)](#_tag-property-5)
3332
- [Namespace (class)](#namespace-class)
34-
- [\_tag (property)](#_tag-property-6)
33+
- [\_tag (property)](#_tag-property-5)
3534
- [Position (interface)](#position-interface)
3635
- [Property (class)](#property-class)
3736
- [TypeAlias (class)](#typealias-class)
38-
- [\_tag (property)](#_tag-property-7)
37+
- [\_tag (property)](#_tag-property-6)
3938
- [service](#service)
4039
- [Process (class)](#process-class)
4140
- [sorting](#sorting)
@@ -256,6 +255,7 @@ Since v0.6.0
256255

257256
```ts
258257
declare class Module { constructor(
258+
readonly source: Parser.SourceShape,
259259
readonly name: string,
260260
readonly doc: Doc,
261261
readonly path: Array.NonEmptyReadonlyArray<string>,
@@ -271,16 +271,6 @@ declare class Module { constructor(
271271

272272
Since v0.6.0
273273

274-
### \_tag (property)
275-
276-
**Signature**
277-
278-
```ts
279-
readonly _tag: "Module"
280-
```
281-
282-
Since v0.6.0
283-
284274
## Namespace (class)
285275

286276
**Signature**

docs/modules/Parser.ts.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ declare const parseFiles: (
7171
>
7272
```
7373
74+
[Source](https://github.com/effect-ts/docgen/blob/main/src/Parser.ts#L667)
75+
7476
Since v0.6.0
7577
7678
## parseFunctions

docs/modules/Printer.ts.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,13 @@ export const a: string = "a"
3939
**Example** (Title 1)
4040

4141
```ts twoslash title="Title 1"
42-
import { Domain, Printer } from "@effect/docgen"
43-
import { Option } from "effect"
44-
45-
const doc = new Domain.Doc(undefined, ["1.0.0"], [], [], [], [], [], {})
46-
const m = new Domain.Module("tests", doc, ["src", "tests.ts"], [], [], [], [], [], [], [])
47-
console.log(Printer.printModule(m))
42+
export const b: string = "b"
4843
```
4944

5045
**Example** (Title 2)
5146

5247
```js twoslash title="Title 2"
53-
export const a: string = "b"
48+
export const c: string = "c"
5449
```
5550

5651
**Throws**
@@ -66,9 +61,11 @@ export const a: string = "b"
6661
**Signature**
6762

6863
```ts
69-
declare const printModule: (module: Domain.Module) => string
64+
declare const printModule: (module: Domain.Module) => Effect.Effect<string, never, Configuration.Configuration>
7065
```
7166
67+
[Source](https://github.com/effect-ts/docgen/blob/main/src/Printer.ts#L323)
68+
7269
Since v0.6.0
7370
7471
# utils
@@ -81,6 +78,8 @@ Since v0.6.0
8178
declare const prettify: (s: string) => Effect.Effect<string, never, never>
8279
```
8380
81+
[Source](https://github.com/effect-ts/docgen/blob/main/src/Printer.ts#L375)
82+
8483
Since v0.6.0
8584
8685
## printFrontMatter
@@ -91,4 +90,6 @@ Since v0.6.0
9190
declare const printFrontMatter: (module: Domain.Module, nav_order: number) => string
9291
```
9392
93+
[Source](https://github.com/effect-ts/docgen/blob/main/src/Printer.ts#L364)
94+
9495
Since v0.6.0

src/Core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ const getModuleMarkdownFiles = (modules: ReadonlyArray<Domain.Module>) =>
522522
Effect.forEach(modules, (module, i) =>
523523
Effect.gen(function*() {
524524
const outputPath = yield* getModuleMarkdownOutputPath(module)
525-
const moduleContent = Printer.printModule(module)
525+
const moduleContent = yield* Printer.printModule(module)
526526
const tocgen = yield* Effect.promise(async () => {
527527
// @ts-expect-error
528528
return await import("@effect/markdown-toc").then((m) => m.default)

src/Domain.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as Data from "effect/Data"
77
import * as Effect from "effect/Effect"
88
import * as Order from "effect/Order"
99
import * as String from "effect/String"
10-
10+
import type * as Parser from "./Parser.js"
1111
/**
1212
* @category model
1313
* @since 0.6.0
@@ -43,11 +43,8 @@ export class Doc {
4343
* @since 0.6.0
4444
*/
4545
export class Module {
46-
/**
47-
* @since 0.6.0
48-
*/
49-
readonly _tag = "Module" // TODO: remove this
5046
constructor(
47+
readonly source: Parser.SourceShape,
5148
readonly name: string,
5249
readonly doc: Doc,
5350
readonly path: Array.NonEmptyReadonlyArray<string>,

src/Parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ export const parseModule = Effect.gen(function*() {
601601
const namespaces = yield* parseNamespaces
602602
const name = source.sourceFile.getBaseName()
603603
return new Domain.Module(
604+
source,
604605
name,
605606
doc,
606607
source.path,
@@ -622,8 +623,8 @@ export const parseFile =
622623
(file: Domain.File): Effect.Effect<Domain.Module, Array<string>, Configuration.Configuration | Path.Path> => {
623624
return Effect.gen(function*() {
624625
const path = yield* Path.Path
625-
const filePath = file.path.split(path.sep)
626626
const sourceFile = project.getSourceFile(file.path)
627+
const filePath = file.path.split(path.sep)
627628
if (sourceFile !== undefined && Array.isNonEmptyArray(filePath)) {
628629
return yield* Effect.provideService(parseModule, Source, { sourceFile, path: filePath })
629630
}

0 commit comments

Comments
 (0)