-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Inline syntax #2098
Comments
I personally would like that a lot. I use JSDoc, so I don't have to setup TypeScript for a few places knowing the type, so this would be create to not flood the code file with very big comment sections all the time :) |
Yeah, that's the idea :-) |
Would it be possible to create a VS Code extension as a "middleware" for |
I don't fully understand what do you want to achieve, but Javascript with comments is still just Typescript valid code (sort of... there are some corner cases where not due to types safety, but in theory it is), so there's no need to do anything. There are some tools to translate JsDoc to Typescript |
Internally TS Language Server is always running, that's why JSDoc comments will produce types on the variables when you hover them. If there was an extension (as middleware that will strip the comment character so So like:
// Not real code but something like this
function detectType(document, line, next) {
if (document.type == 'javascript') {
line = stripCommentsSomehowIfTypeScriptLike(line);
}
next(document, line);
} 3: TS Language Server will see: let x :string = 'Hello!'; No buildstep required and having only I hope it makes more sense now. Still I don't know if this would be possible. |
I think it could be possible, but as I said, I would do a CLI tool first, and later check into de VSCode extension. VSCode is open source, so it could be possible to see in the TS Language Server code to see how it works and create a new one based on it, or create a new extension that wraps the original one. |
Oh okay sorry! I thought that you talked about something else. So what exactly would the cli tool do? I hope JSDoc will implement it in this way but I don't think this will happen soon, unfortunately. |
I mean a CLI tool since it's the most simple and versatile way to make it works, instead of jump directly in a VSCode extension: a CLI tool can be used standalone, without needing to have VSCode at all. It doesn't need to be a new CLI tool, not sure if
Or we can do it ourselves ;-) |
Based on https://jsdoc.app/about-plugins, it could be possible to create a plugin that reads low-level AST looking for comments after the actual symbol being documented, and add the information to the actual emitted docstring. Thing is, we would also need to disable first the docsting event so we can emit it later, but I think it's feasable, and also plugins can be used later with |
As suggested at tc39/proposal-type-annotations#202 (comment), I have a proposal for a minimal inline syntax for types. The idea is to consider any comment where the first token is a JsDoc token (without the
@
) as a JsDoc comment, and also being in that case the:
an alias to@type
, so it's possible to have an inline syntax with a readibility similar to Typescript or flow. That would make JsDoc expresiveness more alike to https://tsdoc.org/, where there's no need to be so much verbose because most of the information is get from Typescript keywords (in that case, the inline comments):The text was updated successfully, but these errors were encountered: