public void TryParseGeneratesProperty() { string result; int caretPosition; foreach (string accessibilityLevel in _accessibilityLevels.Keys) { foreach (string modifier in _modifiers.Keys) { foreach (string type in _types.Keys) { string visibility = _accessibilityLevels[accessibilityLevel]; string mod = _modifiers[modifier]; string returns = _types[type]; string mnemonic = accessibilityLevel + modifier + type + "p"; MnemonicParser.TryParse(mnemonic, " ", out result, out caretPosition) .Should() .BeTrue($"Mnemonic {mnemonic} is valid."); result.Should().Be($"{visibility} {mod} {returns} {{ get; set; }}"); } } } }
public override int Exec( ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { if (PackageGuids.GuidEmmetPackageCmdSet != pguidCmdGroup || PackageIds.CmdIDExpandMnemonic != nCmdID) { return(base.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut)); } // Get mnemonic content from editor. SnapshotPoint caretPosition = View.WpfView.Caret.Position.BufferPosition; ITextSnapshotLine line = View.WpfView.Caret.Position.BufferPosition.GetContainingLine(); string lineText = line.GetText(); if (caretPosition.Position != line.End || lineText.Length < 3) { return(VSConstants.S_OK); } string mnemonic = lineText.TrimStart(); string indent = new string(' ', lineText.Length - mnemonic.Length); string snippet = string.Empty; int caretOffset; if (!MnemonicParser.TryParse(mnemonic, indent, out snippet, out caretOffset)) { return(VSConstants.S_OK); } // Insert generated snippet into the current editor window int startPosition = line.End.Position - mnemonic.Length; Span targetPosition = new Span(startPosition, mnemonic.Length); View.CurrentBuffer.Replace(targetPosition, snippet); // Close all intellisense windows _completionBroker.DismissAllSessions(View.WpfView); // Move caret to the position where user can start typing new member name caretPosition = new SnapshotPoint( View.CurrentBuffer.CurrentSnapshot, caretPosition.Position + caretOffset); View.WpfView.Caret.MoveTo(caretPosition); return(VSConstants.S_OK); }