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.

Show inferred types as inline code

See original GitHub issue

I’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): Screen Shot 2022-09-09 at 11 13 57 AM

: &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:closed
  • Created a year ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
DanTupcommented, Sep 13, 2022

The only question I have is if we should show var int x1.

I think ideally we should replace var with int, but we’re not able to do that. LSP only allows us to provide a Position and not a Range. 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.

2reactions
DanTupcommented, Sep 13, 2022

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:

Screenshot 2022-09-13 at 11 19 12

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.

Read more comments on GitHub >

github_iconTop 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 >

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