question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Include Default Parameter Values in Signature Help

See original GitHub issue

From https://github.com/Microsoft/vscode/issues/28925

TypeScript Version: 2.4.0

Feature Request signatureHelp current shows when a parameter is optional but does not include any information about that parameter’s default value:

function foo(x = 10) { }
foo(|)

Result of TSServer signatureHelp on foo

[Trace  - 5:42:22 PM] Response received: signatureHelp (378). Request took 20 ms. Success: true 
Result: {
    "items": [
        {
            "isVariadic": false,
            "prefixDisplayParts": [
                {
                    "text": "foo",
                    "kind": "functionName"
                },
                {
                    "text": "(",
                    "kind": "punctuation"
                }
            ],
            "suffixDisplayParts": [
                {
                    "text": ")",
                    "kind": "punctuation"
                },
                {
                    "text": ":",
                    "kind": "punctuation"
                },
                {
                    "text": " ",
                    "kind": "space"
                },
                {
                    "text": "void",
                    "kind": "keyword"
                }
            ],
            "separatorDisplayParts": [
                {
                    "text": ",",
                    "kind": "punctuation"
                },
                {
                    "text": " ",
                    "kind": "space"
                }
            ],
            "parameters": [
                {
                    "name": "x",
                    "documentation": [],
                    "displayParts": [
                        {
                            "text": "x",
                            "kind": "parameterName"
                        },
                        {
                            "text": "?",
                            "kind": "punctuation"
                        },
                        {
                            "text": ":",
                            "kind": "punctuation"
                        },
                        {
                            "text": " ",
                            "kind": "space"
                        },
                        {
                            "text": "number",
                            "kind": "keyword"
                        }
                    ],
                    "isOptional": true
                }
            ],
            "documentation": [],
            "tags": []
        }
    ],
    "applicableSpan": {
        "start": {
            "line": 3,
            "offset": 5
        },
        "end": {
            "line": 3,
            "offset": 5
        }
    },
    "selectedItemIndex": 0,
    "argumentIndex": 0,
    "argumentCount": 0
}

When the default value is a simple literal type, it would be helpful to display this default value in the signature help. This information could be included in the displayParts response

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:96
  • Comments:29 (6 by maintainers)

github_iconTop GitHub Comments

13reactions
alystaircommented, Mar 24, 2020

Also applicable to JS, not just TS

10reactions
DavidBradburycommented, Jan 6, 2022

I understand the desire to make this feature ‘smart’, but I think over-engineering is delaying this from getting done. In the JSDoc spec, it suggests a few examples and all you have to do is show what is literally defined in the optional parameter as text, not interpret arguments as given by the function.

Or if it is desired to show default values based on the function itself, and not JSDoc comment, this should be split into two issues instead of merging all the JSDoc related issues into this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

scala - Method signature for a function with default values
In Scala, is there a way to specify that a function should have default parameter values declared? For example, in the code below,...
Read more >
CoC with method whose signature includes default values
Methods that have default parameters can be wrapped by extension classes. However, the method signature in the wrapper method must not include the...
Read more >
Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >
Default arguments - cppreference.com
have a default argument supplied in this or a previous declaration ... int); // Error: only the trailing arguments can have default values...
Read more >
C#: Method overrides should not change parameter defaults
* Use the default parameter value defined in the overridden method. * Remove the default parameter value to match the signature of overridden...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found