HtmlElementInfo GenerateHyperlinkForReference(ReferenceSymbol symbol) { string idHash = symbol.Id.Value; bool isMsBuild = _sourceFile.SourceFile.Info.Language == "msbuild"; bool isDistributedDefinition = symbol.Kind == nameof(SymbolKinds.MSBuildItem) || symbol.Kind == nameof(SymbolKinds.MSBuildItemMetadata) || symbol.Kind == nameof(SymbolKinds.MSBuildProperty) || symbol.Kind == nameof(SymbolKinds.MSBuildTarget) || symbol.Kind == nameof(SymbolKinds.MSBuildTask) || symbol.Kind == nameof(SymbolKinds.MSBuildTaskParameter); var isDefinition = symbol.ReferenceKind == nameof(ReferenceKind.Definition) || isDistributedDefinition; bool isProjectScopedReference = symbol.ReferenceKind == nameof(ReferenceKind.ProjectLevelReference); if (!isDefinition) { idHash = null; } string jsmethod = isDefinition || isProjectScopedReference ? "R" : "D"; string additionalParams = isProjectScopedReference ? $@", '{projectId}'" : string.Empty; string onclick = $@"{jsmethod}('{symbol.ProjectId}', '{symbol.Id}'{additionalParams});return false;"; string url = ""; if (isDefinition) { url = $"/?leftProject={symbol.ProjectId}&leftSymbol={symbol.Id}&file={HttpUtility.UrlEncode(this._sourceFile.SourceFile.Info.Path)}"; } else if (isProjectScopedReference) { url = $"/?leftProject={symbol.ProjectId}&leftSymbol={symbol.Id}&projectScope={projectId}"; } else { url = $"/?rightProject={symbol.ProjectId}&rightSymbol={symbol.Id}"; } var result = new HtmlElementInfo() { Name = "a", Attributes = { { "id", idHash }, { "onclick", onclick }, { "href", url }, { "class", isDistributedDefinition ? "msbuildlink" : null } }, DeclaredSymbolId = symbol.Id.Value, RequiresWrappingSpan = isMsBuild, }; return(result); }
public static ReferenceSymbol TryAddDefinition(this ReferenceSymbol referenceSymbol, ConcurrentDictionary <string, DefinitionSymbol> symbolMap, string shortName, string containerName = null) { if (!symbolMap.ContainsKey(referenceSymbol.Id.Value)) { symbolMap.TryAdd(referenceSymbol.Id.Value, new DefinitionSymbol(referenceSymbol) { ShortName = shortName, ContainerQualifiedName = containerName, }); } return(referenceSymbol); }
private void CreateReferencedProjectFiles(RepoProject repoProject) { foreach (var project in ReferencedProjects.Values) { if (project.Definitions.Count == 0) { continue; } CreateMetadataFile(repoProject, GetProjectReferenceSymbolsPath(project.ProjectId), () => { XElement container = null; return(Element("ReferenceSymbols") .AddAttribute("Count", project.Definitions.Count) .ForEach(project.Definitions, (el, definition) => { var nsdata = definition.ExtData as NamespaceExtensionData; container = nsdata?.GetNamespaceElement(el) ?? el; if (definition.DisplayName.StartsWith(nsdata?.Qualifier ?? string.Empty)) { ReferenceSymbol reference = definition; reference.ReferenceKind = nameof(ReferenceKind.ProjectLevelReference); reference.ExcludeFromSearch = true; container.AddElement("Symbol", symbolElement => symbolElement .AddAttribute("Name", definition.DisplayName .Substring(nsdata?.Qualifier.Length ?? 0), reference) .AddAttribute("ReferenceCount", definition.ReferenceCount.ToString())); } })); }); } CreateMetadataFile(repoProject, "ReferenceProjects.xml", () => { return(Element("ReferenceProjects").ForEach(ReferencedProjects.Values .OrderBy(rp => rp.ProjectId, StringComparer.OrdinalIgnoreCase) .ThenBy(rp => rp.DisplayName, StringComparer.OrdinalIgnoreCase), (el, project) => { ReferenceSymbol fileRef = project.Definitions.Count == 0 ? null : CreateFileReferenceSymbol( GetMetadataFilePath(GetProjectReferenceSymbolsPath(project.ProjectId)), Project.Id); el.AddElement("Project", projElement => projElement .AddAttribute("ReferenceCount", project.Definitions.Count.ToString(), fileRef) .AddAttribute("Name", project.ProjectId) .AddAttribute("FullName", project.DisplayName)); })); }); }
public static ReferenceSymbolModel FromObjectModel(ReferenceSymbol symbol) { var result = new ReferenceSymbolModel { ProjectId = symbol.ProjectId, Id = symbol.Id.Value, Kind = symbol.Kind, ReferenceKind = symbol.ReferenceKind, ExcludeFromDefaultSearch = symbol.ExcludeFromDefaultSearch, ExcludeFromSearch = symbol.ExcludeFromSearch, IsImplicitlyDeclared = symbol.IsImplicitlyDeclared }; return(result); }
public static bool IsMSBuildReference(ReferenceSymbol symbol) { switch (symbol.Kind) { case nameof(SymbolKinds.MSBuildItem): case nameof(SymbolKinds.MSBuildItemMetadata): case nameof(SymbolKinds.MSBuildProperty): case nameof(SymbolKinds.MSBuildTarget): case nameof(SymbolKinds.MSBuildTask): case nameof(SymbolKinds.MSBuildTaskParameter): return(true); default: return(false); } }
public static ReferenceSymbol TryAddDefinition(this ReferenceSymbol referenceSymbol, ConcurrentDictionary <string, DefinitionSymbol> symbolMap, string shortName, string containerName = null) { if (!symbolMap.ContainsKey(referenceSymbol.Id.Value)) { symbolMap.TryAdd(referenceSymbol.Id.Value, new DefinitionSymbol() { Id = SymbolId.UnsafeCreateWithValue(referenceSymbol.Id.Value), Kind = referenceSymbol.Kind, ProjectId = referenceSymbol.ProjectId, ShortName = shortName, ContainerQualifiedName = containerName, Uid = referenceSymbol.Id.Value, }); } return(referenceSymbol); }
private ReferenceSymbol GetReferenceSymbol(ISymbol symbol, ReferenceKind referenceKind, string id = null) { // Use unspecialized generic // TODO: Consider adding reference symbol for specialized generic as well so one can find all references // to List<string>.Add rather than just List<T>.Add symbol = symbol.OriginalDefinition; var boundSymbol = new ReferenceSymbol() { ProjectId = symbol.ContainingAssembly.Name, Id = CreateSymbolId(id ?? GetDocumentationCommentId(symbol)), Kind = GetSymbolKind(symbol), ReferenceKind = referenceKind.GetString(), IsImplicitlyDeclared = symbol.IsImplicitlyDeclared }; if (!string.IsNullOrEmpty(symbol.Name)) { DefinitionSymbol definition; if (!context.ReferenceDefinitionMap.TryGetValue(boundSymbol.Id.Value, out definition)) { var createdDefinition = GetDefinitionSymbol(symbol); definition = context.ReferenceDefinitionMap.GetOrAdd(boundSymbol.Id.Value, createdDefinition); if (createdDefinition == definition) { if (symbol.Kind != SymbolKind.Namespace && symbol.ContainingNamespace != null && !symbol.ContainingNamespace.IsGlobalNamespace) { var namespaceSymbol = GetReferenceSymbol(symbol.ContainingNamespace, ReferenceKind.Reference); var extData = context.GetReferenceNamespaceData(namespaceSymbol.Id.Value); definition.ExtData = extData; } } } if (referenceKind != ReferenceKind.Definition) { definition.IncrementReferenceCount(); } } return(boundSymbol); }
private static void AnnotateReference(BoundSourceFileBuilder binder, ReferenceSymbol projectFileReference, Microsoft.CodeAnalysis.Text.TextSpan span) { binder.AnnotateClassification(span.Start, span.Length, ClassificationTypeNames.XmlLiteralAttributeValue); binder.AnnotateReferences(span.Start, span.Length, projectFileReference); }