Skip to content

Commit

Permalink
Fixed dropdown load
Browse files Browse the repository at this point in the history
[release]
  • Loading branch information
madskristensen committed Jan 11, 2022
1 parent a4bacef commit 8144a48
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
40 changes: 24 additions & 16 deletions src/RestClientVS/Editor/DropdownBars.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections;
using System.Linq;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Package;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
Expand All @@ -20,16 +19,23 @@ public DropdownBars(IVsTextView textView, LanguageService languageService)
: base(languageService)
{
_languageService = languageService;

IVsEditorAdaptersFactoryService adapter = VS.GetMefService<IVsEditorAdaptersFactoryService>();

_textView = adapter.GetWpfTextView(textView);
_textView.Caret.PositionChanged += CaretPositionChanged;

_textView = textView.ToIWpfTextView();
_document = _textView.TextBuffer.GetRestDocument();
_document.Parsed += OnDocumentParsed;

SynchronizeDropdowns();
InitializeAsync(textView).FireAndForget();
}

// This moves the caret to trigger initial drop down load
private Task InitializeAsync(IVsTextView textView)
{
return ThreadHelper.JoinableTaskFactory.StartOnIdle(() =>
{
textView.SendExplicitFocus();
_textView.Caret.MoveToNextCaretPosition();
_textView.Caret.PositionChanged += CaretPositionChanged;
_textView.Caret.MoveToPreviousCaretPosition();
}).Task;
}

private void OnDocumentParsed(object sender, EventArgs e)
Expand All @@ -42,18 +48,20 @@ private void OnDocumentParsed(object sender, EventArgs e)

private void SynchronizeDropdowns()
{
if (_document.IsParsing)
if (!_document.IsParsing)
{
_languageService.SynchronizeDropdowns();

return;
}

_ = ThreadHelper.JoinableTaskFactory.StartOnIdle(() =>
{
if (!_document.IsParsing)
{
_languageService.SynchronizeDropdowns();
}
}, VsTaskRunContext.UIThreadIdlePriority);
//_ = ThreadHelper.JoinableTaskFactory.StartOnIdle(() =>
//{
// if (!_document.IsParsing)
// {
// _languageService.SynchronizeDropdowns();
// }
//}, VsTaskRunContext.UIThreadBackgroundPriority);
}

public override bool OnSynchronizeDropdowns(LanguageService languageService, IVsTextView textView, int line, int col, ArrayList dropDownTypes, ArrayList dropDownMembers, ref int selectedType, ref int selectedMember)
Expand Down
2 changes: 1 addition & 1 deletion src/RestClientVS/RestClientVS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Community.VisualStudio.VSCT" Version="16.0.29.6" PrivateAssets="all" />
<PackageReference Include="Community.VisualStudio.Toolkit.17" Version="17.0.384" ExcludeAssets="Runtime">
<PackageReference Include="Community.VisualStudio.Toolkit.17" Version="17.0.385" ExcludeAssets="Runtime">
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Threading">
Expand Down

0 comments on commit 8144a48

Please sign in to comment.