Skip to content

Commit

Permalink
Merge pull request #123 from Exafunction/rahul/recursively-find-projects
Browse files Browse the repository at this point in the history
Modify InitializeTrackedWorkspaceAsync to recursively walk the project
  • Loading branch information
fortenforge authored Sep 27, 2024
2 parents 76894aa + 3f525af commit 547ee2b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CodeiumVS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Debug|Any CPU.Build.0 = Release|Any CPU
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Debug|arm64.ActiveCfg = Debug|arm64
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Debug|arm64.Build.0 = Debug|arm64
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Debug|x86.ActiveCfg = Debug|x86
Expand Down
25 changes: 21 additions & 4 deletions CodeiumVS/LanguageServer/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -733,15 +733,19 @@ private async Task InitializeTrackedWorkspaceAsync()
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
DTE dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
await _package.LogAsync($"Number of projects: {dte.Solution.Projects.Count}");
foreach (EnvDTE.Project project in dte.Solution.Projects)
await _package.LogAsync($"Number of top-level projects: {dte.Solution.Projects.Count}");

List<string> processedProjects = new List<string>();

async Task ProcessProjectAsync(EnvDTE.Project project)
{
try
{
string projectFullName = project.FullName;
await _package.LogAsync($"Project Full Name: {projectFullName}");
if (!string.IsNullOrEmpty(projectFullName))
if (!string.IsNullOrEmpty(projectFullName) && !processedProjects.Contains(projectFullName))
{
processedProjects.Add(projectFullName);
string projectDir = Path.GetDirectoryName(projectFullName);
await _package.LogAsync($"Project Dir: {projectDir}");
AddTrackedWorkspaceResponse response = await AddTrackedWorkspaceAsync(projectDir);
Expand All @@ -750,13 +754,26 @@ private async Task InitializeTrackedWorkspaceAsync()
_initializedWorkspace = true;
}
}

// Process sub-projects (e.g., project references)
foreach (EnvDTE.ProjectItem item in project.ProjectItems)
{
if (item.SubProject != null)
{
await ProcessProjectAsync(item.SubProject);
}
}
}
catch (Exception ex)
{
await _package.LogAsync("Error: Failed to initialize tracked workspace: " + ex.Message);
continue;
}
}

foreach (EnvDTE.Project project in dte.Solution.Projects)
{
await ProcessProjectAsync(project);
}
}

private async Task<T?> RequestCommandAsync<T>(string command, object data,
Expand Down

0 comments on commit 547ee2b

Please sign in to comment.