-
Notifications
You must be signed in to change notification settings - Fork 9
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
Positioning of JSDoc comments #1
Comments
There is one more issue when dealing with classes: even when writing (note the fat arrow): #
###*
# @param {string} b
###
method2 : (b) =>
console.log b the output js results in constructor: ->
/**
* @param {string} b
*/
this.method2 = this.method2.bind(this);
... within the constructor, and within the class body: method2(b){
console.log(b)
} without any doc. So b is still treated as any ;( |
@robert-boulanger nice catch! but is there any real reason to use fat arrows for class method definition? |
A real world scenario would be (and is) if an instance of such a class is for example, pushed into an reactive array in Vue3. |
I tried to reproduce what you just described: but I cannot see the class instance's Another Vue-related issue I could think of would be a Vue 2 (old-school options api style) component, in which the Vue this gets lost inside the method: here, In any case, I don't think the JSDoc comment block positioning issue for fat arrow methods can be reasonably fixed in extension code :-/ But it should be with the above linked CoffeeScript issue. I'll add a comment there |
@phil294: It is indeed an options api but already Vue3. |
Since the positioning of block comments was why this revert happened 0a147d1 and it seems block comments are incorrectly positioned anyway... would it make sense to restore this? It seems like it would fix a lot of my TypeScript issues and the 'empty comment' hack still works with it. |
@STRd6 edemaine's branch, which was in use for a short period before being reverted again as you noticed, while fixing non-block-commented lines, it still translates the following #
###* @type {abc} ###
a = 1
a = '1'
b = 2 into /** @type {abc} */
var a, b;
a = 1;
a = '1';
b = 2; which is of course bananas, so it can't be used (yet) and the lsp still uses the baked in workaround which translates into /** @type {abc} */
let a = 1;
a = '1';
let b = 2; as expected. (debug with VSCode command So yes, the comment blocks are always broken without the leading empty comment hack Hope I understood you correctly. I guess both logics could be combined too, if it's worth the effort. I'd be interested in seeing your concrete TS issues for that that you are seeing because of the current state of the extension, if you are willing to share? |
I see what you mean... It looks like without block comments edemaine's branch works great with destructuring but doesn't work with block comments. {sep} = require "path"
->
sep // Current implementation
var sep
({sep} = require("path"));
(function() {
return sep; // Later reference inside of a function causes TypeScript to be unable to infer type.
}); // edemaine's branch
var {sep} = require("path"); // TypeScript can figure this out automatically
(function() {
return sep;
}); I tried compiling with the block comments in various places and found that destructuring and block comments really don't get along either. For the example you gave here is what I got when running edemaine's branch: /** @type {abc} */
var a;
a = 1;
a = '1';
var b = 2; It seems almost reasonable but splitting the assignment onto a separate line isn't great. I'll try and get a local dev version of CoffeeSense running with the CoffeeScript branch and see what happens. |
Time to work on my branch again I guess... Sorry, this fell off my radar for a while and it's taking a while to get back to. |
now both logics combined, looks like it works fine. ref #1 reverts a bit of 0a147d which had reverted c71f45
I now did that and it seems to work fine. Idk why I didn't do this from the start. @STRd6 your .. as long as you do the |
@phil294 I've been trying out v1.10.0 and it's very good so far! I think most of the remaining issues have to be fixed in Thank you for your work! |
Adding some links to CoffeeScript issues for reference: jashkenas/coffeescript#5417 Someday I may build up the courage to tackle these in a CoffeeScript PR. |
prefer ``###* ... ### syntax to #\n###* ... ### ref #1
That alternative syntax from the tests is nice, thank you! ``###* ... ### I'm wondering if there's value in adding a vscode command to insert a coffeesense / coffescript jsdoc comment stub. I keep forgetting the correct syntax and always come back to this github issue to remember. EDIT: Just realized that |
@surjikal I think it depends on where you use a comment block - sometimes I haven't found a one-fits-all solution yet unfortunately (both in front of variables and object properties), which is why the extension can't do it for you. But maybe there is. If you have found one and worked with it for a while and it works reliably, please let me know! Else we'll just have to wait for someone to tackle the CoffeeScript compiler enhancements. |
As things have gotten stale around here, I have had another look into this from the extension's point of view and fixed it there now. CoffeeSense now automatically transforms all of your ### something ### into #
### something ### , also multi-line comment blocks, so you don't have to do that or the I wanted to avoid doing this as adding lines led to me having to adjust source maps awkwardly and everything was more prone to errors. Luckily, the large amount of tests helped to iron it all out. On a related note (since we're on issue #1 here :-), I think this extension is now reasonably complete, so I will adjust the Readme a bit to reflect that - at least personally I don't plan on adding any more features. |
Thanks for the hard work, it's a really great extension! |
Hm.. for some reason, the ###*
@typedef {foo} bar
### has stopped working recently. Using the backticks make it work though: ``###*
@typedef {foo} bar
### Looking at the compiled source produced by coffeesense, without the backticks, the comments are being stripped out. I'll post back here if I find a workaround. |
As commented here, block comments are often not where you'd expect them. Please read the specific issue for details. However, it refers to the official CoffeeScript compiler output.
In CoffeeSense, the input is somewhat modified, which is why in the linked case, the following would be enough for in-IDE type hints:
Note the extra
#
on top of the blocks. In many cases, you can also write``###* ... ###
which is even shorter but fails compilation inside objectsThis is treated by tsserver as
Maybe there are better ways of achieving proper block comment positioning? Or even better, something like the extra
#
should be inserted automatically so the user does not have to care about it anymore. This is somewhat annoying as it requires rewriting source maps (similar to how variable declaration rewriting already works), but it's possible.I want more feedback from smart people on this, so until then, this stays as is
The text was updated successfully, but these errors were encountered: