Skip to content

Expand inline hints to type-locations#48422

Merged
CyrusNajmabadi merged 35 commits intodotnet:masterfrom
CyrusNajmabadi:inlineVar
Oct 12, 2020
Merged

Expand inline hints to type-locations#48422
CyrusNajmabadi merged 35 commits intodotnet:masterfrom
CyrusNajmabadi:inlineVar

Conversation

@CyrusNajmabadi
Copy link
Contributor

@CyrusNajmabadi CyrusNajmabadi commented Oct 8, 2020

New Options:

image

(the last three options are new).

These showup as:

image

With #48411 these can be off by default and lightup when holding ctrl-alt.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner October 8, 2020 00:27
@CyrusNajmabadi CyrusNajmabadi requested a review from a team October 8, 2020 00:27
@davidwengier
Copy link
Member

davidwengier commented Oct 8, 2020

int shouldn't show here, right?
image

@CyrusNajmabadi
Copy link
Contributor Author

int shouldn't show here, right?

It should not. Will fix :)

// No need to do anything if we're already in the requested state
var state = workspace.Options.GetOption(InlineHintsOptions.DisplayAllOverride);
var state = _globalOptionService.GetOption(InlineHintsOptions.DisplayAllOverride);
if (state == on)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this if you don't agree, but to me this reads confusingly. desiredState instead of on maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works for me :-)

@CyrusNajmabadi
Copy link
Contributor Author

@davidwengier ptal if you have time :)

this.BackgroundBrush = Brushes.LightGray;
this.DisplayName = EditorFeaturesResources.Inline_Hints;
this.ForegroundBrush = new SolidColorBrush(Color.FromRgb(104, 104, 104));
this.BackgroundBrush = new SolidColorBrush(Color.FromRgb(230, 230, 230));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these match the values we have in the xml files. This means that we get these as the defaults no matter what.

private readonly ITextView _textView;
private readonly SnapshotSpan _span;
private readonly SymbolKey _key;
private readonly SymbolKey? _key;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes away in #48479 when i update this UI code to not be C#/VB specific.


public async Task<IReadOnlyCollection<object>> CreateDescriptionAsync(CancellationToken cancellationToken)
{
var document = _textView.TextBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method added a null check and changed indentation. it's otherwise unchanged.

Copy link
Member

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems GitHub doesn't do a good job when "changes since last review" includes merge commits ¯\_(ツ)_/¯

@CyrusNajmabadi CyrusNajmabadi merged commit f9872f1 into dotnet:master Oct 12, 2020
@ghost ghost added this to the Next milestone Oct 12, 2020
@CyrusNajmabadi CyrusNajmabadi deleted the inlineVar branch October 12, 2020 00:41
@AdmiralSnyder
Copy link
Contributor

hey, would you consider adding an option to show the inline type hints for var and lambdas above the code line (like my extension does) so the line doesn't become illegible when having long generic names?

@CyrusNajmabadi
Copy link
Contributor Author

@AdmiralSnyder can you point me to how you do this. I can try it out. I'm worried about two things:

  1. i don't like adornments that change line height (as it makes the lines seem very inconsistently spaced out).
  2. i think tehse would have to be very short to not interfere too much. i think that could be very hard to read.

that said, since this is suggesting an option to have that be the view, i think that that might be acceptable since it was all opt in.

@AdmiralSnyder
Copy link
Contributor

AdmiralSnyder commented Oct 12, 2020

@CyrusNajmabadi i create SpaceNegotiatingAdornmentTags above the var lines. my project is on azure devops (and nonpublic) so i cannot directly point you towards it.
basically, in my Tagger, i do

var node = RoslynUtils.GetNodeAtSpan(root, span, index);
if (RoslynUtils.IsVarSyntaxNode(node))
{
  yield return new TagSpan<VarLineTag>(new SnapshotSpan(span.Snapshot.TextBuffer.CurrentSnapshot, span), new VarLineTag(0, options.Size * 1.1, 0, 0, 0, PositionAffinity.Predecessor, null, null));
  break; // max. one per line
}
` 
where the VarLineTag is just a SpaceNegotiatingAdornmentTag descendant.
I create one tag per line.
and then i create multiple adornments in the tag's space.
i attach to the LayoutChanged event of the View, then iterate the visible lines and the `var` in the lines., i then get the roslyn node at the position, check whether it's a `var` node, and draw the adornment

if you wanna have a look at the (probably embarrassing :-) ) source, i can invite you to the azure devops project or create a copy in github and invite you there. or i can paste stuff that might be interesting into a gist... just tell me :-)

@Cosifne Cosifne modified the milestones: Next, 16.9.P1 Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants