Skip to content
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

Hover information over export default #2736

Closed
basarat opened this issue Apr 12, 2015 · 13 comments
Closed

Hover information over export default #2736

basarat opened this issue Apr 12, 2015 · 13 comments
Labels
Fixed A PR has been merged for this issue Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@basarat
Copy link
Contributor

basarat commented Apr 12, 2015

If you have a file with the following contents:

export default function(a: string, b: number) {
  return Promise.resolve(a + b);
}

Then there is no way to see function signature through hovering. Basically, because it has no name? It would be nice to get the hover information over the export or default keyword :-)

Original request : TypeStrong/atom-typescript#251

@mhegazy
Copy link
Contributor

mhegazy commented Apr 13, 2015

why not function? that would help with function expressions as well..

@mhegazy mhegazy added the Help Wanted You can do this label Apr 13, 2015
@basarat
Copy link
Contributor Author

basarat commented Apr 13, 2015

Cool. It was just a copy paste. "function" would be best ❤️

@tinganho
Copy link
Contributor

I began on working on this. Shouldn't it be all reserved words related to a declaration?

@DanielRosenwasser
Copy link
Member

@tinganho I'm not entirely sure; if we do this, then anonymous class expressions certainly should get the same behavior for class.

@tinganho
Copy link
Contributor

@DanielRosenwasser with the exception of declarations lists with a length bigger than 1.

/*1*/var a: string = 1, b: string; // doens't get hover info on marker 1

@DanielRosenwasser
Copy link
Member

So we should clarify what we want to see; if we're just going to show the word function, then this sounds very unhelpful.

If, however, we're going to show type information for a contextually typed function expression, that might be very useful.

For instance:

declare f(g: (x: number) => number);

f(/**/function (x) {
});

Quick info at that position should show something like

(local function) (x: number): number;

I'm not really big on how it looks, but it'd be worth discussing a bit.

Similarly, for the class keyword, I think it depends on whether or not a constructor function can be contextually typed.

@tinganho
Copy link
Contributor

@DanielRosenwasser just another clarification. Should the export default etc. keywords have the same quick info as the related declaration?

Quick info at that position should show something like

Don't you think it should be:

function (x: number): number;

because the current non-anonymous is:

function A(x: number): number;

@DanielRosenwasser
Copy link
Member

because the current non-anonymous is:

function A(x: number): number;

It depends on what you mean by non-anonymous:

image

image

I think the latter is inconsistent and something we should probably fix.

@tinganho
Copy link
Contributor

@DanielRosenwasser I have practically finished this issue but before I send a PR. There are some weird namings currently in the language service.

/// <reference path='fourslash.ts' />

//// interface IFunction{
////     (g: (a: string, b: string) => void): any;
//// }
////
//// declare var f: IFunction;
////
//// f(/*contextualType*/function(a, b) { });
////
//// /*namedFunction*/function functionName1() {}
////
//// /*exportAnonymousFunction*/export /*defaultAnonymousFunction*/default /*anonymousFunction*/function(a: string, b: string) {}

goTo.marker("contextualType");
verify.quickInfoIs("(local function) __function(a: string, b: string): void");

goTo.marker("namedFunction");
verify.quickInfoIs("function functionName1(): void");

goTo.marker("exportAnonymousFunction");
verify.quickInfoIs("function default(a: string, b: string): void");

goTo.marker("defaultAnonymousFunction");
verify.quickInfoIs("function default(a: string, b: string): void");

goTo.marker("anonymousFunction");
verify.quickInfoIs("function default(a: string, b: string): void");

@DanielRosenwasser
Copy link
Member

I need someone to wear their end-user hat and help decide what is best to show in these cases (@RyanCavanaugh @danquirk). Clearly we should not be showing the symbol name for an anonymous function. I think that default is not correct either.

We keep running into situations where we resolve the symbol as default in the language service whereas what we really want is the local symbol. @ahejlsberg what's the best way to go about fixing this?

@CyrusNajmabadi
Copy link
Contributor

Seeing a dunder name (i.e. __function) is never going to be appropriate for the user. We should present the item to the user, as they wrote it. i.e. as either function(...) or default function(...).

Also, as an aside, i see no purpose in labeling something a local function.

@tinganho
Copy link
Contributor

function(...) or default function(...)

I vote for just function(...). I see the default as a modifier to the export keyword not the function.

How about just keeping it simple?

function Name(...) {}
function(...) {}

@DanielRosenwasser
Copy link
Member

How about just keeping it simple?

function Name(...) {}
function(...) {}

👍

@mhegazy mhegazy assigned ghost Nov 1, 2017
@ghost ghost closed this as completed in #19669 Nov 2, 2017
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Nov 2, 2017
@mhegazy mhegazy added this to the TypeScript 2.7 milestone Nov 2, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants