コード例 #1
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            var componentModel = (IComponentModel)this.GetService(typeof(SComponentModel));
            var workspace      = componentModel.GetService <VisualStudioWorkspace>();

            ExcessLanguageService langService = new ExcessLanguageService(workspace);

            langService.SetSite(this);

            IServiceContainer serviceContainer = this as IServiceContainer;

            serviceContainer.AddService(typeof(ExcessLanguageService), langService, true);

            // Register a timer to call our language service during
            // idle periods.
            IOleComponentManager mgr = GetService(typeof(SOleComponentManager))
                                       as IOleComponentManager;

            if (_componentID == 0 && mgr != null)
            {
                OLECRINFO[] crinfo = new OLECRINFO[1];
                crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO));
                crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime |
                                   (uint)_OLECRF.olecrfNeedPeriodicIdleTime;
                crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal |
                                     (uint)_OLECADVF.olecadvfRedrawOff |
                                     (uint)_OLECADVF.olecadvfWarningsOff;
                crinfo[0].uIdleTimeInterval = 1000;
                int hr = mgr.FRegisterComponent(this, crinfo, out _componentID);
            }
        }
コード例 #2
0
        public override void BeginParse()
        {
            if (_document != null)
            {
                //td: cancel
            }

            ExcessLanguageService service = (ExcessLanguageService)this.LanguageService;

            _document = service.CreateExcessDocument(GetText(), _id);
            _document.applyChanges(CompilerStage.Syntactical);

            _document.SyntaxRoot = _document.SyntaxRoot.NormalizeWhitespace(elasticTrivia: true); //td: optimize
            if (!saveCodeBehind(_document.SyntaxRoot))
            {
                return; //td: error?
            }
            if (!_document.HasSemanticalChanges())
            {
                return;
            }

            var doc          = _workspace.CurrentSolution.GetDocument(_id);
            var semanticRoot = doc.GetSyntaxRootAsync().Result;

            _document.Mapper.SemanticalChange(_document.SyntaxRoot, semanticRoot);

            var model = doc.GetSemanticModelAsync().Result;

            _document.Model = model;
            _document.applyChanges(CompilerStage.Semantical);

            saveCodeBehind(_document.SyntaxRoot);

            base.BeginParse();
        }