Show inferred types as inline code
See original GitHub issueI’ve been writing some Rust code and I’ve appreciated the inline declarations of inferred types. It makes reading and working with code much easier. This is apropos Dart where some repositories enforce the explicit declaration of types whereas others don’t.
Here is an example of the Rust extension showing inferred types (and parameter names but this issue isn’t asking for that):
: &Option<Rc<Node<i32>>>
is the inferred type of result
. It doesn’t exist in the file but it would be valid code had it been written there. The inline hint is itself valid code, which is important.
So in Dart’s case it would look like this:
final x = add(1, 2);
becomes:
final int x = add(1, 2);
Where int
doesn’t exist in the code but is displayed as above as if it was.
Issue Analytics
- State:
- Created a year ago
- Comments:15 (6 by maintainers)
Top Results From Across the Web
VS Code tips — Variable type inlay hints for JavaScript and ...
See the inferred type of variables directly inline in your #JavaScript and #ypeScript code with variable type inlay hints.
Read more >How to inline inferred types like vscode? : r/vim - Reddit
and it has it so that you can get the inferred type by pressing SHIFT+K which pops out an in-line window, but I...
Read more >vscode-inline-types - Visual Studio Marketplace
vscode-inline-types. A Visual Studio Code extension that will inline-render inferred types in TypeScript documents.
Read more >Inferred annotations | IntelliJ IDEA Documentation - JetBrains
Select the Inferred annotations checkbox. Apply the changes and close the dialog. Inferred annotation shown inline with the code.
Read more >How to get type hints to display? - visual studio code
You're looking for parameter hints in this case. The function for which you want to display hints also needs to have more than...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think ideally we should replace
var
withint
, but we’re not able to do that. LSP only allows us to provide aPosition
and not aRange
. I don’t think not being able to replace it should avoid us showing the type though (the purpose of this feature is to let the user see types that aren’t explicitly in the code), so I think this is all we have.I do generally think we should try to stick to “valid code” where possible though, just not at the expense of not including a type.
I thought we already had an issue for this, but can’t find it (perhaps remembering #3609 which is for parameter names).
Started on this, right now it’s just the labels:
But I’ve filed #4156 to see whether we can support showing the type dartdocs on mouseover too.
The change is in the analysis server so will ship as part of an SDK.