Пример #1
0
        public bool IsUseSuggestionModeOn()
        {
            return(ExecuteOnActiveView(textView =>
            {
                var featureServiceFactory = GetComponentModelService <IFeatureServiceFactory>();
                var subjectBuffer = GetBufferContainingCaret(textView);

                var options = textView.Options.GlobalOptions;
                EditorOptionKey <bool> optionKey;
                bool defaultOption;
                if (IsDebuggerTextView(textView))
                {
                    optionKey = new EditorOptionKey <bool>(PredefinedCompletionNames.SuggestionModeInDebuggerCompletionOptionName);
                    defaultOption = true;
                }
                else
                {
                    optionKey = new EditorOptionKey <bool>(PredefinedCompletionNames.SuggestionModeInCompletionOptionName);
                    defaultOption = false;
                }

                if (!options.IsOptionDefined(optionKey, localScopeOnly: false))
                {
                    return defaultOption;
                }

                return options.GetOptionValue(optionKey);
            }));

            bool IsDebuggerTextView(IWpfTextView textView)
            => textView.Roles.Contains("DEBUGVIEW");
        }
Пример #2
0
        private void LoadOption <T>(EditorOptionKey <T> key)
        {
            string collection = GetCollectionName(key.Name);
            string property   = GetPropertyName(key.Name);

            int ivalue = 0;

            if (VSConstants.S_OK == _store.CollectionExists(collection, out ivalue))
            {
                ivalue = 2;
            }

            string svalue;

            if (VSConstants.S_OK == _store.GetString(collection, property, out svalue))
            {
                if (typeof(T) == typeof(bool))
                {
                    bool value = bool.Parse(svalue);
                    _options.SetOptionValue(key.Name, value);
                }
                else if (typeof(T) == typeof(uint))
                {
                    uint argb = uint.Parse(svalue);
                    _options.SetOptionValue(key.Name, argb);
                }
            }
        }
Пример #3
0
        public void SetUseSuggestionMode(bool value)
        {
            if (IsUseSuggestionModeOn() != value)
            {
                ExecuteCommand(WellKnownCommandNames.Edit_ToggleCompletionMode);

                if (IsUseSuggestionModeOn() != value)
                {
                    throw new InvalidOperationException($"{WellKnownCommandNames.Edit_ToggleCompletionMode} did not leave the editor in the expected state.");
                }
            }

            if (!value)
            {
                // For blocking completion mode, make sure we don't have responsive completion interfering when
                // integration tests run slowly.
                ExecuteOnActiveView(view =>
                {
                    var options = view.Options.GlobalOptions;
                    options.SetOptionValue(DefaultOptions.ResponsiveCompletionOptionId, false);

                    var latencyGuardOptionKey = new EditorOptionKey <bool>("EnableTypingLatencyGuard");
                    options.SetOptionValue(latencyGuardOptionKey, false);
                });
            }
        }
Пример #4
0
        public async Task <bool> IsUseSuggestionModeOnAsync(bool forDebuggerTextView, CancellationToken cancellationToken)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            var editorOptionsFactory = await GetComponentModelServiceAsync <IEditorOptionsFactoryService>(cancellationToken);

            var options = editorOptionsFactory.GlobalOptions;

            EditorOptionKey <bool> optionKey;
            bool defaultOption;

            if (forDebuggerTextView)
            {
                optionKey     = new EditorOptionKey <bool>(PredefinedCompletionNames.SuggestionModeInDebuggerCompletionOptionName);
                defaultOption = true;
            }
            else
            {
                optionKey     = new EditorOptionKey <bool>(PredefinedCompletionNames.SuggestionModeInCompletionOptionName);
                defaultOption = false;
            }

            if (!options.IsOptionDefined(optionKey, localScopeOnly: false))
            {
                return(defaultOption);
            }

            return(options.GetOptionValue(optionKey));
        }
Пример #5
0
        public async Task <bool> IsUseSuggestionModeOnAsync(CancellationToken cancellationToken)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            var textView = await GetActiveTextViewAsync(cancellationToken);

            var subjectBuffer = textView.GetBufferContainingCaret();

            Assumes.Present(subjectBuffer);

            var options = textView.Options.GlobalOptions;
            EditorOptionKey <bool> optionKey;
            bool defaultOption;

            if (IsDebuggerTextView(textView))
            {
                optionKey     = new EditorOptionKey <bool>(PredefinedCompletionNames.SuggestionModeInDebuggerCompletionOptionName);
                defaultOption = true;
            }
            else
            {
                optionKey     = new EditorOptionKey <bool>(PredefinedCompletionNames.SuggestionModeInCompletionOptionName);
                defaultOption = false;
            }

            if (!options.IsOptionDefined(optionKey, localScopeOnly: false))
            {
                return(defaultOption);
            }

            return(options.GetOptionValue(optionKey));
