12
12
13
13
namespace CodeiumVS ;
14
14
15
- // this get called first
15
+ #pragma warning disable CS0618 // Type or member is obsolete
16
+
16
17
[ Export ( typeof ( CodeiumProposalSourceProvider ) ) ]
17
18
[ Export ( typeof ( ProposalSourceProviderBase ) ) ]
18
19
[ Name ( "CodeiumProposalSourceProvider" ) ]
@@ -27,7 +28,8 @@ internal class CodeiumProposalSourceProvider : ProposalSourceProviderBase
27
28
internal CodeiumProposalSourceProvider ( ITextDocumentFactoryService textDocumentFactoryService , SuggestionServiceBase suggestionServiceBase )
28
29
{
29
30
_textDocumentFactoryService = textDocumentFactoryService ;
30
- suggestionServiceBase . GetType ( ) . GetEvent ( "SuggestionAcceptedInternal" , BindingFlags . Instance | BindingFlags . Public ) ? . AddEventHandler ( suggestionServiceBase , new EventHandler < EventArgs > ( OnSuggestionAccepted ) ) ;
31
+ EventInfo ? acceptedEvent = suggestionServiceBase . GetType ( ) . GetEvent ( "SuggestionAcceptedInternal" , BindingFlags . Instance | BindingFlags . Public ) ;
32
+ acceptedEvent ? . AddEventHandler ( suggestionServiceBase , new EventHandler < EventArgs > ( OnSuggestionAccepted ) ) ;
31
33
}
32
34
33
35
internal CodeiumProposalSource TryCreate ( ITextView view )
@@ -36,8 +38,7 @@ internal CodeiumProposalSource TryCreate(ITextView view)
36
38
wpfView = view as IWpfTextView ;
37
39
if ( wpfView != null )
38
40
{
39
- ITextDocument document = null ;
40
- _textDocumentFactoryService . TryGetTextDocument ( view . TextDataModel . DocumentBuffer , out document ) ;
41
+ _textDocumentFactoryService . TryGetTextDocument ( view . TextDataModel . DocumentBuffer , out ITextDocument document ) ;
41
42
if ( document != null && IsAbsolutePath ( document . FilePath ) )
42
43
{
43
44
return view . Properties . GetOrCreateSingletonProperty ( typeof ( CodeiumProposalSource ) , ( ) => new CodeiumProposalSource ( wpfView , document ) ) ;
@@ -57,12 +58,28 @@ private static bool IsAbsolutePath(string path)
57
58
58
59
private void OnSuggestionAccepted ( object sender , EventArgs e )
59
60
{
60
- string proposalId = ( ( SuggestionAcceptedEventArgs ) e ) . FinalProposal . ProposalId ;
61
+ //string proposalId = ((SuggestionAcceptedEventArgs)e).FinalProposal.ProposalId;
62
+
63
+ // unfortunately in the SDK version 17.5.33428.388, there are no
64
+ // SuggestionAcceptedEventArgs so we have to use reflection here
65
+
66
+ FieldInfo ? fieldFinalProposal = e . GetType ( ) . GetField ( "FinalProposal" , BindingFlags . Instance | BindingFlags . Public ) ;
67
+ if ( fieldFinalProposal == null ) return ;
68
+
69
+ object finalProposal = fieldFinalProposal . GetValue ( e ) ;
70
+ if ( finalProposal == null ) return ;
71
+
72
+ PropertyInfo ? propertydProposalId = fieldFinalProposal . FieldType . GetProperty ( "ProposalId" , BindingFlags . Instance | BindingFlags . Public ) ;
73
+ if ( propertydProposalId == null ) return ;
74
+
75
+ if ( propertydProposalId . GetValue ( finalProposal ) is not string proposalId ) return ;
61
76
62
- CodeiumVSPackage . Instance . Log ( "Accepted completion " + proposalId ) ;
63
77
ThreadHelper . JoinableTaskFactory . RunAsync ( async delegate
64
78
{
79
+ await CodeiumVSPackage . Instance . LogAsync ( $ "Accepted completion { proposalId } ") ;
65
80
await CodeiumVSPackage . Instance . LanguageServer . AcceptCompletionAsync ( proposalId ) ;
66
81
} ) . FireAndForget ( true ) ;
67
82
}
68
83
}
84
+
85
+ #pragma warning restore CS0618 // Type or member is obsolete
0 commit comments