-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[IntelliSense] [Salsa] Support @callback in JSDoc #7515
Comments
From @anseki on March 15, 2016 5:6 Hi @santiagohdzb, |
Moving to TypeScript for investigation. |
I'm having the same problem with JSCode. Any workaround? |
We have recently added support for JSDOC @typedef. if you are using the nightly build, you can replace the pattern above with: /**
* @typedef {function(number)} addedCallback
*/
/**
*@param {addedCallback} a
*/
var add = function (a) {
} |
@mhegazy is there a way to do this with TypeScript v1.8.10? Or only for the next release of TypeScript 2.0? Thanks. |
@sant123 support for |
Thank you @zhengbli 😄 |
Any progress on this? |
+1 |
+1
The real use of |
Hate to be that person, but it's been 3 months since the last comment on this issue. Any updates, blocking issues? Is it backlogged, perhaps? |
it is on our Future milestone. so no specific release has been marked. would be happy to take a PR for it anytime though. |
@mhegazy How to name arg0, arg1 for |
EDIT: Ignore what I wrote here, @mhegazy showed a much simpler method below. EDIT2: maybe not quite ignore what I wrote here, it has a slightly different trade-off than the other method. @iugo: It's a bit crude, but as long as you use a bundler like WebPack, which can do dead code elimination, you shouldn't have to worry about those dummy functions it ending up in your production code. Here's more elaborate example, extracted fron a bigger code snippet: /**
* A compare function to pass to `indices.sort()`, see also:
* [`TypedArray.prototype.sort()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/sort).
*
* @param {number} i
* @param {number} j
*/
function indexCompareFunction(i, j) {
// dummy function for missing VSCode JSDoc callback support
return i - j;
}
// Explicit
/**
* Creates a compare function to sort a _separate_ array
* of indices, based on lexicographical ordering of
* the array values. Produces a stable sort.
* @param {*[]} array
* @returns {indexCompareFunction}
*/
function baseCompareFunc(array) {
return (i, j) => {
let vi = array[i],
vj = array[j];
return vi < vj ?
-1 : vi > vj ?
1 : i - j;
};
}
// Inferred from callback JSDoc
/**
* @param {*[]} array
*/
function baseCompareFunc2(array) {
// Must store the function in a variable,
// otherwise JSDoc does nothing!
/**
* @param {number} i
* @param {number} j
*/
let compareFunc = (i, j) => {
let vi = array[i],
vj = array[j];
return vi < vj ?
-1 : vi > vj ?
1 : i - j;
};
return compareFunc;
} |
@JobLeonard this is not accurate. you can do this today using /**
* Creates a compare function to sort a _separate_ array
* of indices, based on lexicographical ordering of
* the array values. Produces a stable sort.
* @param {*[]} array
* @returns {function(number, number): number}
*/
function baseCompareFunc(array) {
return (i, j) => {
let vi = array[i],
vj = array[j];
return vi < vj ?
-1 : vi > vj ?
1 : i - j;
};
}
|
@mhegazy: I actually missed this option, so thanks! However, the question was:
I don't see any other way to get named arguments in there at the moment, other than creating a dummy function. (EDIT: Yes I'm using three-spaces indented tabs. I regret nothing) |
Wow, nice! That |
inside |
Ah, so it's technically not valid JSDoc syntax, and this will only work in VSCode? I mean, that's perfectly fine by me, but it might be important to some. |
yes. it is not standard JSDoc (thought is very hard to define what is a "standard" in JSDoc). We still have this issue open to support the |
I too could really use the native JSDoc |
Hi, this is still a problem in 1.21.0-insiders. |
At least when I needed to find out how to define a callback in jsdoc, the path to doing it was very well laid out and @callback was the top result for "how to document callbacks in jsdoc". I'm not sure how more 'standard' it needs to be considered when usejsdoc.org lays out what @callback is and how it works - and is the top result in google searches. I think it'd be reasonable to assume @callback should work the way usejsdoc.org defines it. @typedef is a poor substitute with no way to define argument names properly. I can either do it the way google is saying others do it and leave people using my code in VSCode high and dry, or incompletely document it the way VSCode allows and leave nothing for those using an IDE with more complete JSDoc support. Neither seems like a happy solution to me. The purpose of good portable documentation is lost if only part of jsdoc is implemented. This issue has existed for 2 years now, how much longer is it going to take to support SOME kind of callback documentation in VSCode? Callbacks are a major part of JS AND TypeScript - not being able to have documentation half as good as you get in another IDE is silly at this point. Even more silly when VSCode is meant to be the defacto IDE for languages like TypeScript. VSCode could come out with it's own special @VSCodeCallback if need be - as long as there's something, I could then define the callback twice - vscode's way, and the way everyone else does it - and no one is left with incomplete documentation about my callbacks then. |
@DanielRosenwasser @mhegazy this would be pretty nice for us also since we are incredibly callback heavy. |
Fix is up at #23947 |
From @santiagohdzb on March 15, 2016 3:43
Hi everyone, I'm in love with the new VS Code's Salsa, but I'm facing this issue:
I'm trying to use InselliSense with JSDoc's callback documentation.
Am I doing something wrong? How am I supposed to do this?
Steps to Reproduce:
1. Open a new Javascript file
2. add the code you see above
Copied from original issue: microsoft/vscode#4223
The text was updated successfully, but these errors were encountered: