private async Task <IProjectEntry> AddFileAsync(Uri documentUri, IAnalysisCookie cookie = null) { var item = ProjectFiles.GetEntry(documentUri, throwIfMissing: false); if (item != null) { return(item); } var path = GetLocalPath(documentUri); var aliases = GetImportNames(documentUri).Select(mp => mp.ModuleName).ToArray(); if (aliases.Length == 0) { aliases = new[] { Path.GetFileNameWithoutExtension(path) }; } var first = aliases.First(); var pyItem = Analyzer.AddModule(first, path, documentUri, cookie); item = pyItem; var actualItem = ProjectFiles.GetOrAddEntry(documentUri, item); if (actualItem != item) { return(actualItem); } var reanalyzeEntries = Analyzer.GetEntriesThatImportModule(pyItem.ModuleName, true).ToArray(); pyItem.NewAnalysis += OnProjectEntryNewAnalysis; if (item is IDocument doc) { await EnqueueItemAsync(doc); } foreach (var entryRef in reanalyzeEntries) { await EnqueueItemAsync(entryRef as IDocument, AnalysisPriority.Low, parse : false); } return(item); }
private async Task <IProjectEntry> AddFileAsync(Uri documentUri, Uri fromSearchPath, IAnalysisCookie cookie = null) { var item = ProjectFiles.GetEntry(documentUri, throwIfMissing: false); if (item != null) { return(item); } string[] aliases = null; var path = GetLocalPath(documentUri); if (fromSearchPath != null) { if (ModulePath.FromBasePathAndFile_NoThrow(GetLocalPath(fromSearchPath), path, out var mp)) { aliases = new[] { mp.ModuleName }; } } else { aliases = GetImportNames(documentUri).Select(mp => mp.ModuleName).ToArray(); } if (aliases.IsNullOrEmpty()) { aliases = new[] { Path.GetFileNameWithoutExtension(path) }; } var reanalyzeEntries = aliases.SelectMany(a => Analyzer.GetEntriesThatImportModule(a, true)).ToArray(); var first = aliases.FirstOrDefault(); var pyItem = Analyzer.AddModule(first, path, documentUri, cookie); item = pyItem; foreach (var a in aliases.Skip(1)) { Analyzer.AddModuleAlias(first, a); } var actualItem = ProjectFiles.GetOrAddEntry(documentUri, item); if (actualItem != item) { return(actualItem); } pyItem.NewAnalysis += OnProjectEntryNewAnalysis; if (item is IDocument doc) { await EnqueueItemAsync(doc); } foreach (var entryRef in reanalyzeEntries) { await EnqueueItemAsync(entryRef as IDocument, AnalysisPriority.Low, parse : false); } return(item); }