Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More indexing changes #159

Merged
merged 6 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions CodeiumVS/LanguageServer/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ private async Task InitializeTrackedWorkspaceAsync()
string projectListPath = _package.SettingsPage.IndexingFilesListPath.Trim();
try
{
projectListPath = projectListPath.Trim();
if (!string.IsNullOrEmpty(projectListPath) && File.Exists(projectListPath))
{
string[] lines = File.ReadAllLines(projectListPath);
Expand All @@ -782,10 +783,11 @@ private async Task InitializeTrackedWorkspaceAsync()
}

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

for (int i = 0; i < projectsToIndex.Count; i++)
for (int i = 0; i < Math.Min(maxToIndex, projectsToIndex.Count); i++)
{
try
{
Expand All @@ -803,25 +805,26 @@ private async Task InitializeTrackedWorkspaceAsync()
}
}

private async Task<List<string>> GetFilesToIndex(HashSet<string> openFilePaths, DTE dte)
private async Task<List<string>> GetFilesToIndex(HashSet<string> processedProjects, HashSet<string> openFilePaths, int remainingToFind, DTE dte)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
int maxToIndex = 15;
HashSet<string> openFilesProjectsToIndexPath = new HashSet<string>();
HashSet<string> remainingProjectsToIndexPath = new HashSet<string>();
HashSet<string> processedProjects = new HashSet<string>();
// Safeguard against any edge case
int maxRecursiveCalls = 25;
async Task AddFilesToIndexLists(EnvDTE.Project project)
{
if (openFilePaths.Count == 0 && (openFilesProjectsToIndexPath.Count + remainingProjectsToIndexPath.Count) >= maxToIndex)
maxRecursiveCalls--;
if (remainingToFind <= 0 || (openFilePaths.Count == 0 && remainingProjectsToIndexPath.Count >= remainingToFind) || maxRecursiveCalls == 0)
{
return;
}
string projectFullName = project.FullName;
string projectName = Path.GetFileNameWithoutExtension(projectFullName);
if (!string.IsNullOrEmpty(projectFullName) && !processedProjects.Contains(projectFullName))
if (!string.IsNullOrEmpty(projectFullName) && !processedProjects.Any(p => projectFullName.StartsWith(p)))
{
string projectDir = Path.GetDirectoryName(projectFullName);
HashSet<string> sourceDirectories = new HashSet<string> { projectDir };
string projectCommonRoot = projectDir;

// Parse the csproj file to find all source directories
if (File.Exists(projectFullName) && (projectFullName.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase) || projectFullName.EndsWith(".vcxproj", StringComparison.OrdinalIgnoreCase)))
Expand Down Expand Up @@ -861,16 +864,16 @@ async Task AddFilesToIndexLists(EnvDTE.Project project)
foreach (var path in fullPaths.Skip(1))
{
string directory = Path.GetDirectoryName(path);
while (!directory.StartsWith(commonRoot, StringComparison.OrdinalIgnoreCase) && commonRoot.Length > 3)
while (!directory.StartsWith(commonRoot, StringComparison.OrdinalIgnoreCase) && commonRoot.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).Where(s => !string.IsNullOrWhiteSpace(s)).Count() > 4)
{
commonRoot = Path.GetDirectoryName(commonRoot);
}
}

await _package.LogAsync($"Common root directory: {commonRoot}");
if (Directory.Exists(commonRoot))
{
sourceDirectories.Add(commonRoot);
await _package.LogAsync($"Common root directory: {commonRoot}");
projectCommonRoot = commonRoot;
}
}
}
Expand All @@ -885,18 +888,16 @@ async Task AddFilesToIndexLists(EnvDTE.Project project)
List<string> matchingFiles = new List<string>();
foreach (var filePath in openFilePaths)
{
if (sourceDirectories.Any(dir => filePath.StartsWith(dir, StringComparison.OrdinalIgnoreCase)))
if (filePath.StartsWith(projectCommonRoot, StringComparison.OrdinalIgnoreCase))
{
await _package.LogAsync($"Found in open files {filePath}");
matchingFiles.Add(filePath);
}
}
if (matchingFiles.Count > 0)
{
foreach (var dir in sourceDirectories)
{
openFilesProjectsToIndexPath.Add(dir);
}
openFilesProjectsToIndexPath.Add(projectCommonRoot);
remainingToFind--;
foreach (var file in matchingFiles)
{
openFilePaths.Remove(file);
Expand All @@ -905,11 +906,8 @@ async Task AddFilesToIndexLists(EnvDTE.Project project)
}
else
{
await _package.LogAsync($"Found in remaining {projectName}");
foreach (var dir in sourceDirectories)
{
remainingProjectsToIndexPath.Add(dir);
}
await _package.LogAsync($"Found in remaining {projectCommonRoot}");
remainingProjectsToIndexPath.Add(projectCommonRoot);
}
processedProjects.Add(projectFullName);
}
Expand Down
2 changes: 1 addition & 1 deletion CodeiumVS/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="Codeium.VisualStudio" Version="1.8.97" Language="en-US" Publisher="Codeium" />
<Identity Id="Codeium.VisualStudio" Version="1.8.98" Language="en-US" Publisher="Codeium" />
<DisplayName>Codeium</DisplayName>
<Description xml:space="preserve">The modern coding superpower: free AI code acceleration plugin for your favorite languages. Type less. Code more. Ship faster.</Description>
<MoreInfo>https://www.codeium.com</MoreInfo>
Expand Down