Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
saranshsaini committed Jan 22, 2025
1 parent db2f0d4 commit b304570
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
47 changes: 19 additions & 28 deletions CodeiumVS/LanguageServer/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ private async Task InitializeTrackedWorkspaceAsync()
}
}

var inputProjectsToIndex = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var inputFilesToIndex = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
string projectListPath = _package.SettingsPage.IndexingFilesListPath.Trim();
try
{
Expand All @@ -767,18 +767,22 @@ private async Task InitializeTrackedWorkspaceAsync()
string trimmedLine = line.Trim();
if (!string.IsNullOrEmpty(trimmedLine))
{
inputProjectsToIndex.Add(trimmedLine);
if (Path.IsPathRooted(trimmedLine))
{
inputFilesToIndex.Add(trimmedLine);
}
}
}
await _package.LogAsync($"Number of Projects loaded from {projectListPath}: {inputProjectsToIndex.Count}");
await _package.LogAsync($"Loaded from {inputFilesToIndex.Count} files");
}
}
catch (Exception ex)
{
await _package.LogAsync($"Error reading project list: {ex.Message}");
}

List<string> projectsToIndex = await GetFilesToIndex(inputProjectsToIndex, openFilePaths, dte);
List<string> projectsToIndex = new List<string>(inputFilesToIndex);
projectsToIndex.AddRange(await GetFilesToIndex(openFilePaths, dte));
await _package.LogAsync($"Number of projects to index: {projectsToIndex.Count}");

for (int i = 0; i < projectsToIndex.Count; i++)
Expand All @@ -799,17 +803,16 @@ private async Task InitializeTrackedWorkspaceAsync()
}
}

private async Task<List<string>> GetFilesToIndex(HashSet<string> inputProjectsToIndex, HashSet<string> openFilePaths, DTE dte)
private async Task<List<string>> GetFilesToIndex(HashSet<string> openFilePaths, DTE dte)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
int maxToIndex = 15;
HashSet<string> specifiedProjectsToIndexPath = new HashSet<string>();
HashSet<string> openFilesProjectsToIndexPath = new HashSet<string>();
HashSet<string> remainingProjectsToIndexPath = new HashSet<string>();
HashSet<string> processedProjects = new HashSet<string>();
async Task AddFilesToIndexLists(EnvDTE.Project project)
{
if (specifiedProjectsToIndexPath.Count == inputProjectsToIndex.Count && openFilePaths.Count == 0 && (specifiedProjectsToIndexPath.Count + remainingProjectsToIndexPath.Count + openFilesProjectsToIndexPath.Count) >= maxToIndex)
if (openFilePaths.Count == 0 && (openFilesProjectsToIndexPath.Count + remainingProjectsToIndexPath.Count) >= maxToIndex)
{
return;
}
Expand Down Expand Up @@ -848,7 +851,6 @@ async Task AddFilesToIndexLists(EnvDTE.Project project)
foreach (var item in compileItems)
{
string fullPath = Path.GetFullPath(Path.Combine(projectDir, item));
await _package.LogAsync($"FULL PATH: {fullPath}");
fullPaths.Add(fullPath);
}

Expand Down Expand Up @@ -878,37 +880,27 @@ async Task AddFilesToIndexLists(EnvDTE.Project project)
}
}

// There are three cases.
// 1. The project is in the list of projects to index passed in by the user. These take priority. The entire solution is searched until all are found.
// 2. Find the project the open file is a member of. Not sure if nested projects could match the same file multiple times so delete from the set when found.
// 3. Any other project. Tops it up to the max amount to index if the previous two cases didnt.
if (inputProjectsToIndex.Contains(projectName))
{
await _package.LogAsync($"Found in input list {projectName}");
foreach (var dir in sourceDirectories)
{
specifiedProjectsToIndexPath.Add(dir);
}
}
else if (openFilePaths.Count != 0)
if (openFilePaths.Count != 0)
{
string matchingFile = null;
List<string> matchingFiles = new List<string>();
foreach (var filePath in openFilePaths)
{
if (sourceDirectories.Any(dir => filePath.StartsWith(dir, StringComparison.OrdinalIgnoreCase)))
{
await _package.LogAsync($"Found in open files {filePath}");
matchingFile = filePath;
break;
matchingFiles.Add(filePath);
}
}
if (!string.IsNullOrEmpty(matchingFile))
if (matchingFiles.Count > 0)
{
foreach (var dir in sourceDirectories)
{
openFilesProjectsToIndexPath.Add(dir);
}
openFilePaths.Remove(matchingFile);
foreach (var file in matchingFiles)
{
openFilePaths.Remove(file);
}
}
}
else
Expand Down Expand Up @@ -945,14 +937,13 @@ async Task AddFilesToIndexLists(EnvDTE.Project project)
{
await AddFilesToIndexLists(project);
}
catch (Exception ex)
catch (Exception ex)
{
await _package.LogAsync($"Failed to process project: {ex.Message}");
continue;
}
}
List<string> result = new List<string>();
result.AddRange(specifiedProjectsToIndexPath);
result.AddRange(openFilesProjectsToIndexPath);
result.AddRange(remainingProjectsToIndexPath);
return result;
Expand Down
2 changes: 1 addition & 1 deletion CodeiumVS/SettingsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class SettingsPage : DialogPage
private bool indexOpenFiles = true;

[Category("Codeium")]
[DisplayName("Enterprise Mode")]
[DisplayName("Self-Hosted Enterprise Mode")]
[Description(
"Set this to True if using Visual Studio with Codeium Enterprise. Requires restart.")]
public bool EnterpriseMode
Expand Down

0 comments on commit b304570

Please sign in to comment.