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 sdkInfo = context.ResolveSdk(this, sdk.id, sdk.span); if (sdkInfo == null) { continue; } yield return(sdk.id, sdkInfo.Path, sdk.span); if (IsToplevel) { Annotations.Add(sdksAtt, new NavigationAnnotation(sdkInfo.Path, sdk.span) { IsSdk = true }); } if (sdkInfo.AdditionalPaths != null && sdkInfo.AdditionalPaths.Count > 0) { foreach (var p in sdkInfo.AdditionalPaths) { yield return(sdk.id, p, sdk.span); } if (IsToplevel) { foreach (var p in sdkInfo.AdditionalPaths) { Annotations.Add(sdksAtt, new NavigationAnnotation(p, sdk.span) { IsSdk = true }); } } } } } }
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 = new ExpressionNode[] { importAtt.Value }; importTxt = importAtt.XAttribute.Value; } if (sdkAtt?.Value is ExpressionText sdkTxt) { var loc = sdkAtt.XAttribute.ValueSpan; var sdkInfo = parseContext.ResolveSdk(this, sdkTxt.Value, loc); if (sdkInfo == null) { if (IsToplevel) { Diagnostics.Add(CoreDiagnostics.UnresolvedSdk, loc, sdkTxt.Value); } return; } if (import != null) { if (sdkInfo.AdditionalPaths != null && sdkInfo.AdditionalPaths.Count > 0) { import = new ExpressionNode[sdkInfo.AdditionalPaths.Count + 1]; for (int i = 0; i < sdkInfo.AdditionalPaths.Count; i++) { import[i + 1] = new ExpressionText(0, Path.Combine(sdkInfo.AdditionalPaths[i], importTxt), true); } } import[0] = new ExpressionText(0, Path.Combine(sdkInfo.Path, importTxt), true); } if (IsToplevel) { Annotations.Add(sdkAtt.XAttribute, new NavigationAnnotation(sdkInfo.Path, loc)); } } if (import != null) { bool wasResolved = false; var loc = importAtt.XAttribute.ValueSpan; foreach (var resolvedImport in import.SelectMany(imp => importResolver.Resolve(imp, importTxt, null))) { 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); } } }