Skip to content

Commit

Permalink
Downgrade the SDK version to 17.5.33428.388
Browse files Browse the repository at this point in the history
  • Loading branch information
thedemons committed Dec 14, 2023
1 parent b6e62cb commit b8c3403
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CodeiumVS/CodeiumVS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.SDK">
<Version>17.8.37222</Version>
<Version>17.5.33428.388</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.SDK.VsixSuppression">
<Version>14.1.37</Version>
Expand Down
45 changes: 26 additions & 19 deletions CodeiumVS/InlineDiff/InlineDiffAdornment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@

namespace CodeiumVs.InlineDiff;

internal class InlineDiffAdornment : TextViewExtension<IWpfTextView, InlineDiffAdornment>, ILineTransformSource, IOleCommandTarget
internal sealed class Components
{
[Export(typeof(AdornmentLayerDefinition))]
[Name("CodeiumInlineDiffAdornment")]
internal const string DiffAdornmentLayerName = "CodeiumInlineDiffAdornment";

[Export]
[Name(DiffAdornmentLayerName)]
[Order(After = "Text")]
private static readonly AdornmentLayerDefinition _codeiumInlineDiffAdornment;
[TextViewRole(PredefinedTextViewRoles.Document)]
internal AdornmentLayerDefinition viewLayerDefinition = null;
}

