Skip to content

Better IntelliSense for TypeScript/JavaScript #8525

@dbaeumer

Description

@dbaeumer

From @donaldpipowitch on May 4, 2016 6:16

  • VSCode Version: 1.0.0
  • OS Version: OS X 10.11.4

I think IntelliSense could show more documentation than it currently does. Take the following example (concrete feature requests are marked with a leading "❤️"):

/**
 * Add numbers!
 * @param a First number.
 * @param b Second number.
 */
function add(a: number, b: number): number {
  return a + b;
}

/**
 * This is a.
 */
const a = 1;

const c = add(a, 2);

/**
 * This is some object.
 */
interface SomeObject {
  /**
   * This is foo.
   */
  foo: string;
  /**
   * This is bar.
   */
  bar: string;
}

/*
 * This is an instance of some object.
 */
const someObject: SomeObject = {
  /**
   * Test.
   */
  foo: 'foo',
  bar: 'bar'
};

const foo2 = someObject.foo;

And now let us step through each statement and look if it could be improved.

1. Function signature

function add(a: number, b: number): number {
  • Hovering over add shows Add numbers!.
  • Hovering over a shows First number..
  • Hovering over b shows Second number..

Great. Everything works 👍

2. Function body

  return a + b;
  • Hovering over a shows First number..
  • Hovering over b shows Second number..

Great. Everything works 👍

3. Variable declaration

const a = 1;
  • Hovering over a shows This is a..

Great. Everything works 👍

4. Function call

const c = add(a, 2);
  • Hovering over c shows nothing.
    • This is expected. We have no description like for const a.
    • ❓ However... it doesn't seem we can document return values from a function call properly. Adding * @return This is the sum. to the function add documentation shows the return annotation as part of the description. But it would be nice, if hovering over c would show This is the sum. instead.
    • If we'd add a description to const c like we did for const a (e.g. This is c.) and we add a proper @return annotation to function add it would be nice if IntelliSense would show both description when hovering over c: This is c. and This is the sum. (maybe with a small visual delimiter between both descriptions.).
  • Hovering over add shows Add numbers!.
  • Hovering over a shows This is a..
    • It would be nice, if it would also show First number..
  • Hovering over 2 shows nothing.
    • It would be nice, if it would show Second number..

❤️ Request 1: It would be nice to show @return annotations correctly in IntelliSense.
❤️ Request 2: It would be nice to additionally show @param and @return annotations alongside with descriptions of variable declarations or at least as a fallback, if a variable has no own description.

5. Interface

interface SomeObject {
  • Hovering over SomeObject shows This is some object..

Great. Everything works 👍

6. Property in interface

  foo: string;
  • Hovering over foo shows This is foo..

Great. Everything works 👍

7. Object with interface

const someObject: SomeObject = {
  • Hovering over someObject shows nothing.
    • I'd expect to see This is an instance of some object..
  • Hovering over SomeObject shows This is some object..

❤️ Request 3: It would be nice to show the description of an object using an interface.

8. Properties of an object with interface

  foo: 'foo',
  bar: 'bar'
  • Hovering over foo shows Test..
    • It could also show This is foo..
  • Hovering over bar shows nothing.
    • It could at least show This is bar..

❤️ Request 4: It would be nice to additionally show property descriptions from an interface and descriptions of properties in a concrete object or at least as a fallback, if the property of an object has no own description.

9. Using properties of an object with interface

const foo2 = someObject.foo;
  • Hovering over foo shows This is foo..
    • It could also show Test.. (💡 This was very surprising for me that IntelliSense used This is foo. instead of Test. here. However... best thing would be to show both.)
  • Hovering over foo2 shows nothing.
    • It looks like the the type is correctly inferred and it would be nice if the descriptions could be reused here, too. (E.g. Test. and This is foo.)
  • Hovering over someObject shows nothing.
    • It should show This is an instance of some object. (and could additionally show This is some object.).

❤️ Request 5: When using properties of an object which are documented in the object itself and in the interface it would be nice if the description from the object declaration could be shown (because it is probably more custom to the current use case) or show both descriptions.
❤️ Request 6: When types can be inferred it would be nice to infer descriptions, too.

Copied from original issue: microsoft/vscode#6083

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: APIRelates to the public API for TypeScriptOut of ScopeThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScriptVS Code TrackedThere is a VS Code equivalent to this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions