Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 28fc2f1

Browse files
Merge branch 'autocompletebox-implementation' into jcansdale/autocompletebox-theme
2 parents d0a7965 + 3d539c8 commit 28fc2f1

File tree

3 files changed

+36
-40
lines changed

3 files changed

+36
-40
lines changed

src/GitHub.Api/GraphQLClient.cs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using GitHub.Extensions;
11-
using Microsoft.VisualStudio.Threading;
1211
using Octokit.GraphQL;
1312
using Octokit.GraphQL.Core;
1413

@@ -28,12 +27,10 @@ public GraphQLClient(
2827
this.cache = cache;
2928
}
3029

31-
public async Task ClearCache(string regionName)
30+
public Task ClearCache(string regionName)
3231
{
3332
// Switch to background thread because FileCache does not provide an async API.
34-
await TaskScheduler.Default;
35-
36-
cache.ClearRegion(GetFullRegionName(regionName));
33+
return Task.Run(() => cache.ClearRegion(GetFullRegionName(regionName)));
3734
}
3835

3936
public Task<T> Run<T>(
@@ -131,28 +128,29 @@ public CachingWrapper(
131128

132129
public Uri Uri => owner.connection.Uri;
133130

134-
public async Task<string> Run(string query, CancellationToken cancellationToken = default)
131+
public Task<string> Run(string query, CancellationToken cancellationToken = default)
135132
{
136133
// Switch to background thread because FileCache does not provide an async API.
137-
await TaskScheduler.Default;
138-
139-
var hash = GetHash(query);
140-
141-
if (refresh)
134+
return Task.Run(async () =>
142135
{
143-
owner.cache.Remove(hash, regionName);
144-
}
136+
var hash = GetHash(query);
145137

146-
var data = (string)owner.cache.Get(hash, regionName);
138+
if (refresh)
139+
{
140+
owner.cache.Remove(hash, regionName);
141+
}
147142

148-
if (data != null)
149-
{
150-
return data;
151-
}
143+
var data = (string) owner.cache.Get(hash, regionName);
144+
145+
if (data != null)
146+
{
147+
return data;
148+
}
152149

153-
var result = await owner.connection.Run(query, cancellationToken);
154-
owner.cache.Add(hash, result, DateTimeOffset.Now + cacheDuration, regionName);
155-
return result;
150+
var result = await owner.connection.Run(query, cancellationToken);
151+
owner.cache.Add(hash, result, DateTimeOffset.Now + cacheDuration, regionName);
152+
return result;
153+
}, cancellationToken);
156154
}
157155
}
158156
}

