<commit_before>﻿using JetBrains.Annotations;
using JetBrains.Application.Settings;
using JetBrains.DocumentModel;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Daemon.CSharp.Stages;
using JetBrains.ReSharper.Feature.Services.Daemon;
using JetBrains.ReSharper.FeaturesTestFramework.Daemon;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Resources.Shell;
using JetBrains.ReSharper.TestFramework;
using JetBrains.TextControl;
using JetBrains.TextControl.DocumentMarkup;
using JetBrains.Util;
using NUnit.Framework;

namespace JetBrains.ReSharper.Plugins.Unity.Tests.Feature.Services.Descriptions
{
    // The default implementation doesn't handle resolving overlapping highlightings
    [Category("Daemon")]
    public class IdentifierTooltipTestBase : BaseTestWithTextControl
    {
        protected override void DoTestSolution(params string[] fileSet)
        {
            ExecuteWithinSettingsTransaction(store =>
            {
                RunGuarded(() => store.SetValue(HighlightingSettingsAccessor.IdentifierHighlightingEnabled, true));
                base.DoTestSolution(fileSet);
            });
        }

        protected override void DoTest(IProject testProject)
        {
            testProject.GetSolution().GetPsiServices().Files.CommitAllDocuments();
            using (ITextControl textControl = OpenTextControl(testProject))
            {
                var document = textControl.Document;
                var psiSourceFile = document.GetPsiSourceFile(Solution);
                Assert.IsNotNull(psiSourceFile, "sourceFile == null");
                using (ReadLockCookie.Create())
                {
                    var highlightingFinder = new IdentifierHighlightingFinder(psiSourceFile, new DocumentRange(document, new TextRange(textControl.Caret.Offset())));
                    highlightingFinder.DoHighlighting(DaemonProcessKind.VISIBLE_DOCUMENT);
                    var highlightingInfo = highlightingFinder.HighlightingInfo;
                    Assertion.AssertNotNull(highlightingInfo, "Highlighting not found");
                    var markupModel = Solution.GetComponent<IDocumentMarkupManager>().GetMarkupModel(document);
                    var highlighterTooltipProvider = DaemonUtil.GetHighlighterTooltipProvider(highlightingInfo.Highlighting, Solution);
                    var attributeId = HighlightingSettingsManager.Instance.GetAttributeId(highlightingInfo.Highlighting, psiSourceFile).NotNull();
                    var highlighter = markupModel.AddHighlighter(new Key("test"), highlightingInfo.Range.TextRange, AreaType.EXACT_RANGE, 0, attributeId, new ErrorStripeAttributes(), highlighterTooltipProvider);
                    ExecuteWithGold(writer => writer.WriteLine(highlighter.ToolTip));
                }
            }
        }

        private class IdentifierHighlightingFinder : TestDaemonProcess
        {
            private readonly DocumentRange myCaretRange;

            public HighlightingInfo HighlightingInfo { get; private set; }<commit_msg>Fix the compilation of the tests<commit_after>﻿using JetBrains.Annotations;
using JetBrains.Application.Settings;
using JetBrains.DocumentModel;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Daemon.CSharp.Stages;
using JetBrains.ReSharper.Feature.Services.Daemon;
using JetBrains.ReSharper.FeaturesTestFramework.Daemon;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Resources.Shell;
using JetBrains.ReSharper.TestFramework;
using JetBrains.TextControl;
using JetBrains.TextControl.DocumentMarkup;
using JetBrains.Util;
using NUnit.Framework;

namespace JetBrains.ReSharper.Plugins.Unity.Tests.Feature.Services.Descriptions
{
    // The default implementation doesn't handle resolving overlapping highlightings
    [Category("Daemon")]
    public class IdentifierTooltipTestBase : BaseTestWithTextControl
    {
        protected override void DoTestSolution(params string[] fileSet)
        {
            ExecuteWithinSettingsTransaction(store =>
            {
                RunGuarded(() => store.SetValue(HighlightingSettingsAccessor.IdentifierHighlightingEnabled, true));
                base.DoTestSolution(fileSet);
            });
        }

        protected override void DoTest(IProject testProject)
        {
            testProject.GetSolution().GetPsiServices().Files.CommitAllDocuments();
            using (ITextControl textControl = OpenTextControl(testProject))
            {
                var document = textControl.Document;
                var psiSourceFile = document.GetPsiSourceFile(Solution);
                Assert.IsNotNull(psiSourceFile, "sourceFile == null");
                using (ReadLockCookie.Create())
                {
                    var highlightingFinder = new IdentifierHighlightingFinder(psiSourceFile, new DocumentRange(document, new TextRange(textControl.Caret.Offset())));
                    highlightingFinder.DoHighlighting(DaemonProcessKind.VISIBLE_DOCUMENT);
                    var highlightingInfo = highlightingFinder.HighlightingInfo;
                    Assertion.AssertNotNull(highlightingInfo, "Highlighting not found");
                    var markupModel = Solution.GetComponent<IDocumentMarkupManager>().GetMarkupModel(document);
                    var highlighterTooltipProvider = DaemonUtil.GetHighlighterTooltipProvider(highlightingInfo.Highlighting, Solution);
                    var attributeId = HighlightingSettingsManager.Instance.GetAttributeId(highlightingInfo.Highlighting, psiSourceFile).NotNull();
                    var highlighter = markupModel.AddHighlighter("test", highlightingInfo.Range.TextRange, AreaType.EXACT_RANGE, 0, attributeId, new ErrorStripeAttributes(), highlighterTooltipProvider);
                    ExecuteWithGold(writer => writer.WriteLine(highlighter.ToolTip));
                }
            }
        }

        private class IdentifierHighlightingFinder : TestDaemonProcess
        {
            private readonly DocumentRange myCaretRange;

            public HighlightingInfo HighlightingInfo { get; private set; }
{'fraction_non_alphanumeric': 0.07636603028308098, 'fraction_numerical': 0.0003291639236339697, 'mean_word_length': 3.1651816312542835, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7252585', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1484, 'n_words': 262}