Ejemplo n.º 1
0
        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];

            foreach (var events in _events.Values)
            {
                events.OnGenerated(
                    primaryText,
                    result,
                    cMappings,
                    ref mappings[0],
                    cPaints,
                    ref paints[0]);
            }
        }
        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]);
            }
        }
Ejemplo n.º 3
0
        public void PrimaryTextChanged(int processImmediately)
        {
            var primaryText = _source.GetPrimaryText();
            var sourceContext = new SourceContext(primaryText, 0, _path);
            var result = _grammar.Nodes(new Position(sourceContext));

            var descriptor = new SparkViewDescriptor()
                .AddTemplate(_path);

            var entry = _engine.CreateEntry(_engine.CreateKey(descriptor), false);

            var mappings = entry.SourceMappings
                .Where(m => string.Equals(m.Source.Begin.SourceContext.FileName, _path,
                                          StringComparison.InvariantCultureIgnoreCase))
                .Select(m => new _SOURCEMAPPING
                                 {
                                     start1 = m.Source.Begin.Offset,
                                     end1 = m.Source.End.Offset,
                                     start2 = m.OutputBegin,
                                     end2 = m.OutputEnd
                                 })
                .ToArray();

            var paints = result.Rest.GetPaint()
                .OfType<Paint<SparkTokenType>>()
                .Where(p => string.Equals(p.Begin.SourceContext.FileName, _path,
                                          StringComparison.InvariantCultureIgnoreCase))
                .Select(p => new _SOURCEPAINTING
                                 {
                                     start = p.Begin.Offset,
                                     end = p.End.Offset,
                                     color = (int)p.Value
                                 })
                .ToArray();

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

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

            foreach (var events in _events.Values)
            {
                events.OnGenerated(
                    primaryText,
                    entry.SourceCode,
                    cMappings,
                    ref mappings[0],
                    cPaints,
                    ref paints[0]);
            }
        }
Ejemplo n.º 4
0
            unsafe public void OnGenerated(string primaryText, string secondaryText, int cMappings, ref _SOURCEMAPPING rgSpans, int cPaints, ref _SOURCEPAINTING rgPaints)
            {
                Mapping = new _SOURCEMAPPING[cMappings];

                fixed(_SOURCEMAPPING *sourcemapping = &rgSpans)
                {
                    for (var index = 0; index != cMappings; ++index)
                    {
                        Mapping[index] = sourcemapping[index];
                    }
                }
            }
Ejemplo n.º 5
0
        public void PrimaryTextChangedCausesEventToFire()
        {
            var hier   = _repos.PartialMock <StubHierarchy>();
            var buffer = _repos.StrictMock <IVsTextLines>();

            var source = _repos.PartialMock <StubSource>(hier, (uint)3, buffer);
            var events = _repos.StrictMock <ISourceSupervisorEvents>();

            var primaryText = "Hello World";

            const string name = @"c:\hello.txt";

            string outname;

            source.Expect(x => x.GetDefaultPageBaseType())
            .Return("FakeBaseType");
            source.Expect(x => x.GetPrimaryText())
            .Return(primaryText);
            source.Expect(x => x.GetRunningDocumentText(name))
            .Return(primaryText).Repeat.AtLeastOnce();
            hier.Expect(x => x.GetCanonicalName(3, out outname))
            .OutRef(name).Repeat.AtLeastOnce();

            var paints = new _SOURCEPAINTING();
            var spans  = new _SOURCEMAPPING();

            events.Expect(x => x.OnGenerated(null, null, 0, ref spans, 0, ref paints))
            .IgnoreArguments();

            _repos.ReplayAll();

            hier.Add(0xfffffffe, new Item {
                { __VSHPROPID.VSHPROPID_FirstChild, 1 }
            });
            hier.Add(1, new Item
            {
                { __VSHPROPID.VSHPROPID_Parent, -2 },
                { __VSHPROPID.VSHPROPID_FirstChild, 2 },
                { __VSHPROPID.VSHPROPID_NextSibling, -1 },
                { __VSHPROPID.VSHPROPID_Name, "Views" },
            });
            hier.Add(2, new Item
            {
                { __VSHPROPID.VSHPROPID_Parent, 1 },
                { __VSHPROPID.VSHPROPID_FirstChild, 3 },
                { __VSHPROPID.VSHPROPID_NextSibling, -1 },
                { __VSHPROPID.VSHPROPID_Name, "Home" },
            });
            hier.Add(3, new Item
            {
                { __VSHPROPID.VSHPROPID_Parent, 2 },
                { __VSHPROPID.VSHPROPID_FirstChild, -1 },
                { __VSHPROPID.VSHPROPID_NextSibling, -1 },
                { __VSHPROPID.VSHPROPID_Name, "Index.spark" },
            });

            uint dwCookie;
            var  sourceSupervisor = new SourceSupervisor(source);

            sourceSupervisor.Advise(events, out dwCookie);
            sourceSupervisor.PrimaryTextChanged(1);

            _repos.VerifyAll();
        }