Skip to content

Commit

Permalink
- Fixed issue #3
Browse files Browse the repository at this point in the history
+ Shows method parameter of current expression in quick info, optionally
- Fixed an issue of code formatting in Super Quick Info which was causing VS to crash
- Fixed an issue that empty Enum type could crash VS in Super Quick Info
  • Loading branch information
wmjordan committed Feb 4, 2018
1 parent f280c2c commit 46a1587
Show file tree
Hide file tree
Showing 14 changed files with 328 additions and 135 deletions.
52 changes: 41 additions & 11 deletions Codist/Classifiers/CodeTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,33 @@ public class CodeTaggerProvider : IViewTaggerProvider
[Import]
internal IBufferTagAggregatorFactoryService Aggregator = null;

ITagAggregator<IClassificationTag> _Tagger;
ITextView _TextView;
CodeTagger _CodeTagger;

public ITagger<T> CreateTagger<T>(ITextView textView, ITextBuffer buffer) where T : ITag
{
var tagger = Aggregator.CreateTagAggregator<IClassificationTag>(buffer);
textView.Closed += (s, args) => { tagger.Dispose(); };
_Tagger = Aggregator.CreateTagAggregator<IClassificationTag>(buffer);
_TextView = textView;
textView.Closed += TextViewClosed;
var tags = textView.Properties.GetOrCreateSingletonProperty(() => new TaggerResult());
var codeTagger = new CodeTagger(ClassificationRegistry, tagger, tags, CodeTagger.GetCodeType(textView.TextBuffer.ContentType));
return codeTagger as ITagger<T>;
_CodeTagger = new CodeTagger(ClassificationRegistry, _Tagger, tags, CodeTagger.GetCodeType(textView.TextBuffer.ContentType));
return _CodeTagger as ITagger<T>;
}

void TextViewClosed(object sender, EventArgs args) {
_Tagger.Dispose();
_TextView.Closed -= TextViewClosed;
_CodeTagger.Dispose();
}
}

enum CodeType
{
None, CSharp, Markup
}

sealed class CodeTagger : ITagger<ClassificationTag>
sealed class CodeTagger : ITagger<ClassificationTag>, IDisposable
{
static ClassificationTag[] __CommentClassifications;
//static ClassificationTag _exitClassification;
Expand Down Expand Up @@ -78,11 +89,7 @@ internal CodeTagger(IClassificationTypeRegistryService registry, ITagAggregator<
_Aggregator = aggregator;
_Tags = tags;
_CodeType = codeType;
_Aggregator.BatchedTagsChanged += (s, args) => {
if (Margin != null) {
Margin.InvalidateVisual();
}
};
_Aggregator.BatchedTagsChanged += AggregateorBatchedTagsChanged;
}

internal FrameworkElement Margin { get; set; }
Expand Down Expand Up @@ -290,6 +297,29 @@ static bool Matches(SnapshotSpan span, string text) {
}
return true;
}
}

void AggregateorBatchedTagsChanged(object sender, EventArgs args) {
if (Margin != null) {
Margin.InvalidateVisual();
}
}

#region IDisposable Support
private bool disposedValue = false;

void Dispose(bool disposing) {
if (!disposedValue) {
if (disposing) {
_Aggregator.BatchedTagsChanged -= AggregateorBatchedTagsChanged;
}
disposedValue = true;
}
}

public void Dispose() {
Dispose(true);
}
#endregion
}

}
57 changes: 49 additions & 8 deletions Codist/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
using System.Text.RegularExpressions;
using System.Reflection;
using System.ComponentModel;
using System.Threading;

