-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix line numbers computation in generated docs
- Loading branch information
Showing
11 changed files
with
718 additions
and
95 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import path from 'path'; | ||
import { Project } from 'ts-morph'; | ||
|
||
// const branch = 'main'; | ||
const branch = 'rewrite-in-ts'; | ||
let output = []; | ||
|
||
const project = new Project({ | ||
tsConfigFilePath: './tsconfig.json', | ||
}); | ||
|
||
for (const src of project.getSourceFiles('src/Decoder.ts')) { | ||
const func = src.getFunction('define'); | ||
const members = func.getFunctions(); | ||
|
||
for (const member of members) { | ||
// Grab the first JSDoc, which, technically, may live on an overload | ||
// declaration | ||
const comment = | ||
[...member.getJsDocs()] | ||
.map((x) => x.getCommentText()?.trim()) | ||
.filter(Boolean)?.[0] ?? null; | ||
|
||
const start = Math.min( | ||
member.getStartLineNumber(), | ||
...member.getJsDocs().map((doc) => doc.getStartLineNumber()), | ||
...member.getOverloads().map((ov) => ov.getStartLineNumber()), | ||
...member | ||
.getOverloads() | ||
.flatMap((ov) => ov.getJsDocs().map((doc) => doc.getStartLineNumber())), | ||
); | ||
const end = Math.max( | ||
member.getEndLineNumber(), | ||
...member.getJsDocs().map((doc) => doc.getEndLineNumber()), | ||
...member.getOverloads().map((ov) => ov.getEndLineNumber()), | ||
...member | ||
.getOverloads() | ||
.flatMap((ov) => ov.getJsDocs().map((doc) => doc.getEndLineNumber())), | ||
); | ||
|
||
const localPath = path.relative('.', src.getFilePath()); | ||
const remotePath = `https://github.com/nvie/decoders/tree/${branch}/${localPath}`; | ||
const remote = `${remotePath}#L${start}-L${end}`; | ||
|
||
output.push({ | ||
name: member.getName(), | ||
comment, | ||
span: { start, end }, | ||
localPath, | ||
remotePath, | ||
remote, | ||
}); | ||
} | ||
|
||
// const start = Math.min( | ||
// type.getStartLineNumber(), | ||
// ...type.getJsDocs().map((doc) => doc.getStartLineNumber()), | ||
// ...type.getOverloads().map((ov) => ov.getStartLineNumber()), | ||
// ...type | ||
// .getOverloads() | ||
// .flatMap((ov) => ov.getJsDocs().map((doc) => doc.getStartLineNumber())), | ||
// ); | ||
// const end = Math.max( | ||
// type.getEndLineNumber(), | ||
// ...type.getJsDocs().map((doc) => doc.getEndLineNumber()), | ||
// ...type.getOverloads().map((ov) => ov.getEndLineNumber()), | ||
// ...type | ||
// .getOverloads() | ||
// .flatMap((ov) => ov.getJsDocs().map((doc) => doc.getEndLineNumber())), | ||
// ); | ||
|
||
// const localPath = path.relative('.', src.getFilePath()); | ||
// const remotePath = `https://github.com/nvie/decoders/tree/${branch}/${localPath}`; | ||
// const remote = `${remotePath}#L${start}-L${end}`; | ||
|
||
// output.push({ | ||
// name: type.getName(), | ||
// comment, | ||
// span: { start, end }, | ||
// localPath, | ||
// remotePath, | ||
// remote, | ||
// }); | ||
// } | ||
|
||
// for (const stm of src.getVariableStatements()) { | ||
// if (!stm.hasExportKeyword()) continue; | ||
|
||
// // Grab the first JSDoc, which, technically, may live on an overload | ||
// // declaration | ||
// const comment = | ||
// [...stm.getJsDocs()].map((x) => x.getCommentText()?.trim()).filter(Boolean)?.[0] ?? | ||
// null; | ||
|
||
// for (const variable of stm.getDeclarations()) { | ||
// const start = Math.min( | ||
// variable.getStartLineNumber(), | ||
// ...stm.getJsDocs().map((doc) => doc.getStartLineNumber()), | ||
// ); | ||
// const end = Math.max( | ||
// variable.getEndLineNumber(), | ||
// ...stm.getJsDocs().map((doc) => doc.getEndLineNumber()), | ||
// ); | ||
// const localPath = path.relative('.', src.getFilePath()); | ||
// const remotePath = `https://github.com/nvie/decoders/tree/${branch}/${localPath}`; | ||
// const remote = `${remotePath}#L${start}-L${end}`; | ||
|
||
// output.push({ | ||
// name: variable.getName(), | ||
// comment, | ||
// span: { start, end }, | ||
// localPath, | ||
// remotePath, | ||
// remote, | ||
// }); | ||
// } | ||
} | ||
|
||
console.log(JSON.stringify(output, null, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import path from 'path'; | ||
import { Project } from 'ts-morph'; | ||
|
||
// const branch = 'main'; | ||
const branch = 'rewrite-in-ts'; | ||
let output = []; | ||
|
||
const project = new Project({ | ||
tsConfigFilePath: './tsconfig.json', | ||
}); | ||
|
||
for (const src of project.getSourceFiles('src/**')) { | ||
for (const func of src.getFunctions()) { | ||
if (!func.hasExportKeyword()) continue; | ||
|
||
// Grab the first JSDoc, which, technically, may live on an overload | ||
// declaration | ||
const comment = | ||
[...func.getJsDocs(), ...func.getOverloads().flatMap((ov) => ov.getJsDocs())] | ||
.map((x) => x.getCommentText()?.trim()) | ||
.filter(Boolean)?.[0] ?? null; | ||
|
||
const start = Math.min( | ||
func.getStartLineNumber(), | ||
...func.getJsDocs().map((doc) => doc.getStartLineNumber()), | ||
...func.getOverloads().map((ov) => ov.getStartLineNumber()), | ||
...func | ||
.getOverloads() | ||
.flatMap((ov) => ov.getJsDocs().map((doc) => doc.getStartLineNumber())), | ||
); | ||
const end = Math.max( | ||
func.getEndLineNumber(), | ||
...func.getJsDocs().map((doc) => doc.getEndLineNumber()), | ||
...func.getOverloads().map((ov) => ov.getEndLineNumber()), | ||
...func | ||
.getOverloads() | ||
.flatMap((ov) => ov.getJsDocs().map((doc) => doc.getEndLineNumber())), | ||
); | ||
|
||
const localPath = path.relative('.', src.getFilePath()); | ||
const remotePath = `https://github.com/nvie/decoders/tree/${branch}/${localPath}`; | ||
const remote = `${remotePath}#L${start}-L${end}`; | ||
|
||
output.push({ | ||
name: func.getName(), | ||
comment, | ||
span: { start, end }, | ||
localPath, | ||
remotePath, | ||
remote, | ||
}); | ||
} | ||
|
||
for (const stm of src.getVariableStatements()) { | ||
if (!stm.hasExportKeyword()) continue; | ||
|
||
// Grab the first JSDoc, which, technically, may live on an overload | ||
// declaration | ||
const comment = | ||
[...stm.getJsDocs()].map((x) => x.getCommentText()?.trim()).filter(Boolean)?.[0] ?? | ||
null; | ||
|
||
for (const variable of stm.getDeclarations()) { | ||
const start = Math.min( | ||
variable.getStartLineNumber(), | ||
...stm.getJsDocs().map((doc) => doc.getStartLineNumber()), | ||
); | ||
const end = Math.max( | ||
variable.getEndLineNumber(), | ||
...stm.getJsDocs().map((doc) => doc.getEndLineNumber()), | ||
); | ||
const localPath = path.relative('.', src.getFilePath()); | ||
const remotePath = `https://github.com/nvie/decoders/tree/${branch}/${localPath}`; | ||
const remote = `${remotePath}#L${start}-L${end}`; | ||
|
||
output.push({ | ||
name: variable.getName(), | ||
comment, | ||
span: { start, end }, | ||
localPath, | ||
remotePath, | ||
remote, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
console.log(JSON.stringify(output, null, 2)); |
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.