예제 #1
0
		bool ShouldPassThroughEnterKey(EnterKeyRule enterKeyRule) {
			if (enterKeyRule == EnterKeyRule.Default)
				enterKeyRule = TryGetRoslynCompletionService()?.GetRules().DefaultEnterKeyRule ?? enterKeyRule;

			switch (enterKeyRule) {
			case EnterKeyRule.Never:
				return false;

			case EnterKeyRule.Always:
				return true;

			case EnterKeyRule.AfterFullyTypedWord:
				if (!HasSession)
					return false;
				var completion = completionSession.SelectedCompletionSet?.SelectionStatus.Completion;
				if (completion == null)
					return false;
				var span = completionSession.SelectedCompletionSet.ApplicableTo;
				var text = span.GetText(span.TextBuffer.CurrentSnapshot);
				return text.Equals(completion.TryGetFilterText(), StringComparison.CurrentCultureIgnoreCase);

			case EnterKeyRule.Default:
				return false;

			default:
				Debug.Fail($"New {nameof(EnterKeyRule)} value: {enterKeyRule}");
				goto case EnterKeyRule.Default;
			}
		}
예제 #2
0
 public async Task SendEnterThroughToEditorTest(EnterKeyRule enterKeyRule) =>
 await VerifySendEnterThroughToEnterAsync(
     "#r \"System$$",
     "System",
     enterKeyRule,
     expected : false
     );
        public async Task <bool> CheckAndCommit(char insertedChar)
        {
            CompletionItem item = CompletionListControl.Items[CompletionListControl.SelectedIndex].item;

            List <char> commitCharacters = new List <char>(CompletionList.Rules.DefaultCommitCharacters);

            foreach (CharacterSetModificationRule rule in item.Rules.CommitCharacterRules)
            {
                if (rule.Kind == CharacterSetModificationKind.Add)
                {
                    commitCharacters.AddRange(rule.Characters);
                }
                else if (rule.Kind == CharacterSetModificationKind.Remove)
                {
                    foreach (char c in rule.Characters)
                    {
                        commitCharacters.Remove(c);
                    }
                }
                else if (rule.Kind == CharacterSetModificationKind.Replace)
                {
                    commitCharacters = new List <char>(rule.Characters);
                }
            }

            if (commitCharacters.Contains(insertedChar) || insertedChar == '\n' || insertedChar == '\r')
            {
                await Commit(item);
            }

            bool tbr = false;

            if (insertedChar == '\n' || insertedChar == '\r')
            {
                EnterKeyRule enterRule = item.Rules.EnterKeyRule;
                if (enterRule == EnterKeyRule.Default)
                {
                    enterRule = CompletionList.Rules.DefaultEnterKeyRule;
                }

                switch (enterRule)
                {
                case EnterKeyRule.Always:
                    tbr = false;
                    break;

                case EnterKeyRule.Never:
                    tbr = true;
                    break;

                case EnterKeyRule.AfterFullyTypedWord:
                    tbr = FilterText.Equals(item.DisplayText, StringComparison.OrdinalIgnoreCase);
                    break;
                }
            }

            return(tbr);
        }
예제 #4
0
 /// <summary>
 /// Creates a new <see cref="CompletionRules"/> instance.
 /// </summary>
 /// <param name="dismissIfEmpty">True if the completion list should be dismissed if the user's typing causes it to filter and display no items.</param>
 /// <param name="dismissIfLastCharacterDeleted">True if the list should be dismissed when the user deletes the last character in the span.</param>
 /// <param name="defaultCommitCharacters">The default set of typed characters that cause the selected item to be committed.</param>
 /// <param name="defaultEnterKeyRule">The default rule that determines if the enter key is passed through to the editor after the selected item has been committed.</param>
 public static CompletionRules Create(
     bool dismissIfEmpty,
     bool dismissIfLastCharacterDeleted,
     ImmutableArray <char> defaultCommitCharacters,
     EnterKeyRule defaultEnterKeyRule)
 {
     return(Create(dismissIfEmpty, dismissIfLastCharacterDeleted, defaultCommitCharacters,
                   defaultEnterKeyRule, SnippetsRule.Default));
 }
예제 #5
0
 /// <summary>
 /// Creates a new <see cref="CompletionRules"/> instance.
 /// </summary>
 /// <param name="dismissIfEmpty">True if the completion list should be dismissed if the user's typing causes it to filter and display no items.</param>
 /// <param name="dismissIfLastCharacterDeleted">True if the list should be dismissed when the user deletes the last character in the span.</param>
 /// <param name="defaultCommitCharacters">The default set of typed characters that cause the selected item to be committed.</param>
 /// <param name="defaultEnterKeyRule">The default rule that determines if the enter key is passed through to the editor after the selected item has been committed.</param>
 public static CompletionRules Create(
     bool dismissIfEmpty,
     bool dismissIfLastCharacterDeleted,
     ImmutableArray<char> defaultCommitCharacters,
     EnterKeyRule defaultEnterKeyRule)
 {
     return Create(dismissIfEmpty, dismissIfLastCharacterDeleted, defaultCommitCharacters,
         defaultEnterKeyRule, SnippetsRule.Default);
 }
예제 #6
0
 private CompletionRules(
     bool dismissIfEmpty,
     bool dismissIfLastCharacterDeleted,
     ImmutableArray <char> defaultCommitCharacters,
     EnterKeyRule defaultEnterKeyRule)
 {
     this.DismissIfEmpty = dismissIfEmpty;
     this.DismissIfLastCharacterDeleted = dismissIfLastCharacterDeleted;
     this.DefaultCommitCharacters       = defaultCommitCharacters.IsDefault ? ImmutableArray <char> .Empty : defaultCommitCharacters;
     this.DefaultEnterKeyRule           = defaultEnterKeyRule;
 }
예제 #7
0
        /// <summary>
        /// Creates a new <see cref="CompletionItemRules"/> instance--internal for TypeScript.
        /// </summary>
        /// <param name="filterCharacterRules">Rules about which keys typed are used to filter the list of completion items.</param>
        /// <param name="commitCharacterRules">Rules about which keys typed caused the completion item to be committed.</param>
        /// <param name="enterKeyRule">Rule about whether the enter key is passed through to the editor after the selected item has been committed.</param>
        /// <param name="formatOnCommit">True if the modified text should be formatted automatically.</param>
        /// <param name="preselect">True if the related completion item should be initially selected.</param>
        /// <returns></returns>
        internal static CompletionItemRules Create(
            ImmutableArray <CharacterSetModificationRule> filterCharacterRules,
            ImmutableArray <CharacterSetModificationRule> commitCharacterRules,
            EnterKeyRule enterKeyRule,
            bool formatOnCommit,
            bool preselect)
        {
            var matchPriority = preselect ? Completion.MatchPriority.Preselect : Completion.MatchPriority.Default;

            return(CompletionItemRules.Create(filterCharacterRules, commitCharacterRules, enterKeyRule, formatOnCommit, matchPriority));
        }
예제 #8
0
 private CompletionRules(
     bool dismissIfEmpty,
     bool dismissIfLastCharacterDeleted,
     ImmutableArray<char> defaultCommitCharacters,
     EnterKeyRule defaultEnterKeyRule)
 {
     this.DismissIfEmpty = dismissIfEmpty;
     this.DismissIfLastCharacterDeleted = dismissIfLastCharacterDeleted;
     this.DefaultCommitCharacters = defaultCommitCharacters.IsDefault ? ImmutableArray<char>.Empty : defaultCommitCharacters;
     this.DefaultEnterKeyRule = defaultEnterKeyRule;
 }
