@r_masseater/song-format 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +33 -1
  2. package/dist/analysis.d.mts +95 -0
  3. package/dist/analysis.mjs +328 -0
  4. package/dist/analysis.mjs.map +1 -0
  5. package/dist/convert-als.d.mts +18 -0
  6. package/dist/convert-als.mjs +504 -0
  7. package/dist/convert-als.mjs.map +1 -0
  8. package/dist/convert-midi.d.mts +2 -75
  9. package/dist/convert-midi.mjs +5 -650
  10. package/dist/convert-midi.mjs.map +1 -1
  11. package/dist/fumx-language-server.mjs +1 -1
  12. package/dist/fumx-language-server.mjs.map +1 -1
  13. package/dist/fumx-module-CmHFC-eI.mjs +12513 -0
  14. package/dist/fumx-module-CmHFC-eI.mjs.map +1 -0
  15. package/dist/fumx-module-DJQrnEVm.mjs +2660 -0
  16. package/dist/fumx-module-DJQrnEVm.mjs.map +1 -0
  17. package/dist/grammar-86_uhiTo.mjs +9836 -0
  18. package/dist/grammar-86_uhiTo.mjs.map +1 -0
  19. package/dist/index-Cup9xTad.d.mts +105 -0
  20. package/dist/index-DPt8MZ6e.d.mts +796 -0
  21. package/dist/index-JXjnMHXw.d.mts +1350 -0
  22. package/dist/index.d.mts +9 -0
  23. package/dist/index.mjs +4 -0
  24. package/dist/language.d.mts +13 -0
  25. package/dist/language.mjs +3 -0
  26. package/dist/mapper.mjs +1 -1
  27. package/dist/midi-to-fumx.mjs +140 -45
  28. package/dist/midi-to-fumx.mjs.map +1 -1
  29. package/dist/read-song-CNrfcHrY.mjs +123 -0
  30. package/dist/read-song-CNrfcHrY.mjs.map +1 -0
  31. package/dist/read-song-CSIhaAEB.mjs +122 -0
  32. package/dist/read-song-CSIhaAEB.mjs.map +1 -0
  33. package/dist/run-main-Bf32CgzU.mjs +26 -0
  34. package/dist/run-main-Bf32CgzU.mjs.map +1 -0
  35. package/dist/song-3Zm9g84K.d.mts +1478 -0
  36. package/dist/song-CYFBSTbH.mjs +387 -0
  37. package/dist/song-CYFBSTbH.mjs.map +1 -0
  38. package/dist/song-report.mjs +327 -4
  39. package/dist/song-report.mjs.map +1 -1
  40. package/dist/ticks-CXehHP2w.mjs +27 -0
  41. package/dist/ticks-CXehHP2w.mjs.map +1 -0
  42. package/dist/transform-DQm5wTlA.mjs +489 -0
  43. package/dist/transform-DQm5wTlA.mjs.map +1 -0
  44. package/dist/vite.mjs +4 -3
  45. package/dist/vite.mjs.map +1 -1
  46. package/dist/write-CS-ZjoQB.mjs +746 -0
  47. package/dist/write-CS-ZjoQB.mjs.map +1 -0
  48. package/package.json +50 -8
  49. package/skills/read-fumx/SKILL.md +86 -0
  50. package/skills/use-fumx-tools/SKILL.md +1 -1
  51. package/dist/app-CdpGdiWq.mjs +0 -190
  52. package/dist/app-CdpGdiWq.mjs.map +0 -1
  53. package/dist/transform-C24h3upp.mjs +0 -108
  54. package/dist/transform-C24h3upp.mjs.map +0 -1
