void ResolveImport(MSBuildImportElement element, MSBuildParserContext parseContext, MSBuildImportResolver importResolver) { var importAtt = element.ProjectAttribute; var sdkAtt = element.SdkAttribute; ExpressionNode import = null; string importTxt = null; if (importAtt?.Value != null) { import = importAtt.Value; importTxt = importAtt.XAttribute.Value; } if (sdkAtt?.Value is ExpressionText sdkTxt) { var loc = sdkAtt.XAttribute.ValueSpan; string sdkPath = parseContext.GetSdkPath(this, sdkTxt.Value, loc); import = import == null ? null : new ExpressionText(0, Path.Combine(sdkPath, importTxt), true); if (IsToplevel && sdkPath != null) { Annotations.Add(sdkAtt.XAttribute, new NavigationAnnotation(sdkPath, loc)); } } if (import != null) { bool wasResolved = false; var loc = importAtt.XAttribute.ValueSpan; foreach (var resolvedImport in importResolver.Resolve(import, importTxt, null)) { this.AddImport(resolvedImport); wasResolved |= resolvedImport.IsResolved; if (IsToplevel && wasResolved) { Annotations.Add(importAtt.XAttribute, new NavigationAnnotation(resolvedImport.Filename, loc)); } } if (!wasResolved && IsToplevel) { DiagnosticSeverity type = element.ConditionAttribute == null ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning; Diagnostics.Add(CoreDiagnostics.UnresolvedImport, loc, importTxt); } } }
IEnumerable <(string id, string path, TextSpan span)> ResolveSdks(MSBuildProjectElement project, MSBuildParserContext context) { var sdksAtt = project.SdkAttribute?.XAttribute; if (sdksAtt == null) { yield break; } string sdks = sdksAtt.Value; if (string.IsNullOrEmpty(sdks)) { yield break; } int offset = IsToplevel ? sdksAtt.ValueOffset : sdksAtt.Span.Start; foreach (var sdk in SplitSdkValue(offset, sdksAtt.Value)) { if (sdk.id == null) { if (IsToplevel) { Diagnostics.Add(CoreDiagnostics.EmptySdkAttribute, sdk.span); } } else { var sdkPath = context.GetSdkPath(this, sdk.id, sdk.span); if (sdkPath != null) { yield return(sdk.id, sdkPath, sdk.span); } if (IsToplevel) { Annotations.Add(sdksAtt, new NavigationAnnotation(sdkPath, sdk.span) { IsSdk = true }); } } } }
void ResolveImport(XElement element) { var importAtt = element.Attributes[new XName("Project")]; var sdkAtt = element.Attributes[new XName("Sdk")]; string sdkPath = null, import = null; if (!string.IsNullOrWhiteSpace(importAtt?.Value)) { import = importAtt.Value; } if (!string.IsNullOrWhiteSpace(sdkAtt?.Value)) { var loc = sdkAtt.ValueSpan; sdkPath = parseContext.GetSdkPath(Document, sdkAtt.Value, loc); import = import == null ? null : sdkPath + "\\" + import; if (isToplevel && sdkPath != null) { Document.Annotations.Add(sdkAtt, new NavigationAnnotation(sdkPath, loc)); } } if (import != null) { bool wasResolved = false; var loc = importAtt.ValueSpan; foreach (var resolvedImport in importResolver.Resolve(import, null)) { Document.AddImport(resolvedImport); wasResolved |= resolvedImport.IsResolved; if (isToplevel && wasResolved) { Document.Annotations.Add(importAtt, new NavigationAnnotation(resolvedImport.Filename, loc)); } } if (!wasResolved && isToplevel) { DiagnosticSeverity type = element.Attributes.Get(new XName("Condition"), true) == null ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning; Document.Errors.Add(new XmlDiagnosticInfo(type, "Could not resolve import", loc)); } } }
IEnumerable <(string id, string path, TextSpan span)> ResolveSdks(MSBuildParserContext context, XElement project) { var sdksAtt = project.Attributes.Get(new XName("Sdk"), true); if (sdksAtt == null) { yield break; } string sdks = sdksAtt?.Value; if (string.IsNullOrEmpty(sdks)) { yield break; } int offset = IsToplevel ? sdksAtt.ValueOffset : sdksAtt.Span.Start; foreach (var sdk in SplitSdkValue(offset, sdksAtt.Value)) { if (sdk.id == null) { if (IsToplevel) { Errors.Add(new XmlDiagnosticInfo(DiagnosticSeverity.Warning, "Empty value", sdk.span)); } } else { var sdkPath = context.GetSdkPath(this, sdk.id, sdk.span); if (sdkPath != null) { yield return(sdk.id, sdkPath, sdk.span); } if (IsToplevel) { Annotations.Add(sdksAtt, new NavigationAnnotation(sdkPath, sdk.span)); } } } }