diff --git a/CodeiumVS/LanguageServer/LanguageServer.cs b/CodeiumVS/LanguageServer/LanguageServer.cs index 179ac31..fdb5cd3 100644 --- a/CodeiumVS/LanguageServer/LanguageServer.cs +++ b/CodeiumVS/LanguageServer/LanguageServer.cs @@ -755,7 +755,7 @@ private async Task InitializeTrackedWorkspaceAsync() } } - var inputProjectsToIndex = new HashSet(StringComparer.OrdinalIgnoreCase); + var inputFilesToIndex = new HashSet(StringComparer.OrdinalIgnoreCase); string projectListPath = _package.SettingsPage.IndexingFilesListPath.Trim(); try { @@ -767,10 +767,13 @@ 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) @@ -778,7 +781,8 @@ private async Task InitializeTrackedWorkspaceAsync() await _package.LogAsync($"Error reading project list: {ex.Message}"); } - List projectsToIndex = await GetFilesToIndex(inputProjectsToIndex, openFilePaths, dte); + List projectsToIndex = new List(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++) @@ -799,17 +803,16 @@ private async Task InitializeTrackedWorkspaceAsync() } } - private async Task> GetFilesToIndex(HashSet inputProjectsToIndex, HashSet openFilePaths, DTE dte) + private async Task> GetFilesToIndex(HashSet openFilePaths, DTE dte) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); int maxToIndex = 15; - HashSet specifiedProjectsToIndexPath = new HashSet(); HashSet openFilesProjectsToIndexPath = new HashSet(); HashSet remainingProjectsToIndexPath = new HashSet(); HashSet processedProjects = new HashSet(); 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; } @@ -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); } @@ -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 matchingFiles = new List(); 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 @@ -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 result = new List(); - result.AddRange(specifiedProjectsToIndexPath); result.AddRange(openFilesProjectsToIndexPath); result.AddRange(remainingProjectsToIndexPath); return result; diff --git a/CodeiumVS/SettingsPage.cs b/CodeiumVS/SettingsPage.cs index ef2322e..f4b80e0 100644 --- a/CodeiumVS/SettingsPage.cs +++ b/CodeiumVS/SettingsPage.cs @@ -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