本文整理汇总了C#中IBraceCompletionSession类的典型用法代码示例。如果您正苦于以下问题:C# IBraceCompletionSession类的具体用法?C# IBraceCompletionSession怎么用?C# IBraceCompletionSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IBraceCompletionSession类属于命名空间,在下文中一共展示了IBraceCompletionSession类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: OnReturn
public void OnReturn(IBraceCompletionSession session) {
if (NodejsPackage.Instance.FormattingGeneralOptionsPage.FormatOnEnter) {
// reshape code from
// {
// |}
//
// to
// {
// |
// }
// where | indicates caret position.
var closingPointPosition = session.ClosingPoint.GetPosition(session.SubjectBuffer.CurrentSnapshot);
Debug.Assert(
condition: closingPointPosition > 0,
message: "The closing point position should always be greater than zero",
detailMessage: "The closing point position should always be greater than zero, " +
"since there is also an opening point for this brace completion session");
// Insert an extra newline and indent the closing brace manually.
session.SubjectBuffer.Insert(
closingPointPosition - 1,
VsExtensions.GetNewLineText(session.TextView.TextSnapshot));
// Format before setting the caret.
Format(session);
// After editing, set caret to the correct position.
SetCaretPosition(session);
}
}
开发者ID:lioaphy,项目名称:nodejstools,代码行数:32,代码来源:BraceCompletionContext.cs
示例2: OnReturn
/// <summary>
/// Called by the editor when return is pressed while both
/// braces are on the same line and no typing has occurred
/// in the session.
/// </summary>
/// <remarks>
/// Called after the newline has been inserted into the buffer.
/// Formatting for scenarios where the closing brace needs to be
/// moved down an additional line past the caret should be done here.
/// </remarks>
/// <param name="session">Default brace completion session</param>
public void OnReturn(IBraceCompletionSession session) {
if (session.OpeningBrace == '{' && REditorSettings.AutoFormat) {
AutoFormat.IgnoreOnce = true;
EnsureTreeReady(session.SubjectBuffer);
FormatOperations.FormatCurrentScope(session.TextView, session.SubjectBuffer, indentCaret: true);
}
}
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:18,代码来源:BraceCompletionContext.cs
示例3: TryCreateSession
public bool TryCreateSession(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionSession session)
{
this.AssertIsForeground();
var textSnapshot = openingPoint.Snapshot;
var document = textSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
{
var editorSessionFactory = document.GetLanguageService<IEditorBraceCompletionSessionFactory>();
if (editorSessionFactory != null)
{
// Brace completion is (currently) not cancellable.
var cancellationToken = CancellationToken.None;
var editorSession = editorSessionFactory.TryCreateSession(document, openingPoint, openingBrace, cancellationToken);
if (editorSession != null)
{
var undoHistory = _undoManager.GetTextBufferUndoManager(textView.TextBuffer).TextBufferUndoHistory;
session = new BraceCompletionSession(
textView, openingPoint.Snapshot.TextBuffer, openingPoint, openingBrace, closingBrace,
undoHistory, _editorOperationsFactoryService,
editorSession);
return true;
}
}
}
session = null;
return false;
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:30,代码来源:BraceCompletionSessionProvider.cs
示例4: AfterReturn
public override void AfterReturn(IBraceCompletionSession session, CancellationToken cancellationToken)
{
// check whether shape of the braces are what we support
// shape must be either "{|}" or "{ }". | is where caret is. otherwise, we don't do any special behavior
if (!ContainsOnlyWhitespace(session))
{
return;
}
// alright, it is in right shape.
var undoHistory = GetUndoHistory(session.TextView);
using (var transaction = undoHistory.CreateTransaction(EditorFeaturesResources.Brace_Completion))
{
var document = session.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
{
document.InsertText(session.ClosingPoint.GetPosition(session.SubjectBuffer.CurrentSnapshot) - 1, Environment.NewLine, cancellationToken);
FormatTrackingSpan(session, shouldHonorAutoFormattingOnCloseBraceOption: false, rules: GetFormattingRules(document));
// put caret at right indentation
PutCaretOnLine(session, session.OpeningPoint.GetPoint(session.SubjectBuffer.CurrentSnapshot).GetContainingLineNumber() + 1);
transaction.Complete();
}
}
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:26,代码来源:CurlyBraceCompletionSession.cs
示例5: Finish
/// <summary>
/// Called after the session has been removed from the stack.
/// </summary>
/// <param name="session">Default brace completion session</param>
public void Finish(IBraceCompletionSession session) {
//if (session.OpeningBrace == '{' && REditorSettings.AutoFormat) {
// AutoFormat.IgnoreOnce = false;
// EnsureTreeReady(session.SubjectBuffer);
// FormatOperations.FormatCurrentScope(session.TextView, session.SubjectBuffer, indentCaret: false);
//}
}
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:11,代码来源:BraceCompletionContext.cs
示例6: Start
/// <summary>
/// Called before the session is added to the stack.
/// </summary>
/// <remarks>
/// If additional formatting is required for the opening or
/// closing brace it should be done here.
/// </remarks>
/// <param name="session">Default brace completion session</param>
public void Start(IBraceCompletionSession session) {
if (session.OpeningBrace == '{' && REditorSettings.AutoFormat) {
AutoFormat.IgnoreOnce = false;
EnsureTreeReady(session.SubjectBuffer);
FormatOperations.FormatCurrentNode<IStatement>(session.TextView, session.SubjectBuffer);
}
}
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:15,代码来源:BraceCompletionContext.cs
示例7: ContainsOnlyWhitespace
private static bool ContainsOnlyWhitespace(IBraceCompletionSession session)
{
var span = session.GetSessionSpan();
var snapshot = span.Snapshot;
var start = span.Start.Position;
start = snapshot[start] == session.OpeningBrace ? start + 1 : start;
var end = span.End.Position - 1;
end = snapshot[end] == session.ClosingBrace ? end - 1 : end;
if (!start.PositionInSnapshot(snapshot) ||
!end.PositionInSnapshot(snapshot))
{
return false;
}
for (int i = start; i <= end; i++)
{
if (!char.IsWhiteSpace(snapshot[i]))
{
return false;
}
}
return true;
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:28,代码来源:CurlyBraceCompletionSession.cs
示例8: SetCaretPosition
private static void SetCaretPosition(IBraceCompletionSession session) {
// Find next line from brace.
var snapshot = session.SubjectBuffer.CurrentSnapshot;
var openCurlyLine = session.OpeningPoint.GetPoint(snapshot).GetContainingLine();
var nextLineNumber = openCurlyLine.LineNumber + 1;
bool nextLineExists = nextLineNumber < snapshot.LineCount;
Debug.Assert(nextLineExists, "There are no lines after this brace completion's opening brace, no place to seek caret to.");
if (!nextLineExists) {
// Don't move the caret as we have somehow ended up without a line following our opening brace.
return;
}
// Get indent for this line.
ITextSnapshotLine nextLine = snapshot.GetLineFromLineNumber(nextLineNumber);
var indentation = GetIndentationLevelForLine(session, nextLine);
if (indentation > 0) {
// before deleting, make sure this line is only whitespace.
bool lineIsWhitepace = string.IsNullOrWhiteSpace(nextLine.GetText());
Debug.Assert(lineIsWhitepace, "The line after the brace should be empty.");
if (lineIsWhitepace) {
session.SubjectBuffer.Delete(nextLine.Extent);
MoveCaretTo(session.TextView, nextLine.End, indentation);
}
} else {
MoveCaretTo(session.TextView, nextLine.End);
}
}
开发者ID:lioaphy,项目名称:nodejstools,代码行数:28,代码来源:BraceCompletionContext.cs
示例9: CheckOpeningPoint
public override bool CheckOpeningPoint(IBraceCompletionSession session, CancellationToken cancellationToken)
{
var snapshot = session.SubjectBuffer.CurrentSnapshot;
var position = session.OpeningPoint.GetPosition(snapshot);
var token = snapshot.FindToken(position, cancellationToken);
// check token at the opening point first
if (!IsValidToken(token) ||
token.RawKind != OpeningTokenKind ||
token.SpanStart != position || token.Parent == null)
{
return false;
}
// now check whether parser think whether there is already counterpart closing parenthesis
var pair = token.Parent.GetParentheses();
// if pair is on the same line, then the closing parenthesis must belong to other tracker.
// let it through
if (snapshot.GetLineNumberFromPosition(pair.Item1.SpanStart) == snapshot.GetLineNumberFromPosition(pair.Item2.Span.End))
{
return true;
}
return (int)pair.Item2.Kind() != ClosingTokenKind || pair.Item2.Span.Length == 0;
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:26,代码来源:ParenthesisCompletionSession.cs
示例10: CheckOpeningPoint
public bool CheckOpeningPoint(IBraceCompletionSession session, CancellationToken cancellationToken)
{
var snapshot = session.SubjectBuffer.CurrentSnapshot;
var position = session.OpeningPoint.GetPosition(snapshot);
var token = snapshot.FindToken(position, cancellationToken);
return token.IsKind(SyntaxKind.InterpolatedStringStartToken, SyntaxKind.InterpolatedVerbatimStringStartToken)
&& token.Span.End - 1 == position;
}
开发者ID:RoryVL,项目名称:roslyn,代码行数:9,代码来源:InterpolatedStringCompletionSession.cs
示例11: Format
private void Format(IBraceCompletionSession session) {
var buffer = session.SubjectBuffer;
EditFilter.ApplyEdits(
buffer,
Formatter.GetEditsAfterEnter(
buffer.CurrentSnapshot.GetText(),
session.OpeningPoint.GetPosition(buffer.CurrentSnapshot),
session.ClosingPoint.GetPosition(buffer.CurrentSnapshot),
EditFilter.CreateFormattingOptions(session.TextView.Options, session.TextView.TextSnapshot)
)
);
}
开发者ID:lioaphy,项目名称:nodejstools,代码行数:12,代码来源:BraceCompletionContext.cs
示例12: CheckBackspace
internal void CheckBackspace(IBraceCompletionSession session)
{
session.TextView.TryMoveCaretToAndEnsureVisible(session.OpeningPoint.GetPoint(session.SubjectBuffer.CurrentSnapshot).Add(1));
session.PreBackspace(out var handled);
if (!handled)
{
session.PostBackspace();
}
Assert.Null(session.OpeningPoint);
Assert.Null(session.ClosingPoint);
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:12,代码来源:AbstractAutomaticBraceCompletionTests.cs
示例13: CheckCurrentPosition
protected bool CheckCurrentPosition(IBraceCompletionSession session, CancellationToken cancellationToken)
{
var document = session.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
{
// make sure auto closing is called from a valid position
var tree = document.GetSyntaxRootSynchronously(cancellationToken).SyntaxTree;
return !_syntaxFactsService.IsInNonUserCode(tree, session.GetCaretPosition().Value, cancellationToken);
}
return true;
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:13,代码来源:AbstractTokenBraceCompletionSession.cs
示例14: CheckOpeningPoint
public virtual bool CheckOpeningPoint(IBraceCompletionSession session, CancellationToken cancellationToken)
{
var snapshot = session.SubjectBuffer.CurrentSnapshot;
var position = session.OpeningPoint.GetPosition(snapshot);
var token = snapshot.FindToken(position, cancellationToken);
if (!IsValidToken(token))
{
return false;
}
return token.RawKind == OpeningTokenKind && token.SpanStart == position;
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:13,代码来源:AbstractTokenBraceCompletionSession.cs
示例15: CheckClosingTokenKind
protected bool CheckClosingTokenKind(IBraceCompletionSession session, CancellationToken cancellationToken)
{
var document = session.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
{
var root = document.GetSyntaxRootSynchronously(cancellationToken);
var position = session.ClosingPoint.GetPosition(session.SubjectBuffer.CurrentSnapshot);
return root.FindTokenFromEnd(position, includeZeroWidth: false, findInsideTrivia: true).RawKind == this.ClosingTokenKind;
}
return true;
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:13,代码来源:AbstractTokenBraceCompletionSession.cs
示例16: CheckOpeningPoint
public override bool CheckOpeningPoint(IBraceCompletionSession session, CancellationToken cancellationToken)
{
var snapshot = session.SubjectBuffer.CurrentSnapshot;
var position = session.OpeningPoint.GetPosition(snapshot);
var token = snapshot.FindToken(position, cancellationToken);
// check what parser thinks about the newly typed "<" and only proceed if parser thinks it is "<" of
// type argument or parameter list
if (!token.CheckParent<TypeParameterListSyntax>(n => n.LessThanToken == token) &&
!token.CheckParent<TypeArgumentListSyntax>(n => n.LessThanToken == token) &&
!PossibleTypeArgument(snapshot, token, cancellationToken))
{
return false;
}
return true;
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:17,代码来源:LessAndGreaterThanCompletionSession.cs
示例17: CheckStart
internal void CheckStart(IBraceCompletionSession session, bool expectValidSession = true)
{
Type(session, session.OpeningBrace.ToString());
session.Start();
if (expectValidSession)
{
var closingPoint = session.ClosingPoint.GetPoint(session.SubjectBuffer.CurrentSnapshot).Subtract(1);
Assert.Equal(closingPoint.GetChar(), session.ClosingBrace);
}
else
{
Assert.Null(session.OpeningPoint);
Assert.Null(session.ClosingPoint);
}
}
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:17,代码来源:AbstractAutomaticBraceCompletionTests.cs
示例18: CheckOpeningPoint
public override bool CheckOpeningPoint(IBraceCompletionSession session, CancellationToken cancellationToken)
{
var snapshot = session.SubjectBuffer.CurrentSnapshot;
var position = session.OpeningPoint.GetPosition(snapshot);
var token = snapshot.FindToken(position, cancellationToken);
if (!IsValidToken(token) || token.RawKind != OpeningTokenKind)
{
return false;
}
if (token.SpanStart == position)
{
return true;
}
return token.SpanStart + 1 == position && snapshot[token.SpanStart] == VerbatimStringPrefix;
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:18,代码来源:StringLiteralCompletionSession.cs
示例19: CheckTab
internal void CheckTab(IBraceCompletionSession session, bool allowTab = true)
{
session.PreTab(out var handled);
if (!handled)
{
session.PostTab();
}
var caret = session.TextView.GetCaretPoint(session.SubjectBuffer).Value;
if (allowTab)
{
Assert.Equal(session.ClosingPoint.GetPosition(session.SubjectBuffer.CurrentSnapshot), caret.Position);
}
else
{
Assert.True(caret.Position < session.ClosingPoint.GetPosition(session.SubjectBuffer.CurrentSnapshot));
}
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:18,代码来源:AbstractAutomaticBraceCompletionTests.cs
示例20: CheckReturn
internal void CheckReturn(IBraceCompletionSession session, int indentation, string result = null)
{
session.PreReturn(out var handled);
Type(session, Environment.NewLine);
if (!handled)
{
session.PostReturn();
}
var virtualCaret = session.TextView.GetVirtualCaretPoint(session.SubjectBuffer).Value;
Assert.Equal(indentation, virtualCaret.VirtualSpaces);
if (result != null)
{
Assert.Equal(result, session.SubjectBuffer.CurrentSnapshot.GetText());
}
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:19,代码来源:AbstractAutomaticBraceCompletionTests.cs
注:本文中的IBraceCompletionSession类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论