Skip to content

Commit

Permalink
Statement Completion improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
HJLebbink committed Sep 14, 2016
1 parent b7353ad commit cf9c831
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,17 @@ public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pv
//handledChar = this.StartSession(); // do not start the session; the existing commandHandler does that for you, otherwise you may create multiple sessions at the same time.
break;
case VSConstants.VSStd2KCmdID.RETURN:
handledChar = this.Complete(true); // this line is necessary. If not present, enter does not commit the completion.
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Exec; return pressed. handledChar=" + handledChar);
break;
case VSConstants.VSStd2KCmdID.TAB:
handledChar = this.Complete(false);
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Exec; tab pressed. handledChar=" + handledChar);
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Exec; tab or enter pressed.");
handledChar = this.Complete();
break;
case VSConstants.VSStd2KCmdID.CANCEL:
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Exec; cancel pressed.");
handledChar = this.Cancel();
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Exec; cancel pressed. handledChar=" + handledChar);
break;
case VSConstants.VSStd2KCmdID.TYPECHAR:
//if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Exec; "+typedChar+" pressed.");
typedChar = GetTypeChar(pvaIn);
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Exec; "+typedChar+" pressed. handledChar=" + handledChar);
break;
}
}
Expand All @@ -106,7 +103,7 @@ public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pv
case VSConstants.VSStd2KCmdID.TYPECHAR:
case VSConstants.VSStd2KCmdID.BACKSPACE:
case VSConstants.VSStd2KCmdID.DELETE:
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Exec; Post-process");
//if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Exec; Post-process");
this.Filter();
break;
}
Expand Down Expand Up @@ -149,59 +146,87 @@ private bool StartSession()
#region Clear all existing sessions
if (this._session != null)
{
//IntrinsicsDudeToolsStatic.Output("INFO: CodeCompletionCommandHandler: StartSession. already an active session(" + _session.GetTriggerPoint(this._textView.TextBuffer) + ")");
IntrinsicsDudeToolsStatic.Output("INFO: CodeCompletionCommandHandler: StartSession. dismissing already active session(" + _session.GetTriggerPoint(this._textView.TextBuffer) + ")");
this._session.Dismiss();
}
this._broker.DismissAllSessions(this._textView);
//this._broker.DismissAllSessions(this._textView);
#endregion

SnapshotPoint caret = this._textView.Caret.Position.BufferPosition;
ITextSnapshot snapshot = caret.Snapshot;
this._session = this._broker.CreateCompletionSession(this._textView, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), false);

this._session = this._broker.TriggerCompletion(this._textView);
//this._session = this._broker.CreateCompletionSession(this._textView, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), false);
//IntrinsicsDudeToolsStatic.Output("INFO: CodeCompletionCommandHandler: StartSession. Created a new auto-complete session(" + _session.GetTriggerPoint(this._textView.TextBuffer) + ")");

this._session.Dismissed += (sender, args) => _session = null;
if (!this._session.IsStarted)
{
//this._session.Dismissed += (sender, args) => _session = null;
//if (!this._session.IsStarted)
//{
//IntrinsicsDudeToolsStatic.Output("INFO: CodeCompletionCommandHandler: StartSession: starting session(" + _session.GetTriggerPoint(this._textView.TextBuffer) + ")");
this._session.Start();
}
// this._session.Start();
//}

//IntrinsicsDudeToolsStatic.Output(string.Format("INFO: {0}:StartSession", this.ToString()));
return true;
}

/// <summary>
/// Complete the auto-complete
/// </summary>
/// <param name="force">force the selection even if it has not been manually selected</param>
/// <returns></returns>
private bool Complete(bool force)
private bool Complete()
{
if (this._broker.IsCompletionActive(_textView))
{ // if _session is zero, it is possible that _broker has a session that has been started by the default code completion code, reuse this session
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Complete. reusing existing session.");
this._session = this._broker.GetSessions(_textView)[0];
if (this._session == null)
{
if (this._broker.IsCompletionActive(_textView))
{
this._session = this._broker.GetSessions(_textView)[0];
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Complete. current session was null; reusing existing session.");
}
} else if (this._session.IsDismissed)
{
if (this._broker.IsCompletionActive(_textView))
{
this._session = this._broker.GetSessions(_textView)[0];
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Complete. current session was dismissed; reusing existing session.");
}
}
if (this._session == null)
{
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Complete. Session is null: no completions.");
return false;
}
if (this._session.IsDismissed)
{
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Complete. Session is dismissed: no completions.");
return false;
}
if (!_session.SelectedCompletionSet.SelectionStatus.IsSelected && !force)
if (!this._session.IsStarted)
{
this._session.Dismiss();
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Complete. exiting; no completion.");
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Complete. Session is not started: no completions.");
return false;
} else
}


bool isSelected = _session.SelectedCompletionSet.SelectionStatus.IsSelected;
bool isUnique = _session.SelectedCompletionSet.SelectionStatus.IsUnique;
string insertionText = this._session.SelectedCompletionSet.SelectionStatus.Completion.InsertionText;

if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Complete. IsSelected="+ isSelected + "; IsUnique=" + isUnique+ "; insertionText="+ insertionText);

if (isSelected)
{
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Complete. committing insertion_Text=" + this._session.SelectedCompletionSet.SelectionStatus.Completion.InsertionText);
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Complete. Committing InsertionText=" + insertionText);
this._session.Commit();
return true;
}

if (isUnique)
{
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Complete. Committing InsertionText=" + insertionText);
this._session.Commit();
return true;
}

this._session.Dismiss();
if (LOG_ON) IntrinsicsDudeToolsStatic.Output("INFO: StatementCompletionCommandHandler: Complete. exiting; no completion.");
return false;
}

