private static DiagnosticAnalyzerInfoCache CreateHostAnalyzerManager(string language, ImmutableArray <DiagnosticAnalyzer> analyzers, AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource) { var map = ImmutableDictionary.CreateRange( SpecializedCollections.SingletonEnumerable(KeyValuePairUtil.Create(language, analyzers))); return(CreateHostAnalyzerManager(map, hostDiagnosticUpdateSource)); }
public void LoadedFile() { var sourceA = @"goto A; A: goto B;"; var sourceB = @"#load ""a.csx"" goto B; B: goto A;"; var resolver = TestSourceReferenceResolver.Create( KeyValuePairUtil.Create("a.csx", sourceA) ); var options = TestOptions.DebugDll.WithSourceReferenceResolver(resolver); var compilation = CreateCompilationWithMscorlib45( sourceB, options: options, parseOptions: TestOptions.Script ); compilation .GetDiagnostics() .Verify( // a.csx(2,9): error CS0159: No such label 'B' within the scope of the goto statement // A: goto B; Diagnostic(ErrorCode.ERR_LabelNotFound, "B") .WithArguments("B") .WithLocation(2, 9), // (3,9): error CS0159: No such label 'A' within the scope of the goto statement // B: goto A; Diagnostic(ErrorCode.ERR_LabelNotFound, "A") .WithArguments("A") .WithLocation(3, 9) ); }
protected void ReadParseOptionsFrom( ObjectReader reader, out SourceCodeKind kind, out DocumentationMode documentationMode, out IEnumerable <KeyValuePair <string, string> > features, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); kind = (SourceCodeKind)reader.ReadInt32(); documentationMode = (DocumentationMode)reader.ReadInt32(); // REVIEW: I don't think there is a guarantee on ordering of elements in the immutable dictionary. // unfortunately, we need to sort them to make it deterministic // not sure why ParseOptions uses SequencialEqual to check options equality // when ordering can change result of it even if contents are same. var count = reader.ReadInt32(); List <KeyValuePair <string, string> > featuresList = null; if (count > 0) { featuresList = new List <KeyValuePair <string, string> >(count); for (var i = 0; i < count; i++) { var key = reader.ReadString(); var value = reader.ReadString(); featuresList.Add(KeyValuePairUtil.Create(key, value)); } } features = featuresList ?? SpecializedCollections.EmptyEnumerable <KeyValuePair <string, string> >(); }
public void KnownMatchesDups() { TestNode x1, x2, y1, y2; var oldRoot = new TestNode(0, 1, x1 = new TestNode(1, 1), y1 = new TestNode(1, 4)); var newRoot = new TestNode(0, 1, x2 = new TestNode(1, 2), y2 = new TestNode(1, 3)); var m = TestTreeComparer.Instance.ComputeMatch(oldRoot, newRoot, new[] { KeyValuePairUtil.Create(x1, x2), KeyValuePairUtil.Create(y1, x2), }); // the first one wins: Assert.True(m.TryGetNewNode(x1, out var n)); Assert.Equal(x2, n); Assert.True(m.TryGetOldNode(x2, out n)); Assert.Equal(x1, n); Assert.True(m.TryGetNewNode(y1, out n)); // matched Assert.Equal(y2, n); }
public void IncorrectPathmaps() { string isABaseDirectory; if (Path.DirectorySeparatorChar == '/') { isABaseDirectory = "/"; } else { isABaseDirectory = "C://"; } try { new SourceFileResolver( ImmutableArray.Create(""), isABaseDirectory, ImmutableArray.Create(KeyValuePairUtil.Create <string, string>("key", null))); AssertEx.Fail("Didn't throw"); } catch (ArgumentException argException) { Assert.Equal(new ArgumentException(CodeAnalysisResources.NullValueInPathMap, "pathMap").Message, argException.Message); } // Empty pathmap value doesn't throw new SourceFileResolver( ImmutableArray.Create(""), isABaseDirectory, ImmutableArray.Create(KeyValuePairUtil.Create <string, string>("key", ""))); }
private static IEnumerable <KeyValuePair <K, V> > ReverseMapping <K, V>(IEnumerable <KeyValuePair <V, K> > mapping) { foreach (var pair in mapping) { yield return(KeyValuePairUtil.Create(pair.Value, pair.Key)); } }
public async Task <LibraryBookPagedListResponse> GetLibraryBooksPaged(PagedBase filterParameters, bool listLostAndStolen) { List <KeyValuePair <string, string> > kvpList = KeyValuePairUtil.KeyValuePairFromPagedBase(filterParameters); kvpList.Add(new KeyValuePair <string, string>("listLostAndStolen", listLostAndStolen.ToString())); return(await GetJsonDecodedContent <LibraryBookPagedListResponse, LibraryBookPageApiModel>(_apiUrl + APIConstants.Paged, kvpList.ToArray()).ConfigureAwait(false)); }
public void FileWithErrors() { using (new EnsureEnglishUICulture()) { var code = "#load \"a.csx\""; var resolver = TestSourceReferenceResolver.Create( KeyValuePairUtil.Create("a.csx", @" #load ""b.csx"" asdf();")); var options = TestOptions.DebugDll.WithSourceReferenceResolver(resolver); var compilation = CreateCompilationWithMscorlib45(code, options: options, parseOptions: TestOptions.Script); Assert.Equal(2, compilation.SyntaxTrees.Length); compilation.GetParseDiagnostics().Verify( // a.csx(2,27): error CS1504: Source file 'b.csx' could not be opened -- Could not find file. // #load "b.csx"; Diagnostic(ErrorCode.ERR_NoSourceFile, @"""b.csx""").WithArguments("b.csx", "Could not find file.").WithLocation(2, 27)); compilation.GetDiagnostics().Verify( // a.csx(2,27): error CS1504: Source file 'b.csx' could not be opened -- Could not find file. // #load "b.csx"; Diagnostic(ErrorCode.ERR_NoSourceFile, @"""b.csx""").WithArguments("b.csx", "Could not find file.").WithLocation(2, 27), // a.csx(3,21): error CS0103: The name 'asdf' does not exist in the current context // asdf(); Diagnostic(ErrorCode.ERR_NameNotInContext, "asdf").WithArguments("asdf").WithLocation(3, 21)); } }
public bool TryGetDocumentOption(OptionKey option, out object value) { if (codingConventionsSnapshot != null) { var editorConfigPersistence = option.Option.StorageLocations.OfType <IEditorConfigStorageLocation> ().SingleOrDefault(); if (editorConfigPersistence != null) { // Temporarly map our old Dictionary<string, object> to a Dictionary<string, string>. This can go away once we either // eliminate the legacy editorconfig support, or we change IEditorConfigStorageLocation.TryGetOption to take // some interface that lets us pass both the Dictionary<string, string> we get from the new system, and the // Dictionary<string, object> from the old system. // // We cache this with a conditional weak table so we're able to maintain the assumptions in EditorConfigNamingStyleParser // that the instance doesn't regularly change and thus can be used for further caching var allRawConventions = s_convertedDictionaryCache.GetValue( codingConventionsSnapshot.AllRawConventions, d => ImmutableDictionary.CreateRange(d.Select(c => KeyValuePairUtil.Create(c.Key, c.Value.ToString())))); try { if (editorConfigPersistence.TryGetOption(allRawConventions, option.Option.Type, out value)) { return(true); } } catch (Exception ex) { LoggingService.LogError("Error while getting editor config preferences.", ex); } } } var result = optionSet.GetOption(option); value = result; return(true); }
public void TryApplyWorksThrowsIfChangeIsDisallowedForParseOption() { // If we don't support the main change kind, then the other method should be called using var workspace = new CustomizedCanApplyWorkspace( allowedKinds: new ApplyChangesKind[] { }, canApplyParseOptions: (_, newParseOptions) => newParseOptions.Features["Feature"] == "ExpectedValue" ); var project = workspace.CurrentSolution.Projects.Single(); var exception = Assert.Throws <NotSupportedException>( () => workspace.TryApplyChanges( project.WithParseOptions( project.ParseOptions !.WithFeatures( new[] { KeyValuePairUtil.Create("Feature", "WrongThing") } ) ).Solution ) ); Assert.Equal( WorkspacesResources.Changing_parse_options_is_not_supported, exception.Message ); }
void InitButtons() { Weapon = InstantiateChild <LMS_GuiBaseButton>(new LMS_GuiConfig() { Rect = new Rect(12f, 30f, 431f, 150f) }, 50); ScreenB = InstantiateChild <LMS_GuiBaseButton>(new LMS_GuiConfig() { Rect = new Rect(12f, 65f, 431f, 150f) }, 50); Camera = InstantiateChild <LMS_GuiBaseButton>(new LMS_GuiConfig() { Rect = new Rect(12f, 100f, 431f, 150f) }, 50); Player = InstantiateChild <LMS_GuiBaseButton>(new LMS_GuiConfig() { Rect = new Rect(12f, 135f, 431f, 150f) }, 50); msGUI = InstantiateChild <LMS_GuiBaseButton>(new LMS_GuiConfig() { Rect = new Rect(12f, 170f, 431f, 150f) }, 50); InitButtonDefault(Weapon, CreateDetails("Weapon Hacks", "memz", KeyValuePairUtil.b(OptWeaponScroller), KeyValuePairUtil.b(OptInvisibleWeaponLabel), KeyValuePairUtil.b(OptInvisibleWeaponToggleLabel))); InitButtonDefault(ScreenB); InitButtonDefault(Camera); InitButtonDefault(Player); InitButtonDefault(msGUI); }
private static void MakeLambdaAndClosureMaps( ImmutableArray <LambdaDebugInfo> lambdaDebugInfo, ImmutableArray <ClosureDebugInfo> closureDebugInfo, out IReadOnlyDictionary <int, KeyValuePair <DebugId, int> > lambdaMap, out IReadOnlyDictionary <int, DebugId> closureMap ) { var lambdas = new Dictionary <int, KeyValuePair <DebugId, int> >(lambdaDebugInfo.Length); var closures = new Dictionary <int, DebugId>(closureDebugInfo.Length); for (int i = 0; i < lambdaDebugInfo.Length; i++) { var lambdaInfo = lambdaDebugInfo[i]; lambdas[lambdaInfo.SyntaxOffset] = KeyValuePairUtil.Create( lambdaInfo.LambdaId, lambdaInfo.ClosureOrdinal ); } for (int i = 0; i < closureDebugInfo.Length; i++) { var closureInfo = closureDebugInfo[i]; closures[closureInfo.SyntaxOffset] = closureInfo.ClosureId; } lambdaMap = lambdas; closureMap = closures; }
public void Add(AssemblyIdentity identity, TValue value) { var pair = KeyValuePairUtil.Create(identity, value); OneOrMany <KeyValuePair <AssemblyIdentity, TValue> > sameName; _map[identity.Name] = _map.TryGetValue(identity.Name, out sameName) ? sameName.Add(pair) : OneOrMany.Create(pair); }
protected override Compilation CreateCompilation(SyntaxTree tree) { return(CSharpCompilation.Create( CompilationName, new[] { tree }, References, TestOptions.ReleaseDll.WithSpecificDiagnosticOptions(new[] { KeyValuePairUtil.Create("CS0219", ReportDiagnostic.Suppress) }))); }
internal IEnumerable <KeyValuePair <TextSpan, TextSpan> > this[int i] { get { for (var j = 0; j < OldSpans[i].Length; j++) { yield return(KeyValuePairUtil.Create(OldSpans[i][j], NewSpans[i][j])); } } }
internal void AddService(Type serviceType, IObjectRef service) { Validate.Begin().IsNotNull <Type>(serviceType, "serviceType").IsNotNull <IObjectRef>(service, "service").Check(); object sync = this.sync; lock (sync) { this.services.Add(KeyValuePairUtil.Create <Type, IObjectRef>(serviceType, service)); } }
public void FileThatCannotBeDecoded() { var code = "#load \"b.csx\""; var resolver = TestSourceReferenceResolver.Create( KeyValuePairUtil.Create <string, object>("a.csx", new byte[] { 0xd8, 0x00, 0x00, 0x00 }), KeyValuePairUtil.Create <string, object>("b.csx", "#load \"a.csx\"")); var options = TestOptions.DebugDll.WithSourceReferenceResolver(resolver); var compilation = CreateCompilationWithMscorlib45(code, sourceFileName: "external1.csx", options: options, parseOptions: TestOptions.Script); var external1 = compilation.SyntaxTrees.Last(); var external2 = Parse(code, "external2.csx", TestOptions.Script); compilation = compilation.AddSyntaxTrees(external2); Assert.Equal(3, compilation.SyntaxTrees.Length); compilation.GetParseDiagnostics().Verify( // (1,7): error CS2015: 'a.csx' is a binary file instead of a text file // #load "a.csx" Diagnostic(ErrorCode.ERR_BinaryFile, @"""a.csx""").WithArguments("a.csx").WithLocation(1, 7)); var external3 = Parse(@" #load ""b.csx"" #load ""a.csx""", filename: "external3.csx", options: TestOptions.Script); compilation = compilation.ReplaceSyntaxTree(external1, external3); Assert.Equal(3, compilation.SyntaxTrees.Length); compilation.GetParseDiagnostics().Verify( // external3.csx(3,23): error CS2015: 'a.csx' is a binary file instead of a text file // #load "a.csx" Diagnostic(ErrorCode.ERR_BinaryFile, @"""a.csx""").WithArguments("a.csx").WithLocation(3, 23), // b.csx(1,7): error CS2015: 'a.csx' is a binary file instead of a text file // #load "a.csx" Diagnostic(ErrorCode.ERR_BinaryFile, @"""a.csx""").WithArguments("a.csx").WithLocation(1, 7)); var external4 = Parse("#load \"a.csx\"", "external4.csx", TestOptions.Script); compilation = compilation.ReplaceSyntaxTree(external3, external4); Assert.Equal(3, compilation.SyntaxTrees.Length); compilation.GetParseDiagnostics().Verify( // external4.csx(1,7): error CS2015: 'a.csx' is a binary file instead of a text file // #load "a.csx" Diagnostic(ErrorCode.ERR_BinaryFile, @"""a.csx""").WithArguments("a.csx").WithLocation(1, 7), // b.csx(1,7): error CS2015: 'a.csx' is a binary file instead of a text file // #load "a.csx" Diagnostic(ErrorCode.ERR_BinaryFile, @"""a.csx""").WithArguments("a.csx").WithLocation(1, 7)); compilation = compilation.RemoveSyntaxTrees(external2); Assert.Equal(external4, compilation.SyntaxTrees.Single()); compilation.GetParseDiagnostics().Verify( // external4.csx(1,7): error CS2015: 'a.csx' is a binary file instead of a text file // #load "a.csx" Diagnostic(ErrorCode.ERR_BinaryFile, @"""a.csx""").WithArguments("a.csx").WithLocation(1, 7)); }
private static IEnumerable <KeyValuePair <DocumentId, SyntaxTree> > GetNewTreeMap(Project project, Compilation compilation) { foreach (var tree in compilation.SyntaxTrees) { var documentId = project.GetDocumentId(tree); if (documentId != null) { yield return(KeyValuePairUtil.Create(documentId, tree)); } } }
private static void ReadVisualBasicImportsDebugInfo( ISymUnmanagedReader reader, int methodToken, int methodVersion, out ImmutableArray <ImmutableArray <ImportRecord> > importRecordGroups, out string defaultNamespaceName) { importRecordGroups = ImmutableArray <ImmutableArray <ImportRecord> > .Empty; var importStrings = CustomDebugInfoReader.GetVisualBasicImportStrings( methodToken, KeyValuePairUtil.Create(reader, methodVersion), (token, arg) => GetImportStrings(arg.Key, token, arg.Value)); if (importStrings.IsDefault) { defaultNamespaceName = ""; return; } string?lazyDefaultNamespaceName = null; var projectLevelImportRecords = ArrayBuilder <ImportRecord> .GetInstance(); var fileLevelImportRecords = ArrayBuilder <ImportRecord> .GetInstance(); foreach (var importString in importStrings) { RoslynDebug.AssertNotNull(importString); if (importString.Length > 0 && importString[0] == '*') { string?alias = null; string?target = null; if (!CustomDebugInfoReader.TryParseVisualBasicImportString(importString, out alias, out target, out var kind, out var scope)) { Debug.WriteLine($"Unable to parse import string '{importString}'"); continue; } else if (kind == ImportTargetKind.Defunct) { continue; } Debug.Assert(alias == null); // The default namespace is never aliased. Debug.Assert(target != null); Debug.Assert(kind == ImportTargetKind.DefaultNamespace); // We only expect to see one of these, but it looks like ProcedureContext::LoadImportsAndDefaultNamespaceNormal // implicitly uses the last one if there are multiple. Debug.Assert(lazyDefaultNamespaceName == null); lazyDefaultNamespaceName = target; }
private static Compilation EnableAnalyzer(DiagnosticAnalyzer analyzer, Compilation compilation) { return(compilation.WithOptions( compilation .Options .WithSpecificDiagnosticOptions( analyzer .SupportedDiagnostics .Select(x => KeyValuePairUtil.Create(x.Id, ReportDiagnostic.Default)) .ToImmutableDictionaryOrEmpty()))); }
public void Cycles() { var code = "#load \"a.csx\""; var resolver = TestSourceReferenceResolver.Create( KeyValuePairUtil.Create("a.csx", code) ); var options = TestOptions.DebugDll.WithSourceReferenceResolver(resolver); var compilation = CreateCompilationWithMscorlib45( code, options: options, parseOptions: TestOptions.Script ); Assert.Equal(2, compilation.SyntaxTrees.Length); compilation.VerifyDiagnostics(); var newTree = Parse(code, "a.csx", TestOptions.Script); compilation = compilation.ReplaceSyntaxTree(compilation.SyntaxTrees.Last(), newTree); Assert.Equal(2, compilation.SyntaxTrees.Length); compilation.VerifyDiagnostics(); compilation = compilation.RemoveSyntaxTrees(newTree); Assert.Empty(compilation.SyntaxTrees); compilation.VerifyDiagnostics(); resolver = TestSourceReferenceResolver.Create( KeyValuePairUtil.Create("a.csx", "#load \"b.csx\""), KeyValuePairUtil.Create("b.csx", code) ); options = TestOptions.DebugDll.WithSourceReferenceResolver(resolver); compilation = CreateCompilationWithMscorlib45( code, options: options, parseOptions: TestOptions.Script ); Assert.Equal(3, compilation.SyntaxTrees.Length); compilation.VerifyDiagnostics(); newTree = Parse(code, "a.csx", TestOptions.Script); compilation = compilation.ReplaceSyntaxTree(compilation.SyntaxTrees.Last(), newTree); Assert.Equal(3, compilation.SyntaxTrees.Length); compilation.VerifyDiagnostics(); compilation = compilation.RemoveSyntaxTrees(newTree); Assert.Empty(compilation.SyntaxTrees); compilation.VerifyDiagnostics(); }
private static KeyValuePair <string, XDocument> MakeValue(XmlReferenceResolver resolver, string resolvedPath) { CacheMissCount++; using (Stream stream = resolver.OpenReadChecked(resolvedPath)) { using (XmlReader reader = XmlReader.Create(stream, s_xmlSettings)) { var document = XDocument.Load(reader, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); return(KeyValuePairUtil.Create(resolvedPath, document)); } } }
public void TryApplyWorksIfAllowingAnyParseOption() { // If we simply support the main change kind, then any type of change should be supported and we should not get called // to the other method using var workspace = new CustomizedCanApplyWorkspace( allowedKinds: new[] { ApplyChangesKind.ChangeParseOptions }, canApplyParseOptions: (_, __) => throw new Exception("This should not have been called.")); var project = workspace.CurrentSolution.Projects.Single(); Assert.True(workspace.TryApplyChanges( project.WithParseOptions( project.ParseOptions !.WithFeatures(new[] { KeyValuePairUtil.Create("Feature", "") })).Solution)); }
public void BadBaseDirectory() { try { new SourceFileResolver( ImmutableArray.Create(""), "not_a_root directory", ImmutableArray.Create(KeyValuePairUtil.Create <string, string>("key", "value"))); AssertEx.Fail("Didn't throw"); } catch (ArgumentException argException) { Assert.Equal(new ArgumentException(CodeAnalysisResources.AbsolutePathExpected, "baseDirectory").Message, argException.Message); } }
private static IEnumerable <KeyValuePair <ISymbol, ImmutableArray <Diagnostic> > > CreateDiagnosticsBySymbol(ImmutableDictionary <ISymbol, List <Diagnostic> > .Builder diagnosticsMapBuilder) { if (diagnosticsMapBuilder.Count == 0) { return(SpecializedCollections.EmptyEnumerable <KeyValuePair <ISymbol, ImmutableArray <Diagnostic> > >()); } var builder = new List <KeyValuePair <ISymbol, ImmutableArray <Diagnostic> > >(); foreach (var kvp in diagnosticsMapBuilder) { builder.Add(KeyValuePairUtil.Create(kvp.Key, GetUniqueDiagnostics(kvp.Value))); } return(builder.OrderBy(kvp => kvp.Key.GetDocumentationCommentId() ?? string.Empty)); }
private static ParseOptions GetPreProcessorParseOptions(string language, XAttribute preprocessorSymbolsAttribute) { if (language == LanguageNames.CSharp) { return(new CSharpParseOptions(preprocessorSymbols: preprocessorSymbolsAttribute.Value.Split(','))); } else if (language == LanguageNames.VisualBasic) { return(new VisualBasicParseOptions(preprocessorSymbols: preprocessorSymbolsAttribute.Value .Split(',').Select(v => KeyValuePairUtil.Create(v.Split('=').ElementAt(0), (object)v.Split('=').ElementAt(1))).ToImmutableArray())); } else { throw new ArgumentException("Unexpected language '{0}' for generating custom parse options.", language); } }
internal virtual async Task <ImmutableDictionary <Project, ImmutableArray <Diagnostic> > > GetProjectDiagnosticsToFixAsync( FixAllContext fixAllContext) { using (Logger.LogBlock( FunctionId.CodeFixes_FixAllOccurrencesComputation_Project_Diagnostics, FixAllLogger.CreateCorrelationLogMessage(fixAllContext.State.CorrelationId), fixAllContext.CancellationToken)) { var project = fixAllContext.Project; if (project != null) { switch (fixAllContext.Scope) { case FixAllScope.Project: var diagnostics = await fixAllContext.GetProjectDiagnosticsAsync(project).ConfigureAwait(false); var kvp = SpecializedCollections.SingletonEnumerable(KeyValuePairUtil.Create(project, diagnostics)); return(ImmutableDictionary.CreateRange(kvp)); case FixAllScope.Solution: var projectsAndDiagnostics = ImmutableDictionary.CreateBuilder <Project, ImmutableArray <Diagnostic> >(); var tasks = project.Solution.Projects.Select(async p => new { Project = p, Diagnostics = await fixAllContext.GetProjectDiagnosticsAsync(p).ConfigureAwait(false) }).ToArray(); await Task.WhenAll(tasks).ConfigureAwait(false); foreach (var task in tasks) { var projectAndDiagnostics = await task.ConfigureAwait(false); if (projectAndDiagnostics.Diagnostics.Any()) { projectsAndDiagnostics[projectAndDiagnostics.Project] = projectAndDiagnostics.Diagnostics; } } return(projectsAndDiagnostics.ToImmutable()); } } return(ImmutableDictionary <Project, ImmutableArray <Diagnostic> > .Empty); } }
public async Task <ImmutableDictionary <Document, ImmutableArray <TextSpan> > > GetFixAllSpansAsync( Document document, TextSpan diagnosticSpan, FixAllScope fixAllScope, CancellationToken cancellationToken) { Contract.ThrowIfFalse(fixAllScope is FixAllScope.ContainingMember or FixAllScope.ContainingType); var decl = await GetContainingMemberOrTypeDeclarationAsync(document, fixAllScope, diagnosticSpan, cancellationToken).ConfigureAwait(false); if (decl == null) { return(await GetFixAllSpansIfWithinGlobalStatementAsync(document, diagnosticSpan, fixAllScope, cancellationToken).ConfigureAwait(false)); } if (fixAllScope == FixAllScope.ContainingMember) { return(ImmutableDictionary.CreateRange(SpecializedCollections.SingletonEnumerable( KeyValuePairUtil.Create(document, ImmutableArray.Create(decl.FullSpan))))); } else { var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); var symbol = semanticModel.GetDeclaredSymbol(decl, cancellationToken); if (symbol?.DeclaringSyntaxReferences.Length > 1) { var syntaxFacts = document.GetRequiredLanguageService <ISyntaxFactsService>(); var builder = PooledDictionary <Document, ArrayBuilder <TextSpan> > .GetInstance(); foreach (var syntaxRef in symbol.DeclaringSyntaxReferences) { var documentForLocation = document.Project.GetDocument(syntaxRef.SyntaxTree); Contract.ThrowIfNull(documentForLocation); var root = await syntaxRef.SyntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false); var partialDeclSpan = syntaxFacts.GetContainingTypeDeclaration(root, syntaxRef.Span.Start) !.FullSpan; builder.MultiAdd(documentForLocation, partialDeclSpan); } return(builder.ToImmutableMultiDictionaryAndFree()); } else { return(ImmutableDictionary.CreateRange(SpecializedCollections.SingletonEnumerable( KeyValuePairUtil.Create(document, ImmutableArray.Create(decl.FullSpan))))); } } }
public void KnownMatches() { TestNode x1, x2; var oldRoot = new TestNode(0, 1, x1 = new TestNode(1, 1)); var newRoot = new TestNode(0, 1, x2 = new TestNode(1, 2)); var m = TestTreeComparer.Instance.ComputeMatch(oldRoot, newRoot, new[] { KeyValuePairUtil.Create(x1, x2), KeyValuePairUtil.Create(x1, x2) }); Assert.True(m.TryGetNewNode(x1, out var n)); Assert.Equal(n, x2); Assert.Throws <ArgumentException>(() => TestTreeComparer.Instance.ComputeMatch(oldRoot, newRoot, new[] { KeyValuePairUtil.Create(x1, x1) })); Assert.Throws <ArgumentException>(() => TestTreeComparer.Instance.ComputeMatch(oldRoot, newRoot, new[] { KeyValuePairUtil.Create(x1, x2), KeyValuePairUtil.Create(x1, new TestNode(0, 0)) })); }
public void ReferenceSearchPaths_LIB() { var cwd = Temp.CreateDirectory(); cwd.CreateFile("a.csx").WriteAllText(@"Console.Write(typeof(C).Name);"); var dir = Temp.CreateDirectory(); dir.CreateFile("C.dll").WriteAllBytes(TestResources.General.C1); var result = ProcessUtilities.Run( CsiPath, "/r:C.dll a.csx", workingDirectory: cwd.Path, additionalEnvironmentVars: new[] { KeyValuePairUtil.Create("LIB", dir.Path) } ); // error CS0006: Metadata file 'C.dll' could not be found Assert.True(result.Errors.StartsWith("error CS0006", StringComparison.Ordinal)); Assert.True(result.ContainsErrors); }