Skip to content

Commit

Permalink
Merge pull request #1 from jonimat/vs2019-update
Browse files Browse the repository at this point in the history
VS2019 update
  • Loading branch information
jonimat authored Sep 24, 2020
2 parents 0594788 + 637d519 commit 517d706
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 56 deletions.
1 change: 1 addition & 0 deletions AutoDoxyDoc/AutoDoxyDoc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<DependentUpon>AbbreviationsEditorDialog.cs</DependentUpon>
</Compile>
<Compile Include="DoxygenConfig.cs" />
<Compile Include="DoxygenConfigService.cs" />
<Compile Include="DoxygenGenerator.cs" />
<Compile Include="GenerateComment.cs" />
<Compile Include="AutoDoxyDocPackage.cs" />
Expand Down
22 changes: 20 additions & 2 deletions AutoDoxyDoc/AutoDoxyDocPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ namespace AutoDoxyDoc
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About
[ProvideMenuResource("Menus.ctmenu", 1)]
[Guid(AutoDoxyDocPackage.PackageGuidString)]
[ProvideAutoLoad(UIContextGuids.SolutionExists/*, PackageAutoLoadFlags.BackgroundLoad*/)] // TODO: Enable background load. It is currently disabled because for some reason the package doesn't always load.
[ProvideService(typeof(DoxygenConfigService), IsAsyncQueryable = true)]
//[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)] // TODO: Enable background load. It is currently disabled because for some reason the package doesn't always load.
//[ProvideAutoLoad(VSConstants.UICONTEXT.NoSolution_string, PackageAutoLoadFlags.BackgroundLoad)]
//[ProvideAutoLoad(UIContextGuids80.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
//[ProvideAutoLoad(UIContextGuids.SolutionExists)] // TODO: Should be changed to async load but for some reason it is not loaded properly in that case.
[ProvideOptionPage(typeof(OptionsPage), "AutoDoxyDoc", "General", 0, 0, true)]
[ProvideProfileAttribute(typeof(OptionsPage), "AutoDoxyDoc", "AutoDoxyDoc Settings", 106, 107, isToolsOptionPage: true, DescriptionResourceID = 108)]
Expand Down Expand Up @@ -70,17 +73,32 @@ public AutoDoxyDocPackage()
/// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
AddService(typeof(DoxygenConfigService), CreateDoxygenConfigServiceAsync, true);

// When initialized asynchronously, the current thread may be a background thread at this point.
// Do any initialization that requires the UI thread after switching to the UI thread.
await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

// Load Doxygen configuration.
OptionsPage page = (OptionsPage)GetDialogPage(typeof(OptionsPage));
DoxygenConfig.Instance.LoadSettings(page);

var configService = await GetServiceAsync(typeof(DoxygenConfigService)) as DoxygenConfigService;

if (configService != null)
{
configService.Config.LoadSettings(page);
}

await GenerateComment.InitializeAsync(this);
}

private async Task<object> CreateDoxygenConfigServiceAsync(IAsyncServiceContainer container, CancellationToken cancellationToken, Type serviceType)
{
var svc = new DoxygenConfigService();
await svc.InitializeAsync(this, cancellationToken);
return svc;
}