@@ -0,0 +1,123 @@
1
+ import { G as isSong } from "./grammar-86_uhiTo.mjs";
2
+ import { a as importedUriOf, i as compileSong, n as createFumxServices, o as isNamed } from "./fumx-module-DJQrnEVm.mjs";
3
+ import { Array, Effect, Option, Predicate, pipe } from "effect";
4
+ import { CstUtils, GrammarUtils, URI, isLeafCstNode } from "langium";
5
+ // src/features/read-song/model/comments.ts
6
+ const KINDS = ["SL_COMMENT", "ML_COMMENT"];
7
+ const FIRST$1 = 1;
8
+ const leavesOf = (cst) => CstUtils.streamCst(cst).filter((node) => isLeafCstNode(node)).toArray();
9
+ const isComment = (leaf) => leaf.hidden && Array.contains(KINDS, leaf.tokenType.name);
10
+ const commentsOf = (root) => pipe(Option.fromNullishOr(root.$cstNode), Option.map(leavesOf), Option.getOrElse(() => []), Array.filter(isComment), Array.map((leaf) => ({
11
+ line: leaf.range.start.line + FIRST$1,
12
+ column: leaf.range.start.character + FIRST$1,
13
+ text: leaf.text
14
+ })));
15
+ // src/features/read-song/model/outline.ts
16
+ const emptyOutline = {
17
+ title: Option.none(),
18
+ names: [],
19
+ imports: [],
20
+ files: [],
21
+ comments: []
22
+ };
23
+ const spanOf = (node) => ({
24
+ start: node.offset,
25
+ end: node.end
26
+ });
27
+ const propertySpanOf = (node) => (property) => pipe(Option.fromNullishOr(GrammarUtils.findNodeForProperty(node.$cstNode, property)), Option.map(spanOf));
28
+ const namesOf = (song) => pipe(song.declarations, Array.filter(isNamed), Array.flatMap((declaration) => pipe(propertySpanOf(declaration)("name"), Option.map((span) => ({
29
+ type: declaration.$type,
30
+ name: declaration.name,
31
+ span
32
+ })), Option.toArray)));
33
+ const importsOf = (song) => pipe(song.imports, Array.flatMap((node) => pipe(propertySpanOf(node)("path"), Option.map((span) => ({
34
+ path: importedUriOf(node).fsPath,
35
+ span
36
+ })), Option.toArray)));
37
+ const outlineOf = (files) => (song) => ({
38
+ title: propertySpanOf(song)("title"),
39
+ names: namesOf(song),
40
+ imports: importsOf(song),
41
+ files,
42
+ comments: commentsOf(song)
43
+ });
44
+ // src/features/read-song/model/read-song.ts
45
+ const FIRST = 1;
46
+ const ERROR = 1;
47
+ const messageOf = (message) => {
48
+ if (Predicate.isString(message)) return message;
49
+ return message.value;
50
+ };
51
+ const loader = (services) => (read) => {
52
+ const { LangiumDocuments, LangiumDocumentFactory } = services.shared.workspace;
53
+ const load = (uri) => Effect.gen(function* loadDocument() {
54
+ if (LangiumDocuments.hasDocument(uri)) return;
55
+ const text = yield* read(uri.fsPath);
56
+ if (Option.isNone(text)) return;
57
+ const document = LangiumDocumentFactory.fromString(text.value, uri);
58
+ LangiumDocuments.addDocument(document);
59
+ yield* Effect.forEach(document.parseResult.value.imports, (node) => load(importedUriOf(node)), {
60
+ concurrency: 1,
61
+ discard: true
62
+ });
63
+ });
64
+ return load;
65
+ };
66
+ const issuesOf = (document) => pipe(document.diagnostics ?? [], Array.filter((diagnostic) => diagnostic.severity === ERROR), Array.map((diagnostic) => ({
67
+ path: document.uri.fsPath,
68
+ line: diagnostic.range.start.line + FIRST,
69
+ column: diagnostic.range.start.character + FIRST,
70
+ start: document.textDocument.offsetAt(diagnostic.range.start),
71
+ end: document.textDocument.offsetAt(diagnostic.range.end),
72
+ message: messageOf(diagnostic.message)
73
+ })));
74
+ const builtOf = (services) => (entry) => Effect.gen(function* build() {
75
+ const { workspace } = services.shared;
76
+ const documents = workspace.LangiumDocuments.all.toArray();
77
+ yield* Effect.promise(() => workspace.DocumentBuilder.build(documents, { validation: true }));
78
+ const files = pipe(documents, Array.map((document) => document.uri.fsPath));
79
+ const root = pipe(Option.fromNullishOr(workspace.LangiumDocuments.getDocument(entry)), Option.map((document) => document.parseResult.value), Option.filter(isSong));
80
+ const outline = pipe(root, Option.map(outlineOf(files)), Option.getOrElse(() => ({
81
+ ...emptyOutline,
82
+ files
83
+ })));
84
+ const issues = pipe(documents, Array.flatMap(issuesOf));
85
+ if (Array.isReadonlyArrayNonEmpty(issues)) return {
86
+ status: "invalid",
87
+ issues,
88
+ outline
89
+ };
90
+ return Option.match(root, {
91
+ onNone: () => ({
92
+ status: "invalid",
93
+ issues: [],
94
+ outline
95
+ }),
96
+ onSome: (song) => ({
97
+ status: "valid",
98
+ song: compileSong(song).value,
99
+ outline
100
+ })
101
+ });
102
+ });
103
+ const readSong = Effect.fnUntraced(function* read(files) {
104
+ const services = createFumxServices();
105
+ const entry = URI.file(files.path);
106
+ yield* loader(services)((path) => Effect.option(files.read(path)))(entry);
107
+ if (!services.shared.workspace.LangiumDocuments.hasDocument(entry)) return {
108
+ status: "invalid",
109
+ issues: [{
110
+ path: files.path,
111
+ line: FIRST,
112
+ column: FIRST,
113
+ start: 0,
114
+ end: 0,
115
+ message: "ファイルを読めません"
116
+ }],
117
+ outline: emptyOutline
118
+ };
119
+ return yield* builtOf(services)(entry);
120
+ });
121
+ export { readSong as t };
122
+
123
+ //# sourceMappingURL=read-song-CNrfcHrY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-song-CNrfcHrY.mjs","names":["FIRST","Arr","Arr","Arr"],"sources":["../src/features/read-song/model/comments.ts","../src/features/read-song/model/outline.ts","../src/features/read-song/model/read-song.ts"],"sourcesContent":["import { Array as Arr, Option, pipe } from \"effect\";\nimport { CstUtils, isLeafCstNode } from \"langium\";\nimport type { AstNode, CstNode, LeafCstNode } from \"langium\";\n\nimport type { From } from \"./problem.ts\";\n\nconst KINDS = [\"SL_COMMENT\", \"ML_COMMENT\"];\nconst FIRST = 1;\n\nexport interface SourceComment {\n readonly line: number;\n readonly column: number;\n readonly text: string;\n}\n\nconst leavesOf: From<CstNode, readonly LeafCstNode[]> = (cst) =>\n CstUtils.streamCst(cst)\n .filter((node) => isLeafCstNode(node))\n .toArray();\n\nconst isComment: From<LeafCstNode, boolean> = (leaf) =>\n leaf.hidden && Arr.contains(KINDS, leaf.tokenType.name);\n\nexport const commentsOf: From<AstNode, readonly SourceComment[]> = (root) =>\n pipe(\n Option.fromNullishOr(root.$cstNode),\n Option.map(leavesOf),\n Option.getOrElse((): readonly LeafCstNode[] => []),\n Arr.filter(isComment),\n Arr.map((leaf) => ({\n line: leaf.range.start.line + FIRST,\n column: leaf.range.start.character + FIRST,\n text: leaf.text,\n })),\n );\n","import { Array as Arr, Option, pipe } from \"effect\";\nimport { GrammarUtils } from \"langium\";\nimport type { AstNode, CstNode } from \"langium\";\n\nimport type { Song as SongNode } from \"#generated/langium/ast.ts\";\n\nimport { commentsOf } from \"./comments.ts\";\nimport type { SourceComment } from \"./comments.ts\";\nimport { isNamed } from \"./declarations.ts\";\nimport type { Named } from \"./declarations.ts\";\nimport type { From } from \"./problem.ts\";\nimport { importedUriOf } from \"./scope.ts\";\n\nexport interface Span {\n readonly start: number;\n readonly end: number;\n}\n\nexport interface NamedSpan {\n readonly type: Named[\"$type\"];\n readonly name: string;\n readonly span: Span;\n}\n\nexport interface ImportSpan {\n readonly path: string;\n readonly span: Span;\n}\n\nexport interface Outline {\n readonly title: Option.Option<Span>;\n readonly names: readonly NamedSpan[];\n readonly imports: readonly ImportSpan[];\n readonly files: readonly string[];\n readonly comments: readonly SourceComment[];\n}\n\nexport const emptyOutline: Outline = {\n title: Option.none(),\n names: [],\n imports: [],\n files: [],\n comments: [],\n};\n\nconst spanOf: From<CstNode, Span> = (node) => ({ start: node.offset, end: node.end });\n\nconst propertySpanOf: From<AstNode, From<string, Option.Option<Span>>> = (node) => (property) =>\n pipe(\n Option.fromNullishOr(GrammarUtils.findNodeForProperty(node.$cstNode, property)),\n Option.map(spanOf),\n );\n\nconst namesOf: From<SongNode, readonly NamedSpan[]> = (song) =>\n pipe(\n song.declarations,\n Arr.filter(isNamed),\n Arr.flatMap((declaration) =>\n pipe(\n propertySpanOf(declaration)(\"name\"),\n Option.map((span) => ({ type: declaration.$type, name: declaration.name, span })),\n Option.toArray,\n ),\n ),\n );\n\nconst importsOf: From<SongNode, readonly ImportSpan[]> = (song) =>\n pipe(\n song.imports,\n Arr.flatMap((node) =>\n pipe(\n propertySpanOf(node)(\"path\"),\n Option.map((span) => ({ path: importedUriOf(node).fsPath, span })),\n Option.toArray,\n ),\n ),\n );\n\nexport const outlineOf: From<readonly string[], From<SongNode, Outline>> = (files) => (song) => ({\n title: propertySpanOf(song)(\"title\"),\n names: namesOf(song),\n imports: importsOf(song),\n files,\n comments: commentsOf(song),\n});\n","import { Array as Arr, Effect, Option, Predicate, pipe } from \"effect\";\nimport { URI } from \"langium\";\nimport type { LangiumDocument } from \"langium\";\nimport type { Diagnostic } from \"vscode-languageserver\";\n\nimport type { Song } from \"#/entities/song/index.ts\";\nimport { isSong } from \"#generated/langium/ast.ts\";\nimport type { Song as SongNode } from \"#generated/langium/ast.ts\";\n\nimport { compileSong } from \"./compile.ts\";\nimport { createFumxServices } from \"./fumx-module.ts\";\nimport type { FumxServices } from \"./fumx-module.ts\";\nimport { emptyOutline, outlineOf } from \"./outline.ts\";\nimport type { Outline } from \"./outline.ts\";\nimport type { From } from \"./problem.ts\";\nimport { importedUriOf } from \"./scope.ts\";\n\nconst FIRST = 1;\nconst ERROR = 1;\n\nexport interface SourceIssue {\n readonly path: string;\n readonly line: number;\n readonly column: number;\n readonly start: number;\n readonly end: number;\n readonly message: string;\n}\n\nexport type SongSource =\n | {\n readonly status: \"invalid\";\n readonly issues: readonly SourceIssue[];\n readonly outline: Outline;\n }\n | { readonly status: \"valid\"; readonly song: Song; readonly outline: Outline };\n\nexport interface SongFiles<Failure> {\n readonly path: string;\n readonly read: (path: string) => Effect.Effect<string, Failure>;\n}\n\nconst messageOf: From<Diagnostic[\"message\"], string> = (message) => {\n if (Predicate.isString(message)) {\n return message;\n }\n return message.value;\n};\n\ntype Reader = From<string, Effect.Effect<Option.Option<string>>>;\n\nconst loader: From<FumxServices, From<Reader, From<URI, Effect.Effect<void>>>> =\n (services) => (read) => {\n const { LangiumDocuments, LangiumDocumentFactory } = services.shared.workspace;\n const load: From<URI, Effect.Effect<void>> = (uri) =>\n Effect.gen(function* loadDocument() {\n if (LangiumDocuments.hasDocument(uri)) {\n return;\n }\n const text = yield* read(uri.fsPath);\n if (Option.isNone(text)) {\n return;\n }\n const document = LangiumDocumentFactory.fromString<SongNode>(text.value, uri);\n LangiumDocuments.addDocument(document);\n yield* Effect.forEach(\n document.parseResult.value.imports,\n (node) => load(importedUriOf(node)),\n { concurrency: 1, discard: true },\n );\n });\n return load;\n };\n\nconst issuesOf: From<LangiumDocument, readonly SourceIssue[]> = (document) =>\n pipe(\n document.diagnostics ?? [],\n Arr.filter((diagnostic) => diagnostic.severity === ERROR),\n Arr.map((diagnostic) => ({\n path: document.uri.fsPath,\n line: diagnostic.range.start.line + FIRST,\n column: diagnostic.range.start.character + FIRST,\n start: document.textDocument.offsetAt(diagnostic.range.start),\n end: document.textDocument.offsetAt(diagnostic.range.end),\n message: messageOf(diagnostic.message),\n })),\n );\n\nconst builtOf: From<FumxServices, From<URI, Effect.Effect<SongSource>>> = (services) => (entry) =>\n Effect.gen(function* build() {\n const { workspace } = services.shared;\n const documents = workspace.LangiumDocuments.all.toArray();\n yield* Effect.promise(() => workspace.DocumentBuilder.build(documents, { validation: true }));\n const files = pipe(\n documents,\n Arr.map((document) => document.uri.fsPath),\n );\n const root = pipe(\n Option.fromNullishOr(workspace.LangiumDocuments.getDocument(entry)),\n Option.map((document) => document.parseResult.value),\n Option.filter(isSong),\n );\n const outline = pipe(\n root,\n Option.map(outlineOf(files)),\n Option.getOrElse(() => ({ ...emptyOutline, files })),\n );\n const issues = pipe(documents, Arr.flatMap(issuesOf));\n if (Arr.isReadonlyArrayNonEmpty(issues)) {\n return { status: \"invalid\", issues, outline };\n }\n return Option.match(root, {\n onNone: (): SongSource => ({ status: \"invalid\", issues: [], outline }),\n onSome: (song): SongSource => ({ status: \"valid\", song: compileSong(song).value, outline }),\n });\n });\n\nexport const readSong = Effect.fnUntraced(function* read<Failure>(\n files: SongFiles<Failure>,\n): Effect.fn.Return<SongSource> {\n const services = createFumxServices();\n const entry = URI.file(files.path);\n yield* loader(services)((path) => Effect.option(files.read(path)))(entry);\n if (!services.shared.workspace.LangiumDocuments.hasDocument(entry)) {\n return {\n status: \"invalid\",\n issues: [\n {\n path: files.path,\n line: FIRST,\n column: FIRST,\n start: 0,\n end: 0,\n message: \"ファイルを読めません\",\n },\n ],\n outline: emptyOutline,\n };\n }\n return yield* builtOf(services)(entry);\n});\n"],"mappings":";;;;;AAMA,MAAM,QAAQ,CAAC,cAAc,YAAY;AACzC,MAAMA,UAAQ;AAQd,MAAM,YAAmD,QACvD,SAAS,UAAU,GAAG,CAAC,CACpB,QAAQ,SAAS,cAAc,IAAI,CAAC,CAAC,CACrC,QAAQ;AAEb,MAAM,aAAyC,SAC7C,KAAK,UAAUC,MAAI,SAAS,OAAO,KAAK,UAAU,IAAI;AAExD,MAAa,cAAuD,SAClE,KACE,OAAO,cAAc,KAAK,QAAQ,GAClC,OAAO,IAAI,QAAQ,GACnB,OAAO,gBAAwC,CAAC,CAAC,GACjDA,MAAI,OAAO,SAAS,GACpBA,MAAI,KAAK,UAAU;CAC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3B,OAAO,iBAAiB;EAAE,GAAG;EAAc;CAAM,EAAE,CACrD;CACA,MAAM,SAAS,KAAK,WAAWA,MAAI,QAAQ,QAAQ,CAAC;CACpD,IAAIA,MAAI,wBAAwB,MAAM,GACpC,OAAO;EAAE,QAAQ;EAAW;EAAQ;CAAQ;CAE9C,OAAO,OAAO,MAAM,MAAM;EACxB,eAA2B;GAAE,QAAQ;GAAW,QAAQ,CAAC;GAAG;EAAQ;EACpE,SAAS,UAAsB;GAAE,QAAQ;GAAS,MAAM,YAAY,IAAI,CAAC,CAAC;GAAO;EAAQ;CAC3F,CAAC;AACH,CAAC;AAEH,MAAa,WAAW,OAAO,WAAW,UAAU,KAClD,OAC8B;CAC9B,MAAM,WAAW,mBAAmB;CACpC,MAAM,QAAQ,IAAI,KAAK,MAAM,IAAI;CACjC,OAAO,OAAO,QAAQ,CAAC,EAAE,SAAS,OAAO,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK;CACxE,IAAI,CAAC,SAAS,OAAO,UAAU,iBAAiB,YAAY,KAAK,GAC/D,OAAO;EACL,QAAQ;EACR,QAAQ,CACN;GACE,MAAM,MAAM;GACZ,MAAM;GACN,QAAQ;GACR,OAAO;GACP,KAAK;GACL,SAAS;EACX,CACF;EACA,SAAS;CACX;CAEF,OAAO,OAAO,QAAQ,QAAQ,CAAC,CAAC,KAAK;AACvC,CAAC"}
@@ -0,0 +1,122 @@
1
+ import { a as importedUriOf, i as compileSong, n as createFumxServices, o as isNamed, p as isSong } from "./fumx-module-CmHFC-eI.mjs";
2
+ import { CstUtils, GrammarUtils, URI, isLeafCstNode } from "langium";
3
+ import { Array, Effect, Option, Predicate, pipe } from "effect";
4
+ // src/features/read-song/model/comments.ts
5
+ const KINDS = ["SL_COMMENT", "ML_COMMENT"];
6
+ const FIRST$1 = 1;
7
+ const leavesOf = (cst) => CstUtils.streamCst(cst).filter((node) => isLeafCstNode(node)).toArray();
8
+ const isComment = (leaf) => leaf.hidden && Array.contains(KINDS, leaf.tokenType.name);
9
+ const commentsOf = (root) => pipe(Option.fromNullishOr(root.$cstNode), Option.map(leavesOf), Option.getOrElse(() => []), Array.filter(isComment), Array.map((leaf) => ({
10
+ line: leaf.range.start.line + FIRST$1,
11
+ column: leaf.range.start.character + FIRST$1,
12
+ text: leaf.text
13
+ })));
14
+ // src/features/read-song/model/outline.ts
15
+ const emptyOutline = {
16
+ title: Option.none(),
17
+ names: [],
18
+ imports: [],
19
+ files: [],
20
+ comments: []
21
+ };
22
+ const spanOf = (node) => ({
23
+ start: node.offset,
24
+ end: node.end
25
+ });
26
+ const propertySpanOf = (node) => (property) => pipe(Option.fromNullishOr(GrammarUtils.findNodeForProperty(node.$cstNode, property)), Option.map(spanOf));
27
+ const namesOf = (song) => pipe(song.declarations, Array.filter(isNamed), Array.flatMap((declaration) => pipe(propertySpanOf(declaration)("name"), Option.map((span) => ({
28
+ type: declaration.$type,
29
+ name: declaration.name,
30
+ span
31
+ })), Option.toArray)));
32
+ const importsOf = (song) => pipe(song.imports, Array.flatMap((node) => pipe(propertySpanOf(node)("path"), Option.map((span) => ({
33
+ path: importedUriOf(node).fsPath,
34
+ span
35
+ })), Option.toArray)));
36
+ const outlineOf = (files) => (song) => ({
37
+ title: propertySpanOf(song)("title"),
38
+ names: namesOf(song),
39
+ imports: importsOf(song),
40
+ files,
41
+ comments: commentsOf(song)
42
+ });
43
+ // src/features/read-song/model/read-song.ts
44
+ const FIRST = 1;
45
+ const ERROR = 1;
46
+ const messageOf = (message) => {
47
+ if (Predicate.isString(message)) return message;
48
+ return message.value;
49
+ };
50
+ const loader = (services) => (read) => {
51
+ const { LangiumDocuments, LangiumDocumentFactory } = services.shared.workspace;
52
+ const load = (uri) => Effect.gen(function* loadDocument() {
53
+ if (LangiumDocuments.hasDocument(uri)) return;
54
+ const text = yield* read(uri.fsPath);
55
+ if (Option.isNone(text)) return;
56
+ const document = LangiumDocumentFactory.fromString(text.value, uri);
57
+ LangiumDocuments.addDocument(document);
58
+ yield* Effect.forEach(document.parseResult.value.imports, (node) => load(importedUriOf(node)), {
59
+ concurrency: 1,
60
+ discard: true
61
+ });
62
+ });
63
+ return load;
64
+ };
65
+ const issuesOf = (document) => pipe(document.diagnostics ?? [], Array.filter((diagnostic) => diagnostic.severity === ERROR), Array.map((diagnostic) => ({
66
+ path: document.uri.fsPath,
67
+ line: diagnostic.range.start.line + FIRST,
68
+ column: diagnostic.range.start.character + FIRST,
69
+ start: document.textDocument.offsetAt(diagnostic.range.start),
70
+ end: document.textDocument.offsetAt(diagnostic.range.end),
71
+ message: messageOf(diagnostic.message)
72
+ })));
73
+ const builtOf = (services) => (entry) => Effect.gen(function* build() {
74
+ const { workspace } = services.shared;
75
+ const documents = workspace.LangiumDocuments.all.toArray();
76
+ yield* Effect.promise(() => workspace.DocumentBuilder.build(documents, { validation: true }));
77
+ const files = pipe(documents, Array.map((document) => document.uri.fsPath));
78
+ const root = pipe(Option.fromNullishOr(workspace.LangiumDocuments.getDocument(entry)), Option.map((document) => document.parseResult.value), Option.filter(isSong));
79
+ const outline = pipe(root, Option.map(outlineOf(files)), Option.getOrElse(() => ({
80
+ ...emptyOutline,
81
+ files
82
+ })));
83
+ const issues = pipe(documents, Array.flatMap(issuesOf));
84
+ if (Array.isReadonlyArrayNonEmpty(issues)) return {
85
+ status: "invalid",
86
+ issues,
87
+ outline
88
+ };
89
+ return Option.match(root, {
90
+ onNone: () => ({
91
+ status: "invalid",
92
+ issues: [],
93
+ outline
94
+ }),
95
+ onSome: (song) => ({
96
+ status: "valid",
97
+ song: compileSong(song).value,
98
+ outline
99
+ })
100
+ });
101
+ });
102
+ const readSong = Effect.fnUntraced(function* read(files) {
103
+ const services = createFumxServices();
104
+ const entry = URI.file(files.path);
105
+ yield* loader(services)((path) => Effect.option(files.read(path)))(entry);
106
+ if (!services.shared.workspace.LangiumDocuments.hasDocument(entry)) return {
107
+ status: "invalid",
108
+ issues: [{
109
+ path: files.path,
110
+ line: FIRST,
111
+ column: FIRST,
112
+ start: 0,
113
+ end: 0,
114
+ message: "ファイルを読めません"
115
+ }],
116
+ outline: emptyOutline
117
+ };
118
+ return yield* builtOf(services)(entry);
119
+ });
120
+ export { readSong as t };
121
+
122
+ //# sourceMappingURL=read-song-CSIhaAEB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-song-CSIhaAEB.mjs","names":["FIRST","Arr","Arr","Arr"],"sources":["../src/features/read-song/model/comments.ts","../src/features/read-song/model/outline.ts","../src/features/read-song/model/read-song.ts"],"sourcesContent":["import { Array as Arr, Option, pipe } from \"effect\";\nimport { CstUtils, isLeafCstNode } from \"langium\";\nimport type { AstNode, CstNode, LeafCstNode } from \"langium\";\n\nimport type { From } from \"./problem.ts\";\n\nconst KINDS = [\"SL_COMMENT\", \"ML_COMMENT\"];\nconst FIRST = 1;\n\nexport interface SourceComment {\n readonly line: number;\n readonly column: number;\n readonly text: string;\n}\n\nconst leavesOf: From<CstNode, readonly LeafCstNode[]> = (cst) =>\n CstUtils.streamCst(cst)\n .filter((node) => isLeafCstNode(node))\n .toArray();\n\nconst isComment: From<LeafCstNode, boolean> = (leaf) =>\n leaf.hidden && Arr.contains(KINDS, leaf.tokenType.name);\n\nexport const commentsOf: From<AstNode, readonly SourceComment[]> = (root) =>\n pipe(\n Option.fromNullishOr(root.$cstNode),\n Option.map(leavesOf),\n Option.getOrElse((): readonly LeafCstNode[] => []),\n Arr.filter(isComment),\n Arr.map((leaf) => ({\n line: leaf.range.start.line + FIRST,\n column: leaf.range.start.character + FIRST,\n text: leaf.text,\n })),\n );\n","import { Array as Arr, Option, pipe } from \"effect\";\nimport { GrammarUtils } from \"langium\";\nimport type { AstNode, CstNode } from \"langium\";\n\nimport type { Song as SongNode } from \"#generated/langium/ast.ts\";\n\nimport { commentsOf } from \"./comments.ts\";\nimport type { SourceComment } from \"./comments.ts\";\nimport { isNamed } from \"./declarations.ts\";\nimport type { Named } from \"./declarations.ts\";\nimport type { From } from \"./problem.ts\";\nimport { importedUriOf } from \"./scope.ts\";\n\nexport interface Span {\n readonly start: number;\n readonly end: number;\n}\n\nexport interface NamedSpan {\n readonly type: Named[\"$type\"];\n readonly name: string;\n readonly span: Span;\n}\n\nexport interface ImportSpan {\n readonly path: string;\n readonly span: Span;\n}\n\nexport interface Outline {\n readonly title: Option.Option<Span>;\n readonly names: readonly NamedSpan[];\n readonly imports: readonly ImportSpan[];\n readonly files: readonly string[];\n readonly comments: readonly SourceComment[];\n}\n\nexport const emptyOutline: Outline = {\n title: Option.none(),\n names: [],\n imports: [],\n files: [],\n comments: [],\n};\n\nconst spanOf: From<CstNode, Span> = (node) => ({ start: node.offset, end: node.end });\n\nconst propertySpanOf: From<AstNode, From<string, Option.Option<Span>>> = (node) => (property) =>\n pipe(\n Option.fromNullishOr(GrammarUtils.findNodeForProperty(node.$cstNode, property)),\n Option.map(spanOf),\n );\n\nconst namesOf: From<SongNode, readonly NamedSpan[]> = (song) =>\n pipe(\n song.declarations,\n Arr.filter(isNamed),\n Arr.flatMap((declaration) =>\n pipe(\n propertySpanOf(declaration)(\"name\"),\n Option.map((span) => ({ type: declaration.$type, name: declaration.name, span })),\n Option.toArray,\n ),\n ),\n );\n\nconst importsOf: From<SongNode, readonly ImportSpan[]> = (song) =>\n pipe(\n song.imports,\n Arr.flatMap((node) =>\n pipe(\n propertySpanOf(node)(\"path\"),\n Option.map((span) => ({ path: importedUriOf(node).fsPath, span })),\n Option.toArray,\n ),\n ),\n );\n\nexport const outlineOf: From<readonly string[], From<SongNode, Outline>> = (files) => (song) => ({\n title: propertySpanOf(song)(\"title\"),\n names: namesOf(song),\n imports: importsOf(song),\n files,\n comments: commentsOf(song),\n});\n","import { Array as Arr, Effect, Option, Predicate, pipe } from \"effect\";\nimport { URI } from \"langium\";\nimport type { LangiumDocument } from \"langium\";\nimport type { Diagnostic } from \"vscode-languageserver\";\n\nimport type { Song } from \"#/entities/song/index.ts\";\nimport { isSong } from \"#generated/langium/ast.ts\";\nimport type { Song as SongNode } from \"#generated/langium/ast.ts\";\n\nimport { compileSong } from \"./compile.ts\";\nimport { createFumxServices } from \"./fumx-module.ts\";\nimport type { FumxServices } from \"./fumx-module.ts\";\nimport { emptyOutline, outlineOf } from \"./outline.ts\";\nimport type { Outline } from \"./outline.ts\";\nimport type { From } from \"./problem.ts\";\nimport { importedUriOf } from \"./scope.ts\";\n\nconst FIRST = 1;\nconst ERROR = 1;\n\nexport interface SourceIssue {\n readonly path: string;\n readonly line: number;\n readonly column: number;\n readonly start: number;\n readonly end: number;\n readonly message: string;\n}\n\nexport type SongSource =\n | {\n readonly status: \"invalid\";\n readonly issues: readonly SourceIssue[];\n readonly outline: Outline;\n }\n | { readonly status: \"valid\"; readonly song: Song; readonly outline: Outline };\n\nexport interface SongFiles<Failure> {\n readonly path: string;\n readonly read: (path: string) => Effect.Effect<string, Failure>;\n}\n\nconst messageOf: From<Diagnostic[\"message\"], string> = (message) => {\n if (Predicate.isString(message)) {\n return message;\n }\n return message.value;\n};\n\ntype Reader = From<string, Effect.Effect<Option.Option<string>>>;\n\nconst loader: From<FumxServices, From<Reader, From<URI, Effect.Effect<void>>>> =\n (services) => (read) => {\n const { LangiumDocuments, LangiumDocumentFactory } = services.shared.workspace;\n const load: From<URI, Effect.Effect<void>> = (uri) =>\n Effect.gen(function* loadDocument() {\n if (LangiumDocuments.hasDocument(uri)) {\n return;\n }\n const text = yield* read(uri.fsPath);\n if (Option.isNone(text)) {\n return;\n }\n const document = LangiumDocumentFactory.fromString<SongNode>(text.value, uri);\n LangiumDocuments.addDocument(document);\n yield* Effect.forEach(\n document.parseResult.value.imports,\n (node) => load(importedUriOf(node)),\n { concurrency: 1, discard: true },\n );\n });\n return load;\n };\n\nconst issuesOf: From<LangiumDocument, readonly SourceIssue[]> = (document) =>\n pipe(\n document.diagnostics ?? [],\n Arr.filter((diagnostic) => diagnostic.severity === ERROR),\n Arr.map((diagnostic) => ({\n path: document.uri.fsPath,\n line: diagnostic.range.start.line + FIRST,\n column: diagnostic.range.start.character + FIRST,\n start: document.textDocument.offsetAt(diagnostic.range.start),\n end: document.textDocument.offsetAt(diagnostic.range.end),\n message: messageOf(diagnostic.message),\n })),\n );\n\nconst builtOf: From<FumxServices, From<URI, Effect.Effect<SongSource>>> = (services) => (entry) =>\n Effect.gen(function* build() {\n const { workspace } = services.shared;\n const documents = workspace.LangiumDocuments.all.toArray();\n yield* Effect.promise(() => workspace.DocumentBuilder.build(documents, { validation: true }));\n const files = pipe(\n documents,\n Arr.map((document) => document.uri.fsPath),\n );\n const root = pipe(\n Option.fromNullishOr(workspace.LangiumDocuments.getDocument(entry)),\n Option.map((document) => document.parseResult.value),\n Option.filter(isSong),\n );\n const outline = pipe(\n root,\n Option.map(outlineOf(files)),\n Option.getOrElse(() => ({ ...emptyOutline, files })),\n );\n const issues = pipe(documents, Arr.flatMap(issuesOf));\n if (Arr.isReadonlyArrayNonEmpty(issues)) {\n return { status: \"invalid\", issues, outline };\n }\n return Option.match(root, {\n onNone: (): SongSource => ({ status: \"invalid\", issues: [], outline }),\n onSome: (song): SongSource => ({ status: \"valid\", song: compileSong(song).value, outline }),\n });\n });\n\nexport const readSong = Effect.fnUntraced(function* read<Failure>(\n files: SongFiles<Failure>,\n): Effect.fn.Return<SongSource> {\n const services = createFumxServices();\n const entry = URI.file(files.path);\n yield* loader(services)((path) => Effect.option(files.read(path)))(entry);\n if (!services.shared.workspace.LangiumDocuments.hasDocument(entry)) {\n return {\n status: \"invalid\",\n issues: [\n {\n path: files.path,\n line: FIRST,\n column: FIRST,\n start: 0,\n end: 0,\n message: \"ファイルを読めません\",\n },\n ],\n outline: emptyOutline,\n };\n }\n return yield* builtOf(services)(entry);\n});\n"],"mappings":";;;;AAMA,MAAM,QAAQ,CAAC,cAAc,YAAY;AACzC,MAAMA,UAAQ;AAQd,MAAM,YAAmD,QACvD,SAAS,UAAU,GAAG,CAAC,CACpB,QAAQ,SAAS,cAAc,IAAI,CAAC,CAAC,CACrC,QAAQ;AAEb,MAAM,aAAyC,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AAS,IAAI,MAAM,CAC3C;CACA,MAAM,OAAO,KACX,OAAO,cAAc,UAAU,iBAAiB,YAAY,KAAK,CAAC,GAClE,OAAO,KAAK,aAAa,SAAS,YAAY,KAAK,GACnD,OAAO,OAAO,MAAM,CACtB;CACA,MAAM,UAAU,KACd,MACA,OAAO,IAAI,UAAU,KAAK,CAAC,GAC3B,OAAO,iBAAiB;EAAE,GAAG;EAAc;CAAM,EAAE,CACrD;CACA,MAAM,SAAS,KAAK,WAAWA,MAAI,QAAQ,QAAQ,CAAC;CACpD,IAAIA,MAAI,wBAAwB,MAAM,GACpC,OAAO;EAAE,QAAQ;EAAW;EAAQ;CAAQ;CAE9C,OAAO,OAAO,MAAM,MAAM;EACxB,eAA2B;GAAE,QAAQ;GAAW,QAAQ,CAAC;GAAG;EAAQ;EACpE,SAAS,UAAsB;GAAE,QAAQ;GAAS,MAAM,YAAY,IAAI,CAAC,CAAC;GAAO;EAAQ;CAC3F,CAAC;AACH,CAAC;AAEH,MAAa,WAAW,OAAO,WAAW,UAAU,KAClD,OAC8B;CAC9B,MAAM,WAAW,mBAAmB;CACpC,MAAM,QAAQ,IAAI,KAAK,MAAM,IAAI;CACjC,OAAO,OAAO,QAAQ,CAAC,EAAE,SAAS,OAAO,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK;CACxE,IAAI,CAAC,SAAS,OAAO,UAAU,iBAAiB,YAAY,KAAK,GAC/D,OAAO;EACL,QAAQ;EACR,QAAQ,CACN;GACE,MAAM,MAAM;GACZ,MAAM;GACN,QAAQ;GACR,OAAO;GACP,KAAK;GACL,SAAS;EACX,CACF;EACA,SAAS;CACX;CAEF,OAAO,OAAO,QAAQ,QAAQ,CAAC,CAAC,KAAK;AACvC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { Effect, Layer, Option } from "effect";
2
+ import { runMain } from "@effect/platform-node/NodeRuntime";
3
+ import { layer } from "@effect/platform-node/NodeServices";
4
+ import { FetchHttpClient } from "effect/http";
5
+ import { Otlp, OtlpSerialization } from "effect/observability";
6
+ // ../node-main/src/features/run-main/model/run-main.ts
7
+ const platform = Layer.mergeAll(layer, FetchHttpClient.layer);
8
+ const runWithTracingAnd = ({ serviceName, services, onFailure }) => (program) => {
9
+ const tracing = Otlp.layerFromConfig({ resource: { serviceName } }).pipe(Layer.provide(OtlpSerialization.layerJson), Layer.provide(FetchHttpClient.layer));
10
+ const provided = Layer.provideMerge(services, platform);
11
+ const report = Option.fromNullishOr(onFailure);
12
+ const reported = Option.match(report, {
13
+ onNone: () => program,
14
+ onSome: (handler) => Effect.tapCause(program, handler)
15
+ });
16
+ runMain(Layer.mergeAll(tracing, provided).pipe(Layer.build, Effect.flatMap((context) => Effect.provideContext(reported, context)), Effect.scoped), { disableErrorReporting: Option.isSome(report) });
17
+ };
18
+ const runWithTracing = (serviceName) => runWithTracingAnd({
19
+ serviceName,
20
+ services: Layer.empty
21
+ });
22
+ /** @internal */
23
+ const runMain$1 = runWithTracing;
24
+ export { runMain$1 as t };
25
+
26
+ //# sourceMappingURL=run-main-Bf32CgzU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-main-Bf32CgzU.mjs","names":["nodeServices","runMain"],"sources":["../../node-main/src/features/run-main/model/run-main.ts"],"sourcesContent":["import { runMain as nodeRuntimeRunMain } from \"@effect/platform-node/NodeRuntime\";\nimport { layer as nodeServices } from \"@effect/platform-node/NodeServices\";\nimport type { NodeServices } from \"@effect/platform-node/NodeServices\";\nimport { Effect, Layer, Option } from \"effect\";\nimport type { Cause } from \"effect\";\nimport { FetchHttpClient } from \"effect/http\";\nimport type { HttpClient } from \"effect/http\";\nimport { Otlp, OtlpSerialization } from \"effect/observability\";\n\n/** @internal */\nexport type Platform = NodeServices | HttpClient.HttpClient;\n\n/** @internal */\nexport type Run<Provided> = <Success, Failure>(\n program: Effect.Effect<Success, Failure, Platform | Provided>,\n) => void;\n\n/** @internal */\nexport type Report<Provided> = <Failure>(\n cause: Cause.Cause<Failure>,\n) => Effect.Effect<void, never, Platform | Provided>;\n\nconst platform = Layer.mergeAll(nodeServices, FetchHttpClient.layer);\n\nconst runWithTracingAnd =\n <Provided, LayerFailure>({\n serviceName,\n services,\n onFailure,\n }: Readonly<{\n serviceName: string;\n services: Layer.Layer<Provided, LayerFailure, Platform>;\n onFailure?: Report<Provided>;\n }>): Run<Provided> =>\n (program) => {\n const tracing = Otlp.layerFromConfig({ resource: { serviceName } }).pipe(\n Layer.provide(OtlpSerialization.layerJson),\n Layer.provide(FetchHttpClient.layer),\n );\n const provided = Layer.provideMerge(services, platform);\n const report = Option.fromNullishOr(onFailure);\n const reported = Option.match(report, {\n onNone: () => program,\n onSome: (handler) => Effect.tapCause(program, handler),\n });\n nodeRuntimeRunMain(\n Layer.mergeAll(tracing, provided).pipe(\n Layer.build,\n Effect.flatMap((context) => Effect.provideContext(reported, context)),\n Effect.scoped,\n ),\n { disableErrorReporting: Option.isSome(report) },\n );\n };\n\nconst runWithTracing = (serviceName: string): Run<never> =>\n runWithTracingAnd({ serviceName, services: Layer.empty });\n\n/** @internal */\nexport const runMainWith = runWithTracingAnd;\n\n/** @internal */\nexport const runMain = runWithTracing;\n"],"mappings":";;;;;;AAsBA,MAAM,WAAW,MAAM,SAASA,OAAc,gBAAgB,KAAK;AAEnE,MAAM,qBACqB,EACvB,aACA,UACA,iBAMD,YAAY;CACX,MAAM,UAAU,KAAK,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,KAClE,MAAM,QAAQ,kBAAkB,SAAS,GACzC,MAAM,QAAQ,gBAAgB,KAAK,CACrC;CACA,MAAM,WAAW,MAAM,aAAa,UAAU,QAAQ;CACtD,MAAM,SAAS,OAAO,cAAc,SAAS;CAC7C,MAAM,WAAW,OAAO,MAAM,QAAQ;EACpC,cAAc;EACd,SAAS,YAAY,OAAO,SAAS,SAAS,OAAO;CACvD,CAAC;CACD,QACE,MAAM,SAAS,SAAS,QAAQ,CAAC,CAAC,KAChC,MAAM,OACN,OAAO,SAAS,YAAY,OAAO,eAAe,UAAU,OAAO,CAAC,GACpE,OAAO,MACT,GACA,EAAE,uBAAuB,OAAO,OAAO,MAAM,EAAE,CACjD;AACF;AAEF,MAAM,kBAAkB,gBACtB,kBAAkB;CAAE;CAAa,UAAU,MAAM;AAAM,CAAC;;AAM1D,MAAaC,YAAU"}