Пример #6
0
        /// <summary>
        /// Determines whether two <see cref="EditorOptionKey&lt;T&gt;"/> objects are the same.
        /// </summary>
        /// <param name="obj">The object to be compared.</param>
        /// <returns><c>true</c> if the objects are the same, otherwise <c>false</c>.</returns>
        public override bool Equals(object obj)
        {
            if (obj is EditorOptionKey <T> )
            {
                EditorOptionKey <T> other = (EditorOptionKey <T>)obj;
                return(other.Name == this.Name);
            }

            return(false);
        }
Пример #7
0
        private void SaveOption <T>(EditorOptionKey <T> key)
        {
            string collection = GetCollectionName(key.Name);
            string property   = GetPropertyName(key.Name);

            EnsureCollectionExists(collection);

            var value = _options.GetOptionValue(key);

            _store.SetString(collection, property, value.ToString());
        }
 public T GetOptionValue <T>(EditorOptionKey <T> key)
 {
     if (key.Equals(DefaultOptions.ConvertTabsToSpacesOptionId))
     {
         return((T)(object)true);
     }
     else if (key.Equals(DefaultOptions.IndentSizeOptionId))
     {
         return((T)(object)4);
     }
     throw new InvalidOperationException();
 }
        private Brush GetBrush(EditorOptionKey <Color> key)
        {
            Brush brush = null;

            Color color = base.TextViewHost.TextView.Options.GetOptionValue(key);

            if (color.A != 0)
            {
                brush = new SolidColorBrush(color);
                brush.Freeze();
            }

            return(brush);
        }
        private void AddPreviewEntry(ContextMenu context, EditorOptionKey <int> key, string label)
        {
            MenuItem item = new MenuItem();

            item.IsCheckable = true;
            item.IsChecked   = base.TextViewHost.TextView.Options.GetOptionValue(key) != 0;
            item.Header      = label;
            item.Click      += delegate
            {
                base.TextViewHost.TextView.Options.SetOptionValue(key, item.IsChecked ? 7 : 0);
                _provider.SaveOption(base.TextViewHost.TextView.Options, key.Name);
            };
            context.Items.Add(item);
        }
Пример #11
0
        public T GetOptionValue <T>(EditorOptionKey <T> key)
        {
            if (key.Equals(DefaultOptions.ConvertTabsToSpacesOptionId))
            {
                return((T)(object)_convertTabsToSpaces);
            }
            else if (key.Equals(DefaultOptions.TabSizeOptionId))
            {
                return((T)(object)_tabSize);
            }
            else if (key.Equals(DefaultOptions.IndentSizeOptionId))
            {
                return((T)(object)_indentSize);
            }

            throw new ArgumentException("key", "unexpected key");
        }
Пример #12
0
        public bool IsOptionDefined <T>(EditorOptionKey <T> key, bool localScopeOnly)
        {
            if (localScopeOnly && (_parent != null))    //All options with valid definitions are set for the root.
            {
                return(OptionsSetLocally.Contains(key.Name));
            }

            EditorOptionDefinition definition = _factory.GetOptionDefinition(key.Name);

            if ((definition != null) &&
                (Scope == null || definition.IsApplicableToScope(Scope)) &&
                definition.ValueType.IsEquivalentTo(typeof(T)))
            {
                return(true);
            }

            return(false);
        }
Пример #13
0
 public T GetOptionValue <T>(EditorOptionKey <T> key)
 {
     if (key.Equals(DefaultWpfViewOptions.EnableSimpleGraphicsId))
     {
         return((T)(object)true);
     }
     if (key.Equals(DefaultWpfViewOptions.UseReducedOpacityForHighContrastOptionId))
     {
         return((T)(object)true);
     }
     if (key.Equals(DefaultOptions.ReplicateNewLineCharacterOptionId))
     {
         return((T)(object)ReplicateNewLineCharacterOption);
     }
     if (key.Equals(DefaultOptions.NewLineCharacterOptionId))
     {
         return((T)(object)NewLineCharacterOption);
     }
     throw new NotImplementedException(key.ToString());
 }