namespace Codist
{
sealed class Config
{
static DateTime LastSaved;
static DateTime _LastSaved, _LastLoaded;
static int _LoadingConfig;

public static readonly string ConfigPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + Constants.NameOfMe + "\\Config.json";
public static Config Instance = InitConfig();
Expand All @@ -30,7 +32,7 @@ sealed class Config
[DefaultValue(true)]
public bool MarkLineNumbers { get; set; } = true;

[DefaultValue(true)]
[DefaultValue(QuickInfoOptions.Attributes | QuickInfoOptions.BaseType | QuickInfoOptions.Interfaces | QuickInfoOptions.NumericValues)]
public QuickInfoOptions QuickInfoOptions { get; set; } = QuickInfoOptions.Attributes | QuickInfoOptions.BaseType | QuickInfoOptions.Interfaces | QuickInfoOptions.NumericValues;

public double TopSpace {
Expand Down Expand Up @@ -67,9 +69,23 @@ public static Config InitConfig() {
}

public static void LoadConfig(string configPath) {
Instance = InternalLoadConfig(configPath);
ConfigLoaded?.Invoke(Instance, EventArgs.Empty);
ConfigUpdated?.Invoke(Instance, EventArgs.Empty);
//HACK: prevent redundant load operations issued by configuration pages
if (_LastLoaded.AddSeconds(2) > DateTime.Now
|| Interlocked.Exchange(ref _LoadingConfig, 1) != 0) {
return;
}
try {
Instance = InternalLoadConfig(configPath);
ConfigLoaded?.Invoke(Instance, EventArgs.Empty);
ConfigUpdated?.Invoke(Instance, EventArgs.Empty);
}
catch(Exception ex) {
Debug.WriteLine(ex.ToString());
Instance = GetDefaultConfig();
}
finally {
_LoadingConfig = 0;
}
}

static Config InternalLoadConfig(string configPath) {
Expand Down Expand Up @@ -108,6 +124,8 @@ static Config InternalLoadConfig(string configPath) {
}
}
MergeDefaultXmlCodeStyles(xcs);
_LastLoaded = DateTime.Now;
Debug.WriteLine("Config loaded");
return config;
}

Expand All @@ -124,7 +142,7 @@ public void Reset() {

public void SaveConfig(string path) {
//HACK: prevent redundant save operations issued by configuration pages
if (LastSaved.AddSeconds(2) > DateTime.Now) {
if (_LastSaved.AddSeconds(2) > DateTime.Now) {
return;
}
path = path ?? ConfigPath;
Expand All @@ -135,7 +153,8 @@ public void SaveConfig(string path) {
}
File.WriteAllText(path, JsonConvert.SerializeObject(this, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter()));
if (path == ConfigPath) {
LastSaved = DateTime.Now;
_LastSaved = _LastLoaded = DateTime.Now;
Debug.WriteLine("Config saved");
ConfigUpdated?.Invoke(this, EventArgs.Empty);
}
}
Expand All @@ -148,6 +167,7 @@ internal void FireConfigChangedEvent() {
ConfigUpdated?.Invoke(this, EventArgs.Empty);
}
static Config GetDefaultConfig() {
_LastLoaded = DateTime.Now;
var c = new Config();
InitDefaultLabels(c.Labels);
c.CommentStyles.AddRange(GetDefaultCommentStyles());
Expand Down Expand Up @@ -290,6 +310,18 @@ internal Color BackColor {
internal StyleBase Clone() {
return (StyleBase)MemberwiseClone();
}
internal void CopyTo(StyleBase style) {
style.Bold = Bold;
style.Italic = Italic;
style.OverLine = OverLine;
style.Underline = Underline;
style.StrikeThrough = StrikeThrough;
style.FontSize = FontSize;
style.BackgroundEffect = BackgroundEffect;
style.Font = Font;
style._foreColor = _foreColor;
style._backColor = _backColor;
}
internal void Reset() {
Bold = Italic = OverLine = Underline = StrikeThrough = null;
FontSize = 0;
Expand Down Expand Up @@ -432,6 +464,14 @@ public bool IgnoreCase {
public CommentLabel Clone() {
return (CommentLabel)MemberwiseClone();
}
public void CopyTo(CommentLabel label) {
label.AllowPunctuationDelimiter = AllowPunctuationDelimiter;
label.StyleApplication = StyleApplication;
label.StyleID = StyleID;
label._label = _label;
label._labelLength = _labelLength;
label._stringComparison = _stringComparison;
}
}

public enum BrushEffect
Expand All @@ -455,6 +495,7 @@ public enum QuickInfoOptions
Interfaces = 1 << 5,
InterfacesInheritence = 1 << 6,
NumericValues = 1 << 7,
String = 1 << 8
String = 1 << 8,
Parameter = 1 << 9
}
}
25 changes: 14 additions & 11 deletions Codist/Margins/CodeMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@ class CodeMargin : Canvas, IWpfTextViewMargin
/// </summary>
public const string MarginName = nameof(CodeMargin);

readonly CodeMarginElement _commentMarginElement;
readonly ITagAggregator<ClassificationTag> _commentTagAggregator;
readonly CodeMarginElement _CodeMarginElement;
readonly ITagAggregator<ClassificationTag> _CodeTagAggregator;
readonly IWpfTextViewHost _TextView;
bool isDisposed;

/// <summary>
/// Initializes a new instance of the <see cref="CodeMargin"/> class for a given <paramref name="textView"/>.
/// </summary>
/// <param name="textView">The <see cref="IWpfTextView"/> to attach the margin to.</param>
public CodeMargin(IWpfTextViewHost textView, IVerticalScrollBar scrollBar, CodeMarginFactory container) {
if (textView == null)
throw new ArgumentNullException("textView");
_TextView = textView ?? throw new ArgumentNullException("textView");
_CodeTagAggregator = container.ViewTagAggregatorFactoryService.CreateTagAggregator<ClassificationTag>(textView.TextView);
_CodeMarginElement = new CodeMarginElement(textView.TextView, container, _CodeTagAggregator, scrollBar);
textView.Closed += TextView_Closed;
}

_commentTagAggregator = container.ViewTagAggregatorFactoryService.CreateTagAggregator<ClassificationTag>(textView.TextView);
_commentMarginElement = new CodeMarginElement(textView.TextView, container, _commentTagAggregator, scrollBar);
textView.Closed += (sender, e) => {
_commentTagAggregator.Dispose();
};
private void TextView_Closed(object sender, EventArgs e) {
_CodeTagAggregator.Dispose();
_CodeMarginElement.Dispose();
}

#region IWpfTextViewMargin
Expand All @@ -46,7 +48,7 @@ public FrameworkElement VisualElement {
// the margin.
get {
ThrowIfDisposed();
return _commentMarginElement;
return _CodeMarginElement;
}
}

Expand All @@ -68,7 +70,7 @@ public double MarginSize {
get {
ThrowIfDisposed();

return _commentMarginElement.ActualHeight;
return _CodeMarginElement.ActualHeight;
}
}

Expand Down Expand Up @@ -104,6 +106,7 @@ public ITextViewMargin GetTextViewMargin(string marginName) {
/// </summary>
public void Dispose() {
if (!isDisposed) {
_TextView.Closed -= TextView_Closed;
GC.SuppressFinalize(this);
isDisposed = true;
}
Expand Down
Loading

0 comments on commit 46a1587

Please sign in to comment.