private bool Cancel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,28 @@ namespace MefRegistration
using Microsoft.VisualStudio.Utilities;
using Microsoft.VisualStudio.Text.Editor;

[Export(typeof(IWpfTextViewCreationListener))]
[ContentType("text")]
[TextViewRole(PredefinedTextViewRoles.Document)]
public sealed class TextAdornment1TextViewCreationListener : IWpfTextViewCreationListener
{
public void TextViewCreated(IWpfTextView textView)
/*
[Export(typeof(IWpfTextViewCreationListener))]
[ContentType("text")]
[TextViewRole(PredefinedTextViewRoles.Document)]
public sealed class TextAdornment1TextViewCreationListener : IWpfTextViewCreationListener
{
//TextAdornment a = new TextAdornment(textView, 0, "BLA1");
//a.show(1, "BLA2");
}
public void TextViewCreated(IWpfTextView textView)
{
//TextAdornment a = new TextAdornment(textView, 0, "BLA1");
//a.show(1, "BLA2");
}
#pragma warning disable CS0169 // C# warning "the field editorAdornmentLayer is never used" -- but it is used, by MEF!
[Export(typeof(AdornmentLayerDefinition))]
[Name("TextAdornment1")]
[Order(After = PredefinedAdornmentLayers.Selection, Before = PredefinedAdornmentLayers.Text)]
private AdornmentLayerDefinition editorAdornmentLayer;
#pragma warning restore CS0169
}
#pragma warning disable CS0169 // C# warning "the field editorAdornmentLayer is never used" -- but it is used, by MEF!
[Export(typeof(AdornmentLayerDefinition))]
[Name("TextAdornment1")]
[Order(After = PredefinedAdornmentLayers.Selection, Before = PredefinedAdornmentLayers.Text)]
private AdornmentLayerDefinition editorAdornmentLayer;
#pragma warning restore CS0169
}
*/
}


public sealed class TextAdornment
{
private readonly IWpfTextView _view;
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion VS/CSHARP/intrinsics-dude-vsix/intrinsics-dude-vsix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@
</Compile>
<Compile Include="StatementCompletion\TextAdornmnent.cs" />
<Compile Include="StatementCompletion\VsTextViewCreationListener.cs" />
<Compile Include="StatementCompletion\WaitAdornment.cs" />
<Compile Include="SyntaxHighlighting\IntrinsicClassificationDefinition.cs" />
<Compile Include="SyntaxHighlighting\IntrinsicClassifier.cs" />
<Compile Include="SyntaxHighlighting\IntrinsicClassifierProvider.cs" />
Expand Down
2 changes: 1 addition & 1 deletion VS/CSHARP/intrinsics-dude-vsix/source.extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static class Vsix
public const string Name = "IntrinsicsDude";
public const string Description = "Improved Statement Completion, Quickinfo Tooltips and Signature Help for Compiler Intrinsics in Visual Studio 2015";
public const string Language = "en-US";
public const string Version = "1.1.1.3";
public const string Version = "1.1.1.4";
public const string Author = "Henk-Jan Lebbink";
public const string Tags = "Compiler Intrinsics, Statement Completion, Quickinfo Tooltips, Signature Help, AVX512";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="5BC76C2B-A941-40D2-9EB4-F0DB92DD7C06" Version="1.1.1.3" Language="en-US" Publisher="Henk-Jan Lebbink" />
<Identity Id="5BC76C2B-A941-40D2-9EB4-F0DB92DD7C06" Version="1.1.1.4" Language="en-US" Publisher="Henk-Jan Lebbink" />
<DisplayName>Intrinsics Dude</DisplayName>
<Description xml:space="preserve">Improved Statement Completion, Quickinfo Tooltips and Signature Help for Compiler Intrinsics in Visual Studio 2015</Description>
<MoreInfo>https://github.com/HJLebbink/intrinsics-dude</MoreInfo>
Expand Down

0 comments on commit cf9c831

Please sign in to comment.