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"); }
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); } } }
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); }); } }
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)); }
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));
/// <summary> /// Determines whether two <see cref="EditorOptionKey<T>"/> 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); }
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); }
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"); }
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); }
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()); }
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); }
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"); }
public T GetOptionValue <T>(EditorOptionKey <T> key) => (T)GetOptionValue(key.Name);
public OptionDefinition(string contentType, EditorOptionKey <T> option, T defaultValue) : base(option) { ContentType = contentType; DefaultValue = defaultValue; }
public bool ClearOptionValue <T>(EditorOptionKey <T> key) { return(ClearOptionValue(key.Name)); }
public void SetOptionValue <T>(EditorOptionKey <T> key, T value) { SetOptionValue(key.Name, value); }
public bool IsOptionDefined <T>(EditorOptionKey <T> key, bool localScopeOnly) { return(IsOptionDefined(key.Name, localScopeOnly)); }
public T GetOptionValue <T>(string contentType, EditorOptionKey <T> option) => (T)GetOptionValue(contentType, option.Name) !;
public bool ClearOptionValue <T>(EditorOptionKey <T> key) { throw new NotImplementedException(); }
public bool ClearOptionValue <T>(EditorOptionKey <T> key) => ClearOptionValue(key.Name);
private T GetOption <T>(EditorOptionKey <T> key) { return(OptionsService.GlobalOptions.GetOptionValue(key)); }
public void SetOptionValue <T>(EditorOptionKey <T> key, T value) { throw new NotImplementedException(); }
public bool IsOptionDefined <T>(EditorOptionKey <T> key, bool localScopeOnly) { throw new NotImplementedException(); }
public bool HasOption <T>(string contentType, EditorOptionKey <T> option) => HasOption(contentType, option.Name);
public bool ClearOptionValue <T>(EditorOptionKey <T> key) { return(_options.Remove(key.Name)); }
public void SetOptionValue <T>(string contentType, EditorOptionKey <T> option, T value) => SetOptionValue(contentType, option.Name, value);
public T GetOptionValue <T>(EditorOptionKey <T> key) { return((T)GetOptionValue(key.Name)); }