Skip to content

Commit

Permalink
Added logging when solution (workspace) is changed. (#116)
Browse files Browse the repository at this point in the history
Improved logging for SolutionService.
  • Loading branch information
PiotrKarczmarz authored Oct 16, 2024
1 parent d22b8b7 commit e742b5e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/Cody.VisualStudio/CodyPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void InitializeServices()
Logger = loggerFactory.Create();

var vsSolution = this.GetService<SVsSolution, IVsSolution>();
SolutionService = new SolutionService(vsSolution);
SolutionService = new SolutionService(vsSolution, Logger);
VersionService = loggerFactory.GetVersionService();
VsVersionService = new VsVersionService(Logger);

Expand Down Expand Up @@ -420,6 +420,7 @@ private void UpdateCurrentWorkspaceFolder()
Uris = new List<string> { solutionUri }
};
AgentService.WorkspaceFolderDidChange(workspaceFolderEvent);
Logger.Debug($"Workspace updated:{solutionUri}");

if (DocumentsSyncService == null)
{
Expand Down
21 changes: 14 additions & 7 deletions src/Cody.VisualStudio/Services/SolutionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,40 @@
using System;
using System.Diagnostics;
using System.IO;
using Cody.Core.Logging;

namespace Cody.VisualStudio.Services
{
public class SolutionService : ISolutionService
{
private IVsSolution solutionService;
private readonly IVsSolution _vsSolution;
private readonly ILog _logger;

public SolutionService(IVsSolution solutionService)
public SolutionService(IVsSolution solutionService, ILog logger)
{
this.solutionService = solutionService;
_vsSolution = solutionService;
_logger = logger;
}

public bool IsSolutionOpen()
{
solutionService.GetProperty((int)__VSPROPID.VSPROPID_IsSolutionOpen, out object value);
return value is bool isSolutionOpen && isSolutionOpen;
_vsSolution.GetProperty((int)__VSPROPID.VSPROPID_IsSolutionOpen, out object value);
var isOpened = value is bool isSolutionOpen && isSolutionOpen;

_logger.Debug($"Is solution opened:{isOpened}");

return isOpened;
}

public string GetSolutionDirectory()
{
solutionService.GetProperty((int)__VSPROPID.VSPROPID_SolutionFileName, out object value);
_vsSolution.GetProperty((int)__VSPROPID.VSPROPID_SolutionFileName, out object value);
var solutionDir = Path.GetDirectoryName(value as string);

// Use user directory if solution directory is null.
var userDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

Debug.WriteLine(solutionDir, "GetSolutionDirectory");
_logger.Debug($"'{solutionDir}'");

return new Uri(solutionDir ?? userDir).ToString();
}
Expand Down

0 comments on commit e742b5e

Please sign in to comment.