/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/ContextQuery/SyntaxTreeExtensions.cs
34 строки
1 KB
Cyrus Najmabadi
Remove unnecessary imports
10 мар 2025, 17:04
10 мар 2025, 17:04
58c992f
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #nullable disable using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Shared.Extensions; namespace Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery; internal static partial class SyntaxTreeExtensions { public static bool IsPreProcessorDirectiveContext(this SyntaxTree syntaxTree, int position, SyntaxToken preProcessorTokenOnLeftOfPosition, CancellationToken cancellationToken) { var token = preProcessorTokenOnLeftOfPosition; var directive = token.GetAncestor<DirectiveTriviaSyntax>(); // Directives contain the EOL, so if the position is within the full span of the // directive, then it is on that line, the only exception is if the directive is on the // last line, the position at the end if technically not contained by the directive but // its also not on a new line, so it should be considered part of the preprocessor // context. if (directive == null) { return false; } return directive.FullSpan.Contains(position) || directive.FullSpan.End == syntaxTree.GetRoot(cancellationToken).FullSpan.End; } }