Пример #14
0
        public async Task ResetHostSettingsAsync(CancellationToken cancellationToken)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            // Suggestion mode defaults to on for debugger views, and off for other views.
            await TestServices.Editor.SetUseSuggestionModeAsync(forDebuggerTextView : true, true, cancellationToken);

            await TestServices.Editor.SetUseSuggestionModeAsync(forDebuggerTextView : false, false, cancellationToken);

            // Make sure responsive completion doesn't interfere if integration tests run slowly.
            var editorOptionsFactory = await GetComponentModelServiceAsync <IEditorOptionsFactoryService>(cancellationToken);

            var options = editorOptionsFactory.GlobalOptions;

            options.SetOptionValue(DefaultOptions.ResponsiveCompletionOptionId, false);

            var latencyGuardOptionKey = new EditorOptionKey <bool>("EnableTypingLatencyGuard");

            options.SetOptionValue(latencyGuardOptionKey, false);
        }
Пример #15
0
        public bool IsUseSuggestionModeOn()
        {
            var asyncCompletionService = (AsyncCompletionService)GetComponentModelService <IAsyncCompletionService>();

            return(ExecuteOnActiveView(textView =>
            {
                var featureServiceFactory = GetComponentModelService <IFeatureServiceFactory>();
                var subjectBuffer = GetBufferContainingCaret(textView);
                if (asyncCompletionService.GetTestAccessor().UseLegacyCompletion(featureServiceFactory, textView, subjectBuffer))
                {
                    return GetComponentModelService <VisualStudioWorkspace>().Options.GetOption(EditorCompletionOptions.UseSuggestionMode);
                }
                else
                {
                    var options = textView.Options.GlobalOptions;
                    EditorOptionKey <bool> optionKey;
                    Option <bool> roslynOption;
                    if (IsDebuggerTextView(textView))
                    {
                        optionKey = new EditorOptionKey <bool>(PredefinedCompletionNames.SuggestionModeInDebuggerCompletionOptionName);
                        roslynOption = EditorCompletionOptions.UseSuggestionMode_Debugger;
                    }
                    else
                    {
                        optionKey = new EditorOptionKey <bool>(PredefinedCompletionNames.SuggestionModeInCompletionOptionName);
                        roslynOption = EditorCompletionOptions.UseSuggestionMode;
                    }

                    if (!options.IsOptionDefined(optionKey, localScopeOnly: false))
                    {
                        return roslynOption.DefaultValue;
                    }

                    return options.GetOptionValue(optionKey);
                }
            }));

            bool IsDebuggerTextView(IWpfTextView textView)
            => textView.Roles.Contains("DEBUGVIEW");
        }
Пример #16
0
 public T GetOptionValue <T>(EditorOptionKey <T> key) => (T)GetOptionValue(key.Name);
Пример #17
0
 public OptionDefinition(string contentType, EditorOptionKey <T> option, T defaultValue)
     : base(option)
 {
     ContentType  = contentType;
     DefaultValue = defaultValue;
 }
Пример #18
0
 public bool ClearOptionValue <T>(EditorOptionKey <T> key)
 {
     return(ClearOptionValue(key.Name));
 }
Пример #19
0
 public void SetOptionValue <T>(EditorOptionKey <T> key, T value)
 {
     SetOptionValue(key.Name, value);
 }
Пример #20
0
 public bool IsOptionDefined <T>(EditorOptionKey <T> key, bool localScopeOnly)
 {
     return(IsOptionDefined(key.Name, localScopeOnly));
 }
Пример #21
0
 public T GetOptionValue <T>(string contentType, EditorOptionKey <T> option) => (T)GetOptionValue(contentType, option.Name) !;
Пример #22
0
 public bool ClearOptionValue <T>(EditorOptionKey <T> key)
 {
     throw new NotImplementedException();
 }
Пример #23
0
 public bool ClearOptionValue <T>(EditorOptionKey <T> key) => ClearOptionValue(key.Name);
Пример #24
0
 private T GetOption <T>(EditorOptionKey <T> key)
 {
     return(OptionsService.GlobalOptions.GetOptionValue(key));
 }
Пример #25
0
 public void SetOptionValue <T>(EditorOptionKey <T> key, T value)
 {
     throw new NotImplementedException();
 }
Пример #26
0
 public bool IsOptionDefined <T>(EditorOptionKey <T> key, bool localScopeOnly)
 {
     throw new NotImplementedException();
 }
Пример #27
0
 public bool HasOption <T>(string contentType, EditorOptionKey <T> option) => HasOption(contentType, option.Name);
Пример #28
0
 public bool ClearOptionValue <T>(EditorOptionKey <T> key)
 {
     return(_options.Remove(key.Name));
 }
Пример #29
0
 public void SetOptionValue <T>(string contentType, EditorOptionKey <T> option, T value) => SetOptionValue(contentType, option.Name, value);
Пример #30
0
 public T GetOptionValue <T>(EditorOptionKey <T> key)
 {
     return((T)GetOptionValue(key.Name));
 }