From 3f525af448bd6fb1e1b8cb4a24cf7bc46efb6cd6 Mon Sep 17 00:00:00 2001 From: Rahul Sridhar Date: Wed, 25 Sep 2024 16:42:26 -0700 Subject: [PATCH] Modify InitializeTrackedWorkspaceAsync to recursively walk the project structure --- CodeiumVS.sln | 4 ++-- CodeiumVS/LanguageServer/LanguageServer.cs | 25 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CodeiumVS.sln b/CodeiumVS.sln index cf092f6..8d5c8ea 100644 --- a/CodeiumVS.sln +++ b/CodeiumVS.sln @@ -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 diff --git a/CodeiumVS/LanguageServer/LanguageServer.cs b/CodeiumVS/LanguageServer/LanguageServer.cs index c66ebd7..e40e814 100644 --- a/CodeiumVS/LanguageServer/LanguageServer.cs +++ b/CodeiumVS/LanguageServer/LanguageServer.cs @@ -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 processedProjects = new List(); + + 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); @@ -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 RequestCommandAsync(string command, object data,