/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/LanguageServer/ProtocolUnitTests/TestSourceGeneratedDocumentSpanMappingService.cs
68 строк
3 KB
David Wengier
Consolidate to just one IsRazorSourceDocument extension method properly
29 апр 2026, 06:33
29 апр 2026, 06:33
5498d93
Код
Авторство
О чём код?
// 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; using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.LanguageServer.UnitTests; [ExportWorkspaceService(typeof(ISourceGeneratedDocumentSpanMappingService))] [Shared] [PartNotDiscoverable] [method: ImportingConstructor] [method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] internal class TestSourceGeneratedDocumentSpanMappingService() : ISourceGeneratedDocumentSpanMappingService { public bool DidMapSpans { get; private set; } public bool DidMapEdits { get; private set; } public bool Enabled { get; set; } = true; private readonly Dictionary<string, string> _mappedFileNames = []; internal void AddMappedFileName(string filePath, string mappedFilePath) { _mappedFileNames[filePath] = mappedFilePath; } public bool CanMapSpans(SourceGeneratedDocument sourceGeneratedDocument) { return Enabled && sourceGeneratedDocument.IsRazorSourceGeneratedDocument(); } public async Task<ImmutableArray<MappedTextChange>> GetMappedTextChangesAsync(SourceGeneratedDocument oldDocument, SourceGeneratedDocument newDocument, CancellationToken cancellationToken) { if (oldDocument.IsRazorSourceGeneratedDocument()) { DidMapEdits = true; var changes = await newDocument.GetTextChangesAsync(oldDocument, cancellationToken); return changes.SelectAsArray(c => new MappedTextChange(_mappedFileNames[newDocument.FilePath], c)); } return []; } public async Task<ImmutableArray<MappedSpanResult>> MapSpansAsync(SourceGeneratedDocument document, ImmutableArray<TextSpan> spans, CancellationToken cancellationToken) { if (document.IsRazorSourceGeneratedDocument()) { var sourceText = await document.GetTextAsync(cancellationToken); DidMapSpans = true; return spans.SelectAsArray(s => new MappedSpanResult(document.FilePath, sourceText.Lines.GetLinePositionSpan(s), s)); } return []; } }