From 1ffc41bff8d199fc2fdcd6b951f407d1e84202ed Mon Sep 17 00:00:00 2001 From: David Wengier Date: Mon, 16 Jan 2023 18:08:39 +1100 Subject: [PATCH 1/4] Cache classified spans and tag helper spans --- .../DefaultRazorDocumentMappingService.cs | 47 +++++++++++++++++-- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorDocumentMappingService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorDocumentMappingService.cs index c1b4f113d48..18d08094931 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorDocumentMappingService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorDocumentMappingService.cs @@ -418,10 +418,9 @@ public override RazorLanguageKind GetLanguageKind(RazorCodeDocument codeDocument throw new ArgumentNullException(nameof(codeDocument)); } - var syntaxTree = codeDocument.GetSyntaxTree(); - var classifiedSpans = syntaxTree.GetClassifiedSpans(); - var tagHelperSpans = syntaxTree.GetTagHelperSpans(); - var documentLength = codeDocument.GetSourceText().Length; + var classifiedSpans = GetClassifiedSpans(codeDocument); + var tagHelperSpans = GetTagHelperSpans(codeDocument); + var documentLength = codeDocument.Source.Length; var languageKind = GetLanguageKindCore(classifiedSpans, tagHelperSpans, originalIndex, documentLength, rightAssociative); return languageKind; @@ -903,4 +902,44 @@ private TextEdit[] RemapTextEditsCore(Uri virtualDocumentUri, RazorCodeDocument return edits; } + + private static IReadOnlyList GetClassifiedSpans(RazorCodeDocument document) + { + // Since this service is called so often, we get a good performance improvement by caching these values + // for this code document. If the document changes, as the user types, then the document instance will be + // different, so we don't need to worry about invalidating the cache. + var classifiedSpans = (IReadOnlyList)document.Items[typeof(ClassifiedSpanInternal)]; + if (classifiedSpans is null) + { + var syntaxTree = document.GetSyntaxTree(); + + var visitor = new ClassifiedSpanVisitor(syntaxTree.Source); + visitor.Visit(syntaxTree.Root); + classifiedSpans = visitor.ClassifiedSpans; + + document.Items[typeof(ClassifiedSpanInternal)] = classifiedSpans; + } + + return classifiedSpans; + } + + private static IReadOnlyList GetTagHelperSpans(RazorCodeDocument document) + { + // Since this service is called so often, we get a good performance improvement by caching these values + // for this code document. If the document changes, as the user types, then the document instance will be + // different, so we don't need to worry about invalidating the cache. + var tagHelperSpans = (IReadOnlyList)document.Items[typeof(TagHelperSpanInternal)]; + if (tagHelperSpans is null) + { + var syntaxTree = document.GetSyntaxTree(); + + var visitor = new TagHelperSpanVisitor(syntaxTree.Source); + visitor.Visit(syntaxTree.Root); + tagHelperSpans = visitor.TagHelperSpans; + + document.Items[typeof(TagHelperSpanInternal)] = tagHelperSpans; + } + + return tagHelperSpans; + } } From b79b1c1a29b2acc5b7c95cddbe376309990c5c4c Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Thu, 2 Mar 2023 13:47:02 -0800 Subject: [PATCH 2/4] Disable integration tests in 17.6 --- azure-pipelines.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ca7f31c7451..d44a83e110e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -231,10 +231,12 @@ stages: -configuration $(_BuildConfig) -prepareMachine -test - -integrationTest + # https://github.com/dotnet/razor/issues/8378 + # -integrationTest /p:BuildProjectReferences=false name: Run_Tests - displayName: Run Unit and Integration tests + # displayName: Run Unit and Integration tests + displayName: Run Unit tests condition: succeeded() - task: PublishBuildArtifacts@1 From 05b6b5d51a11b0849d640a27d1d006b4160682ab Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Thu, 2 Mar 2023 13:59:08 -0800 Subject: [PATCH 3/4] Fix yaml syntax error --- azure-pipelines.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d44a83e110e..05fd348b24b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -227,12 +227,13 @@ stages: - powershell: eng\SetupVSHive.ps1 displayName: Setup VS Hive + # https://github.com/dotnet/razor/issues/8378 + # Restore the following flag to the below script to re-enable integration tests. + # -integrationTest - script: eng\CIBuild.cmd -configuration $(_BuildConfig) -prepareMachine -test - # https://github.com/dotnet/razor/issues/8378 - # -integrationTest /p:BuildProjectReferences=false name: Run_Tests # displayName: Run Unit and Integration tests From 0bc049d49674e2e8d151266fb5e18ed4272601ef Mon Sep 17 00:00:00 2001 From: Allison Chou Date: Fri, 17 Mar 2023 15:01:20 -0700 Subject: [PATCH 4/4] Fix build break --- .../DefaultRazorDocumentMappingService.cs | 40 ------------------- 1 file changed, 40 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorDocumentMappingService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorDocumentMappingService.cs index 23caf3123d6..07f5855fa60 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorDocumentMappingService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorDocumentMappingService.cs @@ -994,44 +994,4 @@ private static IReadOnlyList GetTagHelperSpans(RazorCodeD return tagHelperSpans; } - - private static IReadOnlyList GetClassifiedSpans(RazorCodeDocument document) - { - // Since this service is called so often, we get a good performance improvement by caching these values - // for this code document. If the document changes, as the user types, then the document instance will be - // different, so we don't need to worry about invalidating the cache. - var classifiedSpans = (IReadOnlyList)document.Items[typeof(ClassifiedSpanInternal)]; - if (classifiedSpans is null) - { - var syntaxTree = document.GetSyntaxTree(); - - var visitor = new ClassifiedSpanVisitor(syntaxTree.Source); - visitor.Visit(syntaxTree.Root); - classifiedSpans = visitor.ClassifiedSpans; - - document.Items[typeof(ClassifiedSpanInternal)] = classifiedSpans; - } - - return classifiedSpans; - } - - private static IReadOnlyList GetTagHelperSpans(RazorCodeDocument document) - { - // Since this service is called so often, we get a good performance improvement by caching these values - // for this code document. If the document changes, as the user types, then the document instance will be - // different, so we don't need to worry about invalidating the cache. - var tagHelperSpans = (IReadOnlyList)document.Items[typeof(TagHelperSpanInternal)]; - if (tagHelperSpans is null) - { - var syntaxTree = document.GetSyntaxTree(); - - var visitor = new TagHelperSpanVisitor(syntaxTree.Source); - visitor.Visit(syntaxTree.Root); - tagHelperSpans = visitor.TagHelperSpans; - - document.Items[typeof(TagHelperSpanInternal)] = tagHelperSpans; - } - - return tagHelperSpans; - } }