src/GitHub.InlineReviews/Services/PullRequestSessionService.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ public async Task<string> GetGraphQLPullRequestId(
716716
string repositoryOwner,
717717
int number)
718718
{
719-
var address = HostAddress.Create(localRepository.CloneUrl.Host);
719+
var address = HostAddress.Create(localRepository.CloneUrl);
720720
var graphql = await graphqlFactory.CreateConnection(address);
721721

722722
var query = new Query()
@@ -775,7 +775,7 @@ public async Task<PullRequestDetailModel> CreatePendingReview(
775775
LocalRepositoryModel localRepository,
776776
string pullRequestId)
777777
{
778-
var address = HostAddress.Create(localRepository.CloneUrl.Host);
778+
var address = HostAddress.Create(localRepository.CloneUrl);
779779
var graphql = await graphqlFactory.CreateConnection(address);
780780
var (_, owner, number) = await CreatePendingReviewCore(localRepository, pullRequestId);
781781
var detail = await ReadPullRequestDetail(address, owner, localRepository.Name, number, true);
@@ -790,7 +790,7 @@ public async Task<PullRequestDetailModel> CancelPendingReview(
790790
LocalRepositoryModel localRepository,
791791
string reviewId)
792792
{
793-
var address = HostAddress.Create(localRepository.CloneUrl.Host);
793+
var address = HostAddress.Create(localRepository.CloneUrl);
794794
var graphql = await graphqlFactory.CreateConnection(address);
795795

796796
var delete = new DeletePullRequestReviewInput
@@ -818,7 +818,7 @@ public async Task<PullRequestDetailModel> PostReview(
818818
string body,
819819
PullRequestReviewEvent e)
820820
{
821-
var address = HostAddress.Create(localRepository.CloneUrl.Host);
821+
var address = HostAddress.Create(localRepository.CloneUrl);
822822
var graphql = await graphqlFactory.CreateConnection(address);
823823

824824
var addReview = new AddPullRequestReviewInput
@@ -848,7 +848,7 @@ public async Task<PullRequestDetailModel> SubmitPendingReview(
848848
string body,
849849
PullRequestReviewEvent e)
850850
{
851-
var address = HostAddress.Create(localRepository.CloneUrl.Host);
851+
var address = HostAddress.Create(localRepository.CloneUrl);
852852
var graphql = await graphqlFactory.CreateConnection(address);
853853

854854
var submit = new SubmitPullRequestReviewInput
@@ -880,7 +880,7 @@ public async Task<PullRequestDetailModel> PostPendingReviewComment(
880880
string path,
881881
int position)
882882
{
883-
var address = HostAddress.Create(localRepository.CloneUrl.Host);
883+
var address = HostAddress.Create(localRepository.CloneUrl);
884884
var graphql = await graphqlFactory.CreateConnection(address);
885885

886886
var comment = new AddPullRequestReviewCommentInput
@@ -912,7 +912,7 @@ public async Task<PullRequestDetailModel> PostPendingReviewCommentReply(
912912
string body,
913913
string inReplyTo)
914914
{
915-
var address = HostAddress.Create(localRepository.CloneUrl.Host);
915+
var address = HostAddress.Create(localRepository.CloneUrl);
916916
var graphql = await graphqlFactory.CreateConnection(address);
917917

918918
var comment = new AddPullRequestReviewCommentInput
@@ -944,7 +944,7 @@ public async Task<PullRequestDetailModel> PostStandaloneReviewComment(
944944
string path,
945945
int position)
946946
{
947-
var address = HostAddress.Create(localRepository.CloneUrl.Host);
947+
var address = HostAddress.Create(localRepository.CloneUrl);
948948
var graphql = await graphqlFactory.CreateConnection(address);
949949

950950
var addReview = new AddPullRequestReviewInput
@@ -995,7 +995,7 @@ public async Task<PullRequestDetailModel> DeleteComment(
995995
int pullRequestId,
996996
int commentDatabaseId)
997997
{
998-
var address = HostAddress.Create(localRepository.CloneUrl.Host);
998+
var address = HostAddress.Create(localRepository.CloneUrl);
999999
var apiClient = await apiClientFactory.Create(address);
10001000

10011001
await apiClient.DeletePullRequestReviewComment(
@@ -1013,7 +1013,7 @@ public async Task<PullRequestDetailModel> EditComment(LocalRepositoryModel local
10131013
string commentNodeId,
10141014
string body)
10151015
{
1016-
var address = HostAddress.Create(localRepository.CloneUrl.Host);
1016+
var address = HostAddress.Create(localRepository.CloneUrl);
10171017
var graphql = await graphqlFactory.CreateConnection(address);
10181018

10191019
var updatePullRequestReviewCommentInput = new UpdatePullRequestReviewCommentInput
@@ -1036,7 +1036,7 @@ public async Task<PullRequestDetailModel> EditComment(LocalRepositoryModel local
10361036

10371037
async Task<(string id, string owner, int number)> CreatePendingReviewCore(LocalRepositoryModel localRepository, string pullRequestId)
10381038
{
1039-
var address = HostAddress.Create(localRepository.CloneUrl.Host);
1039+
var address = HostAddress.Create(localRepository.CloneUrl);
10401040
var graphql = await graphqlFactory.CreateConnection(address);
10411041

10421042
var input = new AddPullRequestReviewInput

src/GitHub.VisualStudio.UI/Colors.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.VisualStudio.PlatformUI;
22
using System;
3+
using System.Windows;
34
using System.Windows.Media;
45

56
namespace GitHub.VisualStudio.Helpers
@@ -34,25 +35,22 @@ public static Color ToColor(this System.Drawing.Color color)
3435

3536
public static string DetectTheme()
3637
{
37-
try
38+
if (Application.Current?.TryFindResource(EnvironmentColors.AccentMediumColorKey) is Color cc)
3839
{
39-
var color = VSColorTheme.GetThemedColor(EnvironmentColors.AccentMediumColorKey);
40-
var cc = color.ToColor();
4140
if (cc == AccentMediumBlueTheme)
4241
return "Blue";
4342
if (cc == AccentMediumLightTheme)
4443
return "Light";
4544
if (cc == AccentMediumDarkTheme)
4645
return "Dark";
46+
var color = System.Drawing.Color.FromArgb(cc.A, cc.R, cc.R, cc.B);
4747
var brightness = color.GetBrightness();
4848
var dark = brightness < 0.5f;
4949
return dark ? "Dark" : "Light";
5050
}
51-
// this throws in design time and when running outside of VS
52-
catch (ArgumentNullException)
53-
{
54-
return "Dark";
55-
}
51+
52+
// When Visual Studio resources aren't active
53+
return "Dark";
5654
}
5755
}
5856
}

0 commit comments

Comments
 (0)