<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using NHamlLanguagePackageLib;
using System.IO;

namespace NHamlLanguage
{
    public class SourceSupervisor : ISourceSupervisor
    {
        readonly INHamlSource _source;
        readonly string _path;

        uint _dwLastCookie;
        readonly IDictionary<uint, ISourceSupervisorEvents> _events = new Dictionary<uint, ISourceSupervisorEvents>();

        public SourceSupervisor(INHamlSource source)
        {
            _source = source;

            IVsHierarchy hierarchy;
            uint itemid;
            IVsTextLines buffer;
            _source.GetDocument(out hierarchy, out itemid, out buffer);
            _path = GetDocumentPath(hierarchy, itemid);
        }

        private static string GetDocumentPath(IVsHierarchy hierarchy, uint itemid)
        {
            var rootid = -2;
            var rootItem = new HierarchyItem(hierarchy, (uint)rootid);
            var viewItem = rootItem.FirstOrDefault(child => child.Name == "Views");

            var docItem = new HierarchyItem(hierarchy, itemid);
            var path = docItem.Name;
            while (!Equals(docItem.Parent, viewItem) &&
                   !Equals(docItem.Parent, rootItem))
            {
                docItem = docItem.Parent;
                path = docItem.Name + "\\" + path;
            }

            if (Equals(docItem.Parent, rootItem))
                path = "$\\" + path;

            return path;
        }

        public void Advise(ISourceSupervisorEvents pEvents, out uint pdwCookie)
        {
            pdwCookie = ++_dwLastCookie;
            _events[_dwLastCookie] = pEvents;
        }

        public void Unadvise(uint dwCookie)
        {
            if (_events.ContainsKey(dwCookie))
                _events.Remove(dwCookie);
        }


        public void PrimaryTextChanged(int processImmediately)
        {
            string primaryText = _source.GetPrimaryText();
            var sb = new NHamlParser(primaryText);

            sb.Parse();

            var result = sb.codeMapper.output;
            var mappings = sb.codeMapper.mappings;
            var paints = sb.codeMapper.paintings;

            int cMappings = mappings.Length;
            if (cMappings == 0)
                mappings = new _SOURCEMAPPING[1];

            int cPaints = paints.Length;
            if (cPaints == 0)
                paints = new _SOURCEPAINTING[1];

            using (var tw = new StreamWriter(@"e:\output.txt"))
            {
              tw.Write(result);
            }

            foreach (var events in _events.Values)
            {
                events.OnGenerated(
                    primaryText,
                    result,
                    cMappings,
                    ref mappings[0],
                    cPaints,
                    ref paints[0]);
            }
        }

        public void OnTypeChar(IVsTextView pView, string ch)
        {
        }

    }
}<commit_msg>Bump v0.3. Downloads here: http://github.com/sztupy/nhamlsense/downloads<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using NHamlLanguagePackageLib;
using System.IO;

namespace NHamlLanguage
{
    public class SourceSupervisor : ISourceSupervisor
    {
        readonly INHamlSource _source;
        readonly string _path;

        uint _dwLastCookie;
        readonly IDictionary<uint, ISourceSupervisorEvents> _events = new Dictionary<uint, ISourceSupervisorEvents>();

        public SourceSupervisor(INHamlSource source)
        {
            _source = source;

            IVsHierarchy hierarchy;
            uint itemid;
            IVsTextLines buffer;
            _source.GetDocument(out hierarchy, out itemid, out buffer);
            _path = GetDocumentPath(hierarchy, itemid);
        }

        private static string GetDocumentPath(IVsHierarchy hierarchy, uint itemid)
        {
            var rootid = -2;
            var rootItem = new HierarchyItem(hierarchy, (uint)rootid);
            var viewItem = rootItem.FirstOrDefault(child => child.Name == "Views");

            var docItem = new HierarchyItem(hierarchy, itemid);
            var path = docItem.Name;
            while (!Equals(docItem.Parent, viewItem) &&
                   !Equals(docItem.Parent, rootItem))
            {
                docItem = docItem.Parent;
                path = docItem.Name + "\\" + path;
            }

            if (Equals(docItem.Parent, rootItem))
                path = "$\\" + path;

            return path;
        }

        public void Advise(ISourceSupervisorEvents pEvents, out uint pdwCookie)
        {
            pdwCookie = ++_dwLastCookie;
            _events[_dwLastCookie] = pEvents;
        }

        public void Unadvise(uint dwCookie)
        {
            if (_events.ContainsKey(dwCookie))
                _events.Remove(dwCookie);
        }


        public void PrimaryTextChanged(int processImmediately)
        {
            string primaryText = _source.GetPrimaryText();
            var sb = new NHamlParser(primaryText);

            sb.Parse();

            var result = sb.codeMapper.output;
            var mappings = sb.codeMapper.mappings;
            var paints = sb.codeMapper.paintings;

            int cMappings = mappings.Length;
            if (cMappings == 0)
                mappings = new _SOURCEMAPPING[1];

            int cPaints = paints.Length;
            if (cPaints == 0)
                paints = new _SOURCEPAINTING[1];

            // Simple debug
            /*using (var tw = new StreamWriter(@"e:\output.txt"))
            {
              tw.Write(result);
            }*/

            foreach (var events in _events.Values)
            {
                events.OnGenerated(
                    primaryText,
                    result,
                    cMappings,
                    ref mappings[0],
                    cPaints,
                    ref paints[0]);
            }
        }

        public void OnTypeChar(IVsTextView pView, string ch)
        {
        }

    }
}
{'fraction_non_alphanumeric': 0.08331987728080091, 'fraction_numerical': 0.0025835620862263847, 'mean_word_length': 1.6135021097046414, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6064250', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1598, 'n_words': 372}