private IEnumerable <string> GetSymbolsAsList(string f) { var physFile = new PhysicalFile { Filepath = f, Sourcecode = File.ReadAllText(f) }; var dtu = new DafnyTranslationUnit(physFile); var dafnyProg = dtu.Verify().DafnyProgram; ISymbolTableGenerator st = new SymbolTableGenerator(dafnyProg); ISymbolInformation root = st.GenerateSymbolTable(); ISymbolTableManager sm = new SymbolTableManager(root); ISymbolNavigator navigator = new SymbolNavigator(); List <ISymbolInformation> symbols = new List <ISymbolInformation>(); foreach (var modul in root.Children) { symbols.AddRange(navigator.TopDownAll(modul)); } var actual = symbols.Select(x => x.ToDebugString()).ToList(); Console.WriteLine("SymboleTable for " + f); Console.Write(((SymbolTableManager)sm).CreateDebugReadOut()); return(actual); }
private IEnumerable <CompletionItem> GetCompletionItems(SyntaxContext syntaxContext) { var hasStaticImports = syntaxContext.StaticImports.Count > 0; var hasAliases = syntaxContext.Aliases.Count > 0; foreach (var typeSymbol in SymbolNavigator.GetAllTypes(syntaxContext)) { if (typeSymbol.ContainingType == null) { continue; } // Skip nested type if there is static using for parent type if (hasStaticImports && syntaxContext.StaticImports.Contains(typeSymbol.ContainingType)) { continue; } // Skip if alias present from current type if (hasAliases && syntaxContext.Aliases.ContainsKey(typeSymbol)) { continue; } var isImported = syntaxContext.IsNamespaceImported(typeSymbol.ContainingNamespace); var sorting = isImported ? Sorting.Default : Sorting.Last; yield return(CompletionItemHelper.CreateCompletionItem(typeSymbol, syntaxContext, sorting, unimported: !isImported)); } }
public override async Task ProvideCompletionsAsync(CompletionContext context) { try { if (Options == null) { // Package not loaded yet (e.g. no solution opened) return; } if (await IsWatchWindowAsync(context).ConfigureAwait(false)) { // Completions are not usable in watch window return; } if (IsRazorView(context)) { // Completions are not usable in cshtml-Razor Views. Insertion of Namespaces doesn't work there. return; } var syntaxContext = await SyntaxContext.CreateAsync(context.Document, context.Position, context.CancellationToken) .ConfigureAwait(false); var applicableTypeProviders = typeCompletionProviders .Where(p => p.IsApplicable(syntaxContext, Options)) .ToArray(); if (applicableTypeProviders.Length > 0) { var typeCompletions = SymbolNavigator.GetAllTypes(syntaxContext, Options) .SelectMany(type => applicableTypeProviders .Select(provider => provider.GetCompletionItemsForType(type, syntaxContext, Options))) .Where(enumerable => enumerable != null) .SelectMany(enumerable => enumerable); context.AddItems(typeCompletions); } var simpleCompletions = simpleCompletionProviders .Where(p => p.IsApplicable(syntaxContext, Options)) .Select(provider => provider.GetCompletionItems(syntaxContext, Options)) .Where(enumerable => enumerable != null) .SelectMany(enumerable => enumerable); context.AddItems(simpleCompletions); // If Completion was triggered by this provider - use suggestion mode if (_triggeredByUs && context.SuggestionModeItem == null) { context.SuggestionModeItem = CompletionItem.Create(""); } } finally { _triggeredByUs = false; } }