예제 #9
0
 /// <summary>
 /// Creates a new <see cref="CompletionRules"/> instance.
 /// </summary>
 /// <param name="dismissIfEmpty">True if the completion list should be dismissed if the user's typing causes it to filter and display no items.</param>
 /// <param name="dismissIfLastCharacterDeleted">True if the list should be dismissed when the user deletes the last character in the span.</param>
 /// <param name="defaultCommitCharacters">The default set of typed characters that cause the selected item to be committed.</param>
 /// <param name="defaultEnterKeyRule">The default rule that determines if the enter key is passed through to the editor after the selected item has been committed.</param>
 /// <returns></returns>
 public static CompletionRules Create(
     bool dismissIfEmpty = false,
     bool dismissIfLastCharacterDeleted = false,
     ImmutableArray<char> defaultCommitCharacters = default(ImmutableArray<char>),
     EnterKeyRule defaultEnterKeyRule = EnterKeyRule.Default)
 {
     return new CompletionRules(
         dismissIfEmpty: dismissIfEmpty,
         dismissIfLastCharacterDeleted: dismissIfLastCharacterDeleted,
         defaultCommitCharacters: defaultCommitCharacters,
         defaultEnterKeyRule: defaultEnterKeyRule);
 }
예제 #10
0
 /// <summary>
 /// Creates a new <see cref="CompletionItemRules"/> instance.
 /// </summary>
 /// <param name="filterCharacterRules">Rules about which keys typed are used to filter the list of completion items.</param>
 /// <param name="commitCharacterRules">Rules about which keys typed caused the completion item to be committed.</param>
 /// <param name="enterKeyRule">Rule about whether the enter key is passed through to the editor after the selected item has been committed.</param>
 /// <param name="formatOnCommit">True if the modified text should be formatted automatically.</param>
 /// <param name="matchPriority">True if the related completion item should be initially selected.</param>
 /// <returns></returns>
 public static CompletionItemRules Create(
     ImmutableArray <CharacterSetModificationRule> filterCharacterRules,
     ImmutableArray <CharacterSetModificationRule> commitCharacterRules,
     EnterKeyRule enterKeyRule,
     bool formatOnCommit,
     int?matchPriority)
 {
     return(Create(
                filterCharacterRules, commitCharacterRules,
                enterKeyRule, formatOnCommit, matchPriority,
                selectionBehavior: CompletionItemSelectionBehavior.Default));
 }
예제 #11
0
 /// <summary>
 /// Creates a new <see cref="CompletionRules"/> instance.
 /// </summary>
 /// <param name="dismissIfEmpty">True if the completion list should be dismissed if the user's typing causes it to filter and display no items.</param>
 /// <param name="dismissIfLastCharacterDeleted">True if the list should be dismissed when the user deletes the last character in the span.</param>
 /// <param name="defaultCommitCharacters">The default set of typed characters that cause the selected item to be committed.</param>
 /// <param name="defaultEnterKeyRule">The default rule that determines if the enter key is passed through to the editor after the selected item has been committed.</param>
 /// <returns></returns>
 public static CompletionRules Create(
     bool dismissIfEmpty = false,
     bool dismissIfLastCharacterDeleted            = false,
     ImmutableArray <char> defaultCommitCharacters = default(ImmutableArray <char>),
     EnterKeyRule defaultEnterKeyRule = EnterKeyRule.Default)
 {
     return(new CompletionRules(
                dismissIfEmpty: dismissIfEmpty,
                dismissIfLastCharacterDeleted: dismissIfLastCharacterDeleted,
                defaultCommitCharacters: defaultCommitCharacters,
                defaultEnterKeyRule: defaultEnterKeyRule));
 }
예제 #12
0
 private CompletionItemRules(
     ImmutableArray<CharacterSetModificationRule> filterCharacterRules,
     ImmutableArray<CharacterSetModificationRule> commitCharacterRules,
     EnterKeyRule enterKeyRule,
     bool formatOnCommit,
     bool preselect)
 {
     this.FilterCharacterRules = filterCharacterRules.IsDefault ? ImmutableArray<CharacterSetModificationRule>.Empty : filterCharacterRules;
     this.CommitCharacterRules = commitCharacterRules.IsDefault ? ImmutableArray<CharacterSetModificationRule>.Empty : commitCharacterRules;
     this.EnterKeyRule = enterKeyRule;
     this.FormatOnCommit = formatOnCommit;
     this.Preselect = preselect;
 }
