-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fullDocs option for doc_comment #425
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,14 @@ | |
})(function(infer, tern, comment, acorn, walk) { | ||
"use strict"; | ||
|
||
tern.registerPlugin("doc_comment", function(server) { | ||
var fullDocs=false; | ||
|
||
tern.registerPlugin("doc_comment", function(server, options) { | ||
server.jsdocTypedefs = Object.create(null); | ||
server.on("reset", function() { | ||
server.jsdocTypedefs = Object.create(null); | ||
}); | ||
fullDocs = options && options.fullDocs; | ||
|
||
return { | ||
passes: { | ||
|
@@ -93,11 +96,17 @@ | |
type = null; | ||
} | ||
|
||
var first = comments[0], dot = first.search(/\.\s/); | ||
if (dot > 5) first = first.slice(0, dot + 1); | ||
first = first.trim().replace(/\s*\n\s*\*\s*|\s{1,}/g, " "); | ||
if (aval instanceof infer.AVal) aval.doc = first; | ||
if (type) type.doc = first; | ||
var result = comments[comments.length - 1]; | ||
if (fullDocs) result = result.trim().replace(/\n {0,}\* {0,}/g, "\n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This removes all asterisks that are part of the JSDoc structure except the first one (which is removed later). This is important as it keeps asterisks that are part of the documentation; example of asterisk in documentation:
This also preserves the newlines inside of the comments. |
||
else{ | ||
var dot = result.search(/\.\s/); | ||
if (dot > 5) result = result.slice(0, dot + 1); | ||
result = result.trim().replace(/\s*\n\s*\*\s*|\s{1,}/g, " "); | ||
} | ||
result = result.replace(/^\s{0,}\*{1,}\s{0,}/, ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this tern likes to return comments that start with an asterisk which also doesn't make sense. This fix applies to both fullDocs and the first sentence doc mode. Example: /** test comments */
function test(){} Without this fix (current state of tern) the resulting comment is |
||
|
||
if (aval instanceof infer.AVal) aval.doc = result; | ||
if (type) type.doc = result; | ||
} | ||
|
||
// Parses a subset of JSDoc-style comments in order to include the | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an issue I've always had with tern but I thought it would be a difficult fix because I never looked at the code. Now that I looked at the code I realized how simple it is to fix this!
Example:
Why would it ever make sense to display the first comment when there are more than one? I have a lot of code similar to above and I end up with
section header
as my documentation for functiontest
inside of tern. It makes sense to display the last comment (Unless there is a use case I'm not aware of).