#endregion
}
}
9 changes: 8 additions & 1 deletion AutoDoxyDoc/CompletionHandlerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public void VsTextViewCreated(IVsTextView textViewAdapter)
{
try
{
var configService = ServiceProvider.GetService(typeof(DoxygenConfigService)) as DoxygenConfigService;

if (configService == null)
{
return;
}

IWpfTextView textView = this.AdapterService.GetWpfTextView(textViewAdapter);
if (textView == null)
{
Expand All @@ -43,7 +50,7 @@ public void VsTextViewCreated(IVsTextView textViewAdapter)
{
ThreadHelper.ThrowIfNotOnUIThread();
var dte = ServiceProvider.GetService(typeof(DTE)) as DTE;
return new DoxygenCompletionCommandHandler(textViewAdapter, textView, this, dte);
return new DoxygenCompletionCommandHandler(textViewAdapter, textView, this, dte, configService);
};

textView.Properties.GetOrCreateSingletonProperty(createCommandHandler);
Expand Down
13 changes: 12 additions & 1 deletion AutoDoxyDoc/CompletionSourceProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Operations;
using Microsoft.VisualStudio.Utilities;
Expand All @@ -17,14 +18,24 @@ public class CompletionSourceProvider : ICompletionSourceProvider
[Import]
internal IGlyphService GlyphService { get; set; }

[Import]
internal SVsServiceProvider ServiceProvider { get; set; }

/// <summary>
/// Tries to create a Doxygen completion source.
/// </summary>
/// <param name="textBuffer"></param>
/// <returns></returns>
public ICompletionSource TryCreateCompletionSource(ITextBuffer textBuffer)
{
return new DoxygenCompletionSource(this, textBuffer);
var configService = ServiceProvider.GetService(typeof(DoxygenConfigService)) as DoxygenConfigService;

if (configService == null)
{
return null;
}

return new DoxygenCompletionSource(this, textBuffer, configService);
}
}
}
26 changes: 16 additions & 10 deletions AutoDoxyDoc/DoxygenCompletionCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ public class DoxygenCompletionCommandHandler : IOleCommandTarget
/// <param name="textView"></param>
/// <param name="provider"></param>
/// <param name="dte"></param>
public DoxygenCompletionCommandHandler(IVsTextView textViewAdapter, IWpfTextView textView, CompletionHandlerProvider provider, DTE dte)
public DoxygenCompletionCommandHandler(IVsTextView textViewAdapter, IWpfTextView textView, CompletionHandlerProvider provider, DTE dte, DoxygenConfigService configService)
{
this.m_textView = textView;
this.m_provider = provider;
this.m_dte = dte;
m_textView = textView;
m_provider = provider;
m_dte = dte;
m_configService = configService;

// Add the command to the command chain.
if (textViewAdapter != null &&
Expand All @@ -41,12 +42,17 @@ public DoxygenCompletionCommandHandler(IVsTextView textViewAdapter, IWpfTextView
textViewAdapter.AddCommandFilter(this, out m_nextCommandHandler);
}

m_generator = new DoxygenGenerator(m_config);
m_generator = new DoxygenGenerator(m_configService);

m_config.ConfigChanged += onDoxygenConfigChanged;
m_configService.Config.ConfigChanged += onDoxygenConfigChanged;
onDoxygenConfigChanged(this, EventArgs.Empty);
}

~DoxygenCompletionCommandHandler()
{
m_configService.Config.ConfigChanged -= onDoxygenConfigChanged;
}

public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
{
ThreadHelper.ThrowIfNotOnUIThread();
Expand Down Expand Up @@ -128,7 +134,7 @@ public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pv
int retVal = m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);

// Start auto-completion session for doxygen tags and parameter names.
if (!IsAutoCompletionActive() && (typedChar == m_config.TagChar || typedChar == '['))
if (!IsAutoCompletionActive() && (typedChar == m_configService.Config.TagChar || typedChar == '['))
{
string currentLine = m_textView.TextSnapshot.GetLineFromPosition(
m_textView.Caret.Position.BufferPosition.Position).GetText();
Expand Down Expand Up @@ -239,7 +245,7 @@ private void NewCommentLine(string currentLine)
{
if (m_regexTagSection.IsMatch(currentLine))
{
extraIndent = m_config.TagIndentation;
extraIndent = m_configService.Config.TagIndentation;
break;
}

Expand Down Expand Up @@ -455,7 +461,7 @@ private static bool IsInsideComment(string line)
/// <param name="e"></param>
private void onDoxygenConfigChanged(object sender, EventArgs e)
{
m_regexTagSection = new Regex(@"\*\s+\" + m_config.TagChar + @"([a-z]+)\s+(.+)$", RegexOptions.Compiled);
m_regexTagSection = new Regex(@"\*\s+\" + m_configService.Config.TagChar + @"([a-z]+)\s+(.+)$", RegexOptions.Compiled);
}

//! Next command handler.
Expand All @@ -474,7 +480,7 @@ private void onDoxygenConfigChanged(object sender, EventArgs e)
private DTE m_dte;

//! Doxygen config.
DoxygenConfig m_config = DoxygenConfig.Instance;
DoxygenConfigService m_configService;

//! Doxygen generator.
DoxygenGenerator m_generator;
Expand Down
23 changes: 19 additions & 4 deletions AutoDoxyDoc/DoxygenCompletionSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ public class DoxygenCompletionSource : ICompletionSource
/// </summary>
/// <param name="sourceProvider"></param>
/// <param name="textBuffer"></param>
public DoxygenCompletionSource(CompletionSourceProvider sourceProvider, ITextBuffer textBuffer)
public DoxygenCompletionSource(CompletionSourceProvider sourceProvider, ITextBuffer textBuffer, DoxygenConfigService configService)
{
m_sourceProvider = sourceProvider;
m_textBuffer = textBuffer;
m_configService = configService;
CreateCompletionLists();

m_configService.Config.ConfigChanged += onConfigChanged;
}

/// <summary>
Expand Down Expand Up @@ -68,7 +69,7 @@ void ICompletionSource.AugmentCompletionSession(ICompletionSession session, ILis
compList = m_compListDir;
}
// Generic doxygen tags.
else if (prevChar == '@')
else if (prevChar == m_configService.Config.TagChar)
{
compList = m_compListTag;
}
Expand Down Expand Up @@ -96,6 +97,7 @@ public void Dispose()
{
if (!m_disposed)
{
m_configService.Config.ConfigChanged -= onConfigChanged;
GC.SuppressFinalize(this);
m_disposed = true;
}
Expand Down Expand Up @@ -166,16 +168,29 @@ private void CreateCompletionLists()
/// <param name="image">Image for the completion listbox.</param>
private void AddCompletionTag(string name, ImageSource image)
{
string tag = DoxygenConfig.Instance.TagChar + name;
string tag = m_configService.Config.TagChar + name;
m_compListTag.Add(new Completion(tag, tag, string.Empty, image, string.Empty));
}

/// <summary>
/// Called when the Doxygen configuration has changed.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void onConfigChanged(object sender, EventArgs e)
{
CreateCompletionLists();
}

//! Completion source provider.
private CompletionSourceProvider m_sourceProvider;

//! Text buffer.
private ITextBuffer m_textBuffer;

//! Doxygen configuration service.
private DoxygenConfigService m_configService;

// List of tag completions.
private List<Completion> m_compListTag = new List<Completion>();

Expand Down
5 changes: 0 additions & 5 deletions AutoDoxyDoc/DoxygenConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ public char TagChar
public string ReturnBooleanDescFormat { get; set; } = "True if {0}. False if not.";
public string ParamBooleanFormat { get; set; } = "If true, {0}. Otherwise not {0}.";

/// <summary>
/// Singleton instance.
/// </summary>
public static DoxygenConfig Instance { get; } = new DoxygenConfig();

/// <summary>
/// Constructor.
/// </summary>
Expand Down
34 changes: 34 additions & 0 deletions AutoDoxyDoc/DoxygenConfigService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.VisualStudio.Shell;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Task = System.Threading.Tasks.Task;

namespace AutoDoxyDoc
{
/// <summary>
/// Doxygen configuration service for accessing Doxygen configuration.
/// </summary>
public class DoxygenConfigService
{
/// <summary>
/// Global doxygen configuration.
/// </summary>
public DoxygenConfig Config { get; private set; }

/// <summary>
/// Initializes the config service asynchronously.
/// </summary>
/// <param name="provider"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task InitializeAsync(IAsyncServiceProvider provider, CancellationToken cancellationToken)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
Config = new DoxygenConfig();
}
}
}
Loading

0 comments on commit 517d706

Please sign in to comment.