internal class InlineDiffAdornment : TextViewExtension<IWpfTextView, InlineDiffAdornment>, ILineTransformSource, IOleCommandTarget
{
private static readonly LineTransform _defaultTransform = new(1.0);
private static MethodInfo? _fnSetInterceptsAggregateFocus = null;

Expand All @@ -59,15 +65,15 @@ internal class InlineDiffAdornment : TextViewExtension<IWpfTextView, InlineDiffA
private double _codeBlockHeight = 0;

private LineTransform _lineTransform = _defaultTransform;
private ITagAggregator<InterLineAdornmentTag>? _tagAggregator = null;
//private ITagAggregator<InterLineAdornmentTag>? _tagAggregator = null;

public bool HasAdornment => _adornment != null;
public bool IsAdornmentFocused => HasAdornment && (_adornment.ActiveView != null) && _adornment.ActiveView.VisualElement.IsKeyboardFocused;

public InlineDiffAdornment(IWpfTextView view) : base(view)
{
_vsHostView = _hostView.ToIVsTextView();
_layer = _hostView.GetAdornmentLayer("CodeiumInlineDiffAdornment");
_layer = _hostView.GetAdornmentLayer(Components.DiffAdornmentLayerName);

_hostView.Closed += HostView_OnClosed;
_hostView.LayoutChanged += HostView_OnLayoutChanged;
Expand Down Expand Up @@ -610,19 +616,20 @@ LineTransform ILineTransformSource.GetLineTransform(ITextViewLine line, double y
/// <returns></returns>
private bool IsPeekOnAdornment()
{
ThreadHelper.ThrowIfNotOnUIThread("IsPeekOnAnchor");
_tagAggregator ??= IntellisenseUtilities.GetTagAggregator<InterLineAdornmentTag>(_hostView);

SnapshotSpan extent = _leftTrackingSpan.GetSpan(_hostView.TextSnapshot);

foreach (IMappingTagSpan<InterLineAdornmentTag> tag in _tagAggregator.GetTags(extent))
{
if (!tag.Tag.IsAboveLine && tag.Span.GetSpans(_hostView.TextSnapshot).IntersectsWith(extent))
{
return true;
}
}
return false;
//Microsoft.VisualStudio.Text.Editor.InterLineAdornmentTag
//ThreadHelper.ThrowIfNotOnUIThread("IsPeekOnAnchor");
//_tagAggregator ??= IntellisenseUtilities.GetTagAggregator<InterLineAdornmentTag>(_hostView);

//SnapshotSpan extent = _leftTrackingSpan.GetSpan(_hostView.TextSnapshot);

//foreach (IMappingTagSpan<InterLineAdornmentTag> tag in _tagAggregator.GetTags(extent))
//{
// if (!tag.Tag.IsAboveLine && tag.Span.GetSpans(_hostView.TextSnapshot).IntersectsWith(extent))
// {
// return true;
// }
//}
return true;
}

#pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread
Expand Down
3 changes: 3 additions & 0 deletions CodeiumVS/Proposal/CodeiumProposalManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace CodeiumVS;

#pragma warning disable CS0618 // Type or member is obsolete
internal class CodeiumProposalManager : ProposalManagerBase
{
private readonly IWpfTextView view;
Expand Down Expand Up @@ -62,3 +63,5 @@ public override bool TryGetIsProposalPosition(VirtualSnapshotPoint caret, Propos
return value;
}
}

#pragma warning restore CS0618 // Type or member is obsolete
4 changes: 4 additions & 0 deletions CodeiumVS/Proposal/CodeiumProposalManagerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace CodeiumVS;

#pragma warning disable CS0618 // Type or member is obsolete

[Export(typeof(ProposalManagerProviderBase))]
[Name("CodeiumProposalManagerProvider")]
[Order(Before = "InlineCSharpProposalManagerProvider")]
Expand All @@ -19,3 +21,5 @@ internal class CodeiumProposalManagerProvider : ProposalManagerProviderBase
return CodeiumProposalManager.TryCreateAsync(view, this);
}
}

#pragma warning restore CS0618 // Type or member is obsolete
9 changes: 6 additions & 3 deletions CodeiumVS/Proposal/CodeiumProposalSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace CodeiumVS;

#pragma warning disable CS0618 // Type or member is obsolete
internal class CodeiumProposalSource : ProposalSourceBase
{

Expand Down Expand Up @@ -43,7 +44,7 @@ public override Task DisposeAsync()
{
_document.FileActionOccurred -= OnFileActionOccurred;
_document.TextBuffer.ContentTypeChanged -= OnContentTypeChanged;
UpdateRequestTokenSource(null, "source is being disposed");
UpdateRequestTokenSource(null);
return base.DisposeAsync();
}

Expand All @@ -69,7 +70,7 @@ public override async Task<ProposalCollectionBase> RequestProposalsAsync(Virtual

CancellationTokenSource cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
cancellationToken = cancellationTokenSource.Token;
UpdateRequestTokenSource(cancellationTokenSource, "new proposal requested");
UpdateRequestTokenSource(cancellationTokenSource);

if (completionState != null)
{
Expand Down Expand Up @@ -113,7 +114,7 @@ public override async Task<ProposalCollectionBase> RequestProposalsAsync(Virtual
}
}

private void UpdateRequestTokenSource(CancellationTokenSource newSource, string reason)
private void UpdateRequestTokenSource(CancellationTokenSource newSource)
{
CancellationTokenSource cancellationTokenSource = Interlocked.Exchange(ref _requestTokenSource, newSource);
if (cancellationTokenSource != null)
Expand Down Expand Up @@ -191,3 +192,5 @@ private void RefreshLanguage()
}

}

#pragma warning restore CS0618 // Type or member is obsolete
29 changes: 23 additions & 6 deletions CodeiumVS/Proposal/CodeiumProposalSourceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

namespace CodeiumVS;

// this get called first
#pragma warning disable CS0618 // Type or member is obsolete

[Export(typeof(CodeiumProposalSourceProvider))]
[Export(typeof(ProposalSourceProviderBase))]
[Name("CodeiumProposalSourceProvider")]
Expand All @@ -27,7 +28,8 @@ internal class CodeiumProposalSourceProvider : ProposalSourceProviderBase
internal CodeiumProposalSourceProvider(ITextDocumentFactoryService textDocumentFactoryService, SuggestionServiceBase suggestionServiceBase)
{
_textDocumentFactoryService = textDocumentFactoryService;
suggestionServiceBase.GetType().GetEvent("SuggestionAcceptedInternal", BindingFlags.Instance | BindingFlags.Public)?.AddEventHandler(suggestionServiceBase, new EventHandler<EventArgs>(OnSuggestionAccepted));
EventInfo? acceptedEvent = suggestionServiceBase.GetType().GetEvent("SuggestionAcceptedInternal", BindingFlags.Instance | BindingFlags.Public);
acceptedEvent?.AddEventHandler(suggestionServiceBase, new EventHandler<EventArgs>(OnSuggestionAccepted));
}

internal CodeiumProposalSource TryCreate(ITextView view)
Expand All @@ -36,8 +38,7 @@ internal CodeiumProposalSource TryCreate(ITextView view)
wpfView = view as IWpfTextView;
if (wpfView != null)
{
ITextDocument document = null;
_textDocumentFactoryService.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out document);
_textDocumentFactoryService.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out ITextDocument document);
if (document != null && IsAbsolutePath(document.FilePath))
{
return view.Properties.GetOrCreateSingletonProperty(typeof(CodeiumProposalSource), () => new CodeiumProposalSource(wpfView, document));
Expand All @@ -57,12 +58,28 @@ private static bool IsAbsolutePath(string path)

private void OnSuggestionAccepted(object sender, EventArgs e)
{
string proposalId = ((SuggestionAcceptedEventArgs)e).FinalProposal.ProposalId;
//string proposalId = ((SuggestionAcceptedEventArgs)e).FinalProposal.ProposalId;

// unfortunately in the SDK version 17.5.33428.388, there are no
// SuggestionAcceptedEventArgs so we have to use reflection here

FieldInfo? fieldFinalProposal = e.GetType().GetField("FinalProposal", BindingFlags.Instance | BindingFlags.Public);
if (fieldFinalProposal == null) return;

object finalProposal = fieldFinalProposal.GetValue(e);
if (finalProposal == null) return;

PropertyInfo? propertydProposalId = fieldFinalProposal.FieldType.GetProperty("ProposalId", BindingFlags.Instance | BindingFlags.Public);
if (propertydProposalId == null) return;

if (propertydProposalId.GetValue(finalProposal) is not string proposalId) return;

CodeiumVSPackage.Instance.Log("Accepted completion " + proposalId);
ThreadHelper.JoinableTaskFactory.RunAsync(async delegate
{
await CodeiumVSPackage.Instance.LogAsync($"Accepted completion {proposalId}");
await CodeiumVSPackage.Instance.LanguageServer.AcceptCompletionAsync(proposalId);
}).FireAndForget(true);
}
}

#pragma warning restore CS0618 // Type or member is obsolete
2 changes: 1 addition & 1 deletion CodeiumVS/Utilities/MefProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private MefProvider()
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

// sastify mef import
_compositionService = Requires.NotNull(await ServiceProvider.GetGlobalServiceAsync(typeof(SComponentModel)) as IComponentModel);
_compositionService = Requires.NotNull(await ServiceProvider.GetGlobalServiceAsync(typeof(SComponentModel)) as IComponentModel, "_compositionService");
_compositionService.DefaultCompositionService.SatisfyImportsOnce(this);

// disabled because not needed right now
Expand Down

0 comments on commit b8c3403

Please sign in to comment.