phil294 / coffeesense

IntelliSense for CoffeeScript. LSP implementation / VSCode extension
MIT License
47 stars 8 forks source link

type association on hover lacks in constructor #6

Closed robert-boulanger closed 2 years ago

robert-boulanger commented 2 years ago

Given the following class:

class ClassTest2
  ###*
   * @constructor
   * @param {string} A
   * @param {number} B
   * @param {object} C
   ###
  constructor: (A,B,C)->
    @myA = A
    this.myB = B
    @myC = C
    @test="Hello cruel world"
    test="Is there anybody out there"
    this.test2="defintly the end"

  ###*
   * @param {number} a
   * @return {*}
  ###
  method1:(a)->
    m=a
    x=1
    y=2
    return y

  method2:(b)->
    x=1
    y=2
    return y

pointing the mouse over @myA in constructor : @myA is shown as any => incorrect pointing the mouse over A (right from equal sign) in constructor : A is shown as string => correct pointing the mouse over this.myB in constructor : this.myB is shown as any => incorrect pointing the mouse over B (right from equal sign) in constructor : B is shown as number => correct pointing the mouse over @myC in constructor : @myC is shown as any => seems to be correct, since C is an object pointing the mouse over C (right from equal sign) in constructor : C is shown as number => seems to be correct, since C is an object pointing the mouse over @test in constructor : @test is shown as any => incorrect pointing the mouse over test in constructor : test is shown as string => correct pointing the mouse over this.test2 in constructor : this.test2 is shown as any => incorrect

pointing the mouse over var m in method1 : m is shown as number => correct pointing the mouse over var x in method1 : x is shown as number => correct pointing the mouse over var y in method1 : y is shown as number => correct

pointing the mouse over var x in method2 : x is shown as number => correct pointing the mouse over var y in method2 : y is shown as number => correct pointing the mouse over methodname method2 : return is shown as number => correct

robert-boulanger commented 2 years ago

Addendum:

Anyhow, when in an other class or module (even if it is in a different file)

ClassTest.test2 (the string) is assigned to a var which was a number before, the error is shown correctly.

example referencing the code block above

import {ClassTest2} from "..."

ct2 = new ClassTest2("tada",2,{})
x=0
x=ct2.test2

would cause an error in Coffeesense, which is correct

phil294 commented 2 years ago

pointing the mouse over @myA in constructor : @myA is shown as any => incorrect

It's correct, as this is also exactly what tsserver tells you in a JavaScript file: img It even kind of makes sense, as at that point in time, this.myA wasn't born yet And as long as

x = new ClassTest2 'a', 1, {}
x.myA # <-- cursor pos

correctly gives you accurate autocomplete info about myA being string, I think it's fine.

pointing the mouse over this.myB in constructor : this.myB is shown as any => incorrect pointing the mouse over @test in constructor : @test is shown as any => incorrect pointing the mouse over this.test2 in constructor : this.test2 is shown as any => incorrect

same thing as above

so I'd say everything works as expected

robert-boulanger commented 2 years ago

It even kind of makes sense, as at that point in time, this.myA wasn't born yet And as long as

´´´coffeescript x = new ClassTest2 'a', 1, {} x.myA # <-- cursor pos ´´´

correctly gives you accurate autocomplete info about myA being string, I think it's fine.

I agree, the important thing is, that the error is shown in the latter case and the autocomplete info is correct.