예제 #13
0
 private CompletionItemRules(
     ImmutableArray <CharacterSetModificationRule> filterCharacterRules,
     ImmutableArray <CharacterSetModificationRule> commitCharacterRules,
     EnterKeyRule enterKeyRule,
     bool formatOnCommit,
     int matchPriority)
 {
     this.FilterCharacterRules = filterCharacterRules.IsDefault ? ImmutableArray <CharacterSetModificationRule> .Empty : filterCharacterRules;
     this.CommitCharacterRules = commitCharacterRules.IsDefault ? ImmutableArray <CharacterSetModificationRule> .Empty : commitCharacterRules;
     this.EnterKeyRule         = enterKeyRule;
     this.FormatOnCommit       = formatOnCommit;
     this.MatchPriority        = matchPriority;
 }
예제 #14
0
 private CompletionItemRules(
     ImmutableArray <CharacterSetModificationRule> filterCharacterRules,
     ImmutableArray <CharacterSetModificationRule> commitCharacterRules,
     EnterKeyRule enterKeyRule,
     bool formatOnCommit,
     bool preselect)
 {
     this.FilterCharacterRules = filterCharacterRules.IsDefault ? ImmutableArray <CharacterSetModificationRule> .Empty : filterCharacterRules;
     this.CommitCharacterRules = commitCharacterRules.IsDefault ? ImmutableArray <CharacterSetModificationRule> .Empty : commitCharacterRules;
     this.EnterKeyRule         = enterKeyRule;
     this.FormatOnCommit       = formatOnCommit;
     this.Preselect            = preselect;
 }
예제 #15
0
 private CompletionRules(
     bool dismissIfEmpty,
     bool dismissIfLastCharacterDeleted,
     ImmutableArray <char> defaultCommitCharacters,
     EnterKeyRule defaultEnterKeyRule,
     SnippetsRule snippetsRule)
 {
     DismissIfEmpty = dismissIfEmpty;
     DismissIfLastCharacterDeleted = dismissIfLastCharacterDeleted;
     DefaultCommitCharacters       = defaultCommitCharacters.NullToEmpty();
     DefaultEnterKeyRule           = defaultEnterKeyRule;
     SnippetsRule = snippetsRule;
 }
예제 #16
0
 private CompletionRules(
     bool dismissIfEmpty,
     bool dismissIfLastCharacterDeleted,
     ImmutableArray<char> defaultCommitCharacters,
     EnterKeyRule defaultEnterKeyRule,
     SnippetsRule snippetsRule)
 {
     this.DismissIfEmpty = dismissIfEmpty;
     this.DismissIfLastCharacterDeleted = dismissIfLastCharacterDeleted;
     this.DefaultCommitCharacters = defaultCommitCharacters.NullToEmpty();
     this.DefaultEnterKeyRule = defaultEnterKeyRule;
     this.SnippetsRule = snippetsRule;
 }
예제 #17
0
 private CompletionItemRules(
     ImmutableArray <CharacterSetModificationRule> filterCharacterRules,
     ImmutableArray <CharacterSetModificationRule> commitCharacterRules,
     EnterKeyRule enterKeyRule,
     bool formatOnCommit,
     int matchPriority,
     CompletionItemSelectionBehavior selectionBehavior)
 {
     FilterCharacterRules = filterCharacterRules.NullToEmpty();
     CommitCharacterRules = commitCharacterRules.NullToEmpty();
     EnterKeyRule         = enterKeyRule;
     FormatOnCommit       = formatOnCommit;
     MatchPriority        = matchPriority;
     SelectionBehavior    = selectionBehavior;
 }
예제 #18
0
 private CompletionItemRules(
     ImmutableArray<CharacterSetModificationRule> filterCharacterRules,
     ImmutableArray<CharacterSetModificationRule> commitCharacterRules,
     EnterKeyRule enterKeyRule,
     bool formatOnCommit,
     int matchPriority,
     CompletionItemSelectionBehavior selectionBehavior)
 {
     FilterCharacterRules = filterCharacterRules.IsDefault ? ImmutableArray<CharacterSetModificationRule>.Empty : filterCharacterRules;
     CommitCharacterRules = commitCharacterRules.IsDefault ? ImmutableArray<CharacterSetModificationRule>.Empty : commitCharacterRules;
     EnterKeyRule = enterKeyRule;
     FormatOnCommit = formatOnCommit;
     MatchPriority = matchPriority;
     SelectionBehavior = selectionBehavior;
 }
예제 #19
0
 /// <summary>
 /// Creates a new <see cref="CompletionItemRules"/> instance.
 /// </summary>
 /// <param name="filterCharacterRules">Rules about which keys typed are used to filter the list of completion items.</param>
 /// <param name="commitCharacterRules">Rules about which keys typed caused the completion item to be committed.</param>
 /// <param name="enterKeyRule">Rule about whether the enter key is passed through to the editor after the selected item has been committed.</param>
 /// <param name="formatOnCommit">True if the modified text should be formatted automatically.</param>
 /// <param name="preselect">True if the related completion item should be initially selected.</param>
 /// <returns></returns>
 public static CompletionItemRules Create(
     ImmutableArray <CharacterSetModificationRule> filterCharacterRules = default(ImmutableArray <CharacterSetModificationRule>),
     ImmutableArray <CharacterSetModificationRule> commitCharacterRules = default(ImmutableArray <CharacterSetModificationRule>),
     EnterKeyRule enterKeyRule = EnterKeyRule.Default,
     bool formatOnCommit       = false,
     bool preselect            = false)
 {
     if (filterCharacterRules.IsDefaultOrEmpty &&
         commitCharacterRules.IsDefaultOrEmpty &&
         enterKeyRule == Default.EnterKeyRule &&
         formatOnCommit == Default.FormatOnCommit &&
         preselect == Default.Preselect)
     {
         return(Default);
     }
     else
     {
         return(new CompletionItemRules(filterCharacterRules, commitCharacterRules, enterKeyRule, formatOnCommit, preselect));
     }
 }
예제 #20
0
 /// <summary>
 /// Creates a new <see cref="CompletionItemRules"/> instance.
 /// </summary>
 /// <param name="filterCharacterRules">Rules about which keys typed are used to filter the list of completion items.</param>
 /// <param name="commitCharacterRules">Rules about which keys typed caused the completion item to be committed.</param>
 /// <param name="enterKeyRule">Rule about whether the enter key is passed through to the editor after the selected item has been committed.</param>
 /// <param name="formatOnCommit">True if the modified text should be formatted automatically.</param>
 /// <param name="matchPriority">True if the related completion item should be initially selected.</param>
 /// <returns></returns>
 public static CompletionItemRules Create(
     ImmutableArray <CharacterSetModificationRule> filterCharacterRules = default(ImmutableArray <CharacterSetModificationRule>),
     ImmutableArray <CharacterSetModificationRule> commitCharacterRules = default(ImmutableArray <CharacterSetModificationRule>),
     EnterKeyRule enterKeyRule = EnterKeyRule.Default,
     bool formatOnCommit       = false,
     int?matchPriority         = null)
 {
     if (filterCharacterRules.IsDefaultOrEmpty &&
         commitCharacterRules.IsDefaultOrEmpty &&
         enterKeyRule == Default.EnterKeyRule &&
         formatOnCommit == Default.FormatOnCommit &&
         matchPriority == Default.MatchPriority)
     {
         return(Default);
     }
     else
     {
         return(new CompletionItemRules(filterCharacterRules, commitCharacterRules, enterKeyRule, formatOnCommit, matchPriority ?? Completion.MatchPriority.Default));
     }
 }
예제 #21
0
 /// <summary>
 /// Creates a new <see cref="CompletionItemRules"/> instance.
 /// </summary>
 /// <param name="filterCharacterRules">Rules about which keys typed are used to filter the list of completion items.</param>
 /// <param name="commitCharacterRules">Rules about which keys typed caused the completion item to be committed.</param>
 /// <param name="enterKeyRule">Rule about whether the enter key is passed through to the editor after the selected item has been committed.</param>
 /// <param name="formatOnCommit">True if the modified text should be formatted automatically.</param>
 /// <param name="preselect">True if the related completion item should be initially selected.</param>
 /// <returns></returns>
 public static CompletionItemRules Create(
     ImmutableArray<CharacterSetModificationRule> filterCharacterRules = default(ImmutableArray<CharacterSetModificationRule>),
     ImmutableArray<CharacterSetModificationRule> commitCharacterRules = default(ImmutableArray<CharacterSetModificationRule>),
     EnterKeyRule enterKeyRule = EnterKeyRule.Default,
     bool formatOnCommit = false,
     bool preselect = false)
 {
     if (filterCharacterRules.IsDefaultOrEmpty
         && commitCharacterRules.IsDefaultOrEmpty
         && enterKeyRule == Default.EnterKeyRule
         && formatOnCommit == Default.FormatOnCommit
         && preselect == Default.Preselect)
     {
         return Default;
     }
     else
     {
         return new CompletionItemRules(filterCharacterRules, commitCharacterRules, enterKeyRule, formatOnCommit, preselect);
     }
 }
예제 #22
0
 /// <summary>
 /// Creates a new <see cref="CompletionItemRules"/> instance.
 /// </summary>
 /// <param name="filterCharacterRules">Rules about which keys typed are used to filter the list of completion items.</param>
 /// <param name="commitCharacterRules">Rules about which keys typed caused the completion item to be committed.</param>
 /// <param name="enterKeyRule">Rule about whether the enter key is passed through to the editor after the selected item has been committed.</param>
 /// <param name="formatOnCommit">True if the modified text should be formatted automatically.</param>
 /// <param name="matchPriority">True if the related completion item should be initially selected.</param>
 /// <param name="selectionBehavior">How this item should be selected if no text has been typed after the completion list is brought up.</param>
 /// <returns></returns>
 public static CompletionItemRules Create(
     ImmutableArray <CharacterSetModificationRule> filterCharacterRules = default(ImmutableArray <CharacterSetModificationRule>),
     ImmutableArray <CharacterSetModificationRule> commitCharacterRules = default(ImmutableArray <CharacterSetModificationRule>),
     EnterKeyRule enterKeyRule = EnterKeyRule.Default,
     bool formatOnCommit       = false,
     int?matchPriority         = null,
     CompletionItemSelectionBehavior selectionBehavior = CompletionItemSelectionBehavior.Default)
 {
     if (filterCharacterRules.IsDefaultOrEmpty &&
         commitCharacterRules.IsDefaultOrEmpty &&
         enterKeyRule == Default.EnterKeyRule &&
         formatOnCommit == Default.FormatOnCommit &&
         matchPriority.GetValueOrDefault() == Default.MatchPriority &&
         selectionBehavior == Default.SelectionBehavior)
     {
         return(Default);
     }
     else
     {
         return(new CompletionItemRules(
                    filterCharacterRules, commitCharacterRules, enterKeyRule, formatOnCommit,
                    matchPriority.GetValueOrDefault(), selectionBehavior));
     }
 }
예제 #23
0
 /// <summary>
 /// Creates a new <see cref="CompletionItemRules"/> instance.
 /// </summary>
 /// <param name="filterCharacterRules">Rules about which keys typed are used to filter the list of completion items.</param>
 /// <param name="commitCharacterRules">Rules about which keys typed caused the completion item to be committed.</param>
 /// <param name="enterKeyRule">Rule about whether the enter key is passed through to the editor after the selected item has been committed.</param>
 /// <param name="formatOnCommit">True if the modified text should be formatted automatically.</param>
 /// <param name="matchPriority">True if the related completion item should be initially selected.</param>
 /// <returns></returns>
 public static CompletionItemRules Create(
     ImmutableArray<CharacterSetModificationRule> filterCharacterRules,
     ImmutableArray<CharacterSetModificationRule> commitCharacterRules,
     EnterKeyRule enterKeyRule,
     bool formatOnCommit,
     int? matchPriority)
 {
     return Create(
         filterCharacterRules, commitCharacterRules, 
         enterKeyRule, formatOnCommit, matchPriority, 
         selectionBehavior: CompletionItemSelectionBehavior.Default);
 }
        protected async Task VerifySendEnterThroughToEnterAsync(string initialMarkup, string textTypedSoFar, EnterKeyRule sendThroughEnterOption, bool expected, SourceCodeKind sourceCodeKind = SourceCodeKind.Regular)
        {
            using var workspace = TestWorkspace.CreateCSharp(initialMarkup, exportProvider: ExportProvider);
            var hostDocument = workspace.DocumentWithCursor;

            workspace.OnDocumentSourceCodeKindChanged(hostDocument.Id, sourceCodeKind);

            var documentId = workspace.GetDocumentId(hostDocument);
            var document   = workspace.CurrentSolution.GetDocument(documentId);
            var position   = hostDocument.CursorPosition.Value;

            workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options
                                                                            .WithChangedOption(
                                                                                CompletionOptions.EnterKeyBehavior,
                                                                                LanguageNames.CSharp,
                                                                                sendThroughEnterOption)));

            var service        = GetCompletionService(document.Project);
            var completionList = await GetCompletionListAsync(service, document, position, RoslynTrigger.Invoke);

            var item = completionList.Items.First(i => (i.DisplayText + i.DisplayTextSuffix).StartsWith(textTypedSoFar));

            Assert.Equal(expected, CommitManager.SendEnterThroughToEditor(service.GetRules(), item, textTypedSoFar));
        }
예제 #25
0
 /// <summary>
 /// Creates a copy of this <see cref="CompletionRules"/> with the <see cref="DefaultEnterKeyRule"/> property changed.
 /// </summary>
 public CompletionRules WithDefaultEnterKeyRule(EnterKeyRule defaultEnterKeyRule)
 {
     return With(defaultEnterKeyRule: defaultEnterKeyRule);
 }
예제 #26
0
        protected async Task VerifySendEnterThroughToEnterAsync(string initialMarkup, string textTypedSoFar, EnterKeyRule sendThroughEnterOption, bool expected)
        {
            using (var workspace = TestWorkspace.CreateCSharp(initialMarkup))
            {
                var hostDocument = workspace.DocumentWithCursor;
                var documentId   = workspace.GetDocumentId(hostDocument);
                var document     = workspace.CurrentSolution.GetDocument(documentId);
                var position     = hostDocument.CursorPosition.Value;

                workspace.Options = workspace.Options.WithChangedOption(
                    CompletionOptions.EnterKeyBehavior,
                    LanguageNames.CSharp,
                    sendThroughEnterOption);

                var service        = GetCompletionService(workspace);
                var completionList = await GetCompletionListAsync(service, document, position, CompletionTrigger.Invoke);

                var item = completionList.Items.First(i => (i.DisplayText + i.DisplayTextSuffix).StartsWith(textTypedSoFar));

                Assert.Equal(expected, CommitManager.SendEnterThroughToEditor(service.GetRules(), item, textTypedSoFar));
            }
        }
예제 #27
0
 /// <summary>
 /// Creates a copy of this <see cref="CompletionItemRules"/> with the <see cref="EnterKeyRule"/> property changed.
 /// </summary>
 public CompletionItemRules WithEnterKeyRule(EnterKeyRule enterKeyRule)
 {
     return this.With(enterKeyRule: enterKeyRule);
 }
 [InlineData(EnterKeyRule.Always)] // note: GAC completion helper uses its own EnterKeyRule
 public async Task SendEnterThroughToEditorTest(EnterKeyRule enterKeyRule)
 {
     await VerifySendEnterThroughToEnterAsync("#r \"System$$", "System", enterKeyRule, expected : false, SourceCodeKind.Script);
 }
예제 #29
0
 /// <summary>
 /// Creates a copy of this <see cref="CompletionRules"/> with the <see cref="DefaultEnterKeyRule"/> property changed.
 /// </summary>
 public CompletionRules WithDefaultEnterKeyRule(EnterKeyRule defaultEnterKeyRule)
 {
     return(With(defaultEnterKeyRule: defaultEnterKeyRule));
 }
예제 #30
0
 /// <summary>
 /// Creates a new <see cref="CompletionItemRules"/> instance--internal for TypeScript.
 /// </summary>
 /// <param name="filterCharacterRules">Rules about which keys typed are used to filter the list of completion items.</param>
 /// <param name="commitCharacterRules">Rules about which keys typed caused the completion item to be committed.</param>
 /// <param name="enterKeyRule">Rule about whether the enter key is passed through to the editor after the selected item has been committed.</param>
 /// <param name="formatOnCommit">True if the modified text should be formatted automatically.</param>
 /// <param name="preselect">True if the related completion item should be initially selected.</param>
 /// <returns></returns>
 internal static CompletionItemRules Create(
     ImmutableArray<CharacterSetModificationRule> filterCharacterRules,
     ImmutableArray<CharacterSetModificationRule> commitCharacterRules,
     EnterKeyRule enterKeyRule,
     bool formatOnCommit,
     bool preselect)
 {
     var matchPriority = preselect ? Completion.MatchPriority.Preselect : Completion.MatchPriority.Default;
     return CompletionItemRules.Create(filterCharacterRules, commitCharacterRules, enterKeyRule, formatOnCommit, matchPriority);
 }
예제 #31
0
 /// <summary>
 /// Creates a copy of this <see cref="CompletionItemRules"/> with the <see cref="EnterKeyRule"/> property changed.
 /// </summary>
 public CompletionItemRules WithEnterKeyRule(EnterKeyRule enterKeyRule)
 {
     return(this.With(enterKeyRule: enterKeyRule));
 }
예제 #32
0
 public CompletionRules WithDefaultEnterKeyRule(EnterKeyRule defaultEnterKeyRule)
 => With(defaultEnterKeyRule: defaultEnterKeyRule);
예제 #33
0
 /// <summary>
 /// Creates a new <see cref="CompletionItemRules"/> instance.
 /// </summary>
 /// <param name="filterCharacterRules">Rules about which keys typed are used to filter the list of completion items.</param>
 /// <param name="commitCharacterRules">Rules about which keys typed caused the completion item to be committed.</param>
 /// <param name="enterKeyRule">Rule about whether the enter key is passed through to the editor after the selected item has been committed.</param>
 /// <param name="formatOnCommit">True if the modified text should be formatted automatically.</param>
 /// <param name="matchPriority">True if the related completion item should be initially selected.</param>
 /// <param name="selectionBehavior">How this item should be selected if no text has been typed after the completion list is brought up.</param>
 /// <returns></returns>
 public static CompletionItemRules Create(
     ImmutableArray<CharacterSetModificationRule> filterCharacterRules = default(ImmutableArray<CharacterSetModificationRule>),
     ImmutableArray<CharacterSetModificationRule> commitCharacterRules = default(ImmutableArray<CharacterSetModificationRule>),
     EnterKeyRule enterKeyRule = EnterKeyRule.Default,
     bool formatOnCommit = false,
     int? matchPriority = null,
     CompletionItemSelectionBehavior selectionBehavior = CompletionItemSelectionBehavior.Default)
 {
     if (filterCharacterRules.IsDefaultOrEmpty &&
         commitCharacterRules.IsDefaultOrEmpty &&
         enterKeyRule == Default.EnterKeyRule &&
         formatOnCommit == Default.FormatOnCommit &&
         matchPriority.GetValueOrDefault() == Default.MatchPriority &&
         selectionBehavior == Default.SelectionBehavior)
     {
         return Default;
     }
     else
     {
         return new CompletionItemRules(
             filterCharacterRules, commitCharacterRules, enterKeyRule, formatOnCommit,
             matchPriority.GetValueOrDefault(), selectionBehavior);
     }
 }