Comments (7)
Quick on-the-bus question: have you tried ts.getJSDocTags(node: Node)? That only returns jsdoc of course, and it chops everything up into tags, but it might be enough.
I’ll take a closer look when I’m back in the office after the holiday.
from tsdoc.
@sandersn I don't think ts.getJSDocTags(node: Node)
will work. It attempts to parse the code comment (using the compiler's grammar rules which don't yet support TSDoc). Whereas for the purposes of this demo, we want to extract the /** ... */
text range so that we can pass it to the TSDoc library's parser.
from tsdoc.
I've been looking into this a bit more and noticed the ts.getCommentRange
method, which might meet the requirements.
from tsdoc.
I tried ts.getCommentRange()
but it returns a nonempty range for most AST nodes, which includes code expressions. The docs suggest that this function is meant to be used when injecting comments in emitted output.
So we still don't have an answer: What's a good way to scan a source file and find all the /** */
comment ranges? @RyanCavanaugh
from tsdoc.
@eps1lon thanks for contributing this PR. Today I'm going to look at the various options and see what's the best approach for this demo. I agree with @Gerrit0 that the demo itself should be self-contained, but maybe tsutils will provide a useful model.
from tsdoc.
After debugging into the compiler library, I realized that advancedDemo.ts#L69 was calling SourceFile.getText()
instead of SourceFile.getFullText()
. This sometimes some leading comments/whitespace, which shifted the buffer indexes around, producing mostly correct but sometimes very bizarre results. After fixing that, things got a lot more sane.
Although tsutils.forEachComment()
is a pretty good way to enumerate all comments associated with a subtree, I'm not sure it's best for this demo. The demo is meant to model a tool that discovers declarations and then parses the TSDoc that would conventionally be associated with a declaration. We probably would not want to exhaustively consider every comment in the input. Also we should ignore //
and /* */
style comments. The compiler's internal ts.getJSDocCommentRanges() seems like a closer match for what we need.
However, with this approach we sometimes pickup duplicates when iterating the AST tree. For example when analyzing "public static example(): void {
" and calling ts.getJSDocCommentRanges()
, it will find the same comment for both the PublicKeyword
node and the MethodDeclaration
node (since they have the same physical position). We need to filter out the "insignificant" nodes. @RyanCavanaugh pointed me to ts.isDeclaration()
which should work, however that is an unfortunately internal API.
I'll see if I can combine all these ideas together into a PR.
from tsdoc.
This was fixed in PR #59.
from tsdoc.
Related Issues (20)
- Upgrade Node.js and `node-sass` dependencies HOT 1
- Validate invalid params through tsdoc eslint plugin HOT 1
- This repo is missing important files
- Documentation coverage? HOT 1
- JSDoc/TSDoc `@inherit[dD]oc` mismatch HOT 1
- Is it dead? HOT 4
- VS Code unable to load Schema
- tsdoc-unnecessary-backslash false positive
- Weird warnings about multiple declarations HOT 1
- Grouping classes under the same index name
- Support for defining custom tag syntax HOT 1
- tsdoc-html-tag-missing-equals erroneously flagging boolean attributes
- tsdoc-malformed-html-name erroneously flagging use of less than symbol HOT 1
- Unable to load schema from 'https://json.schemastore.org/tsconfig HOT 1
- `tsdoc-reference-unquoted-identifier` is incorrectly reported for certain identifiers
- [ Question ][ Playground ] Intended Behaviour? HOT 2
- eslint-plugin-tsdoc: Missing rule to check for absence of a TSDoc comment HOT 1
- ESLint flat configurations? HOT 1
- "extends": "@rushstack/heft-node-rig/profiles/default/config/jest.config.json"
- Can inherit doc also copy the TSDoc when I hover?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tsdoc.