예제 #1
0
        public Task <Diagnostic[]> StartTypeCheck()
        {
            _cancellation?.Cancel();
            var cancellationTokenSource = new CancellationTokenSource();

            _cancellation = cancellationTokenSource;
            var current = DetectTypeCheckChange();
            var res     = _typeCheckTask.ContinueWith((_task, _state) => {
                current = (TypeCheckChange)Math.Max((int)_cancelledTypeCheckType, (int)current);
                if (cancellationTokenSource.IsCancellationRequested)
                {
                    _cancelledTypeCheckType = current;
                    return(null);
                }
                _cancelledTypeCheckType = TypeCheckChange.None;
                DoTypeCheck(current);
                if (cancellationTokenSource.IsCancellationRequested)
                {
                    return(null);
                }
                return(_lastSemantics);
            }, TaskContinuationOptions.RunContinuationsAsynchronously | TaskContinuationOptions.LongRunning);

            _typeCheckTask = res;
            return(res);
        }
예제 #2
0
        void DoTypeCheck(TypeCheckChange type)
        {
            if (_typeChecker == null)
            {
                type = TypeCheckChange.Options;
            }
            if (BuildOnceOnly)
            {
                type = TypeCheckChange.Once;
            }
            switch (type)
            {
            case TypeCheckChange.None:
                return;

            case TypeCheckChange.Small:
                _typeChecker.ClearDiagnostics();
                _typeChecker.TriggerUpdate();
                break;

            case TypeCheckChange.Input:
                _typeChecker.ClearDiagnostics();
                _typeChecker.UpdateProgram(MakeSourceListArray());
                _typeChecker.TriggerUpdate();
                break;

            case TypeCheckChange.Options:
                if (_typeChecker != null)
                {
                    CompilerPool.ReleaseTs(_typeChecker);
                    _typeChecker = null;
                }
                _typeChecker = CompilerPool.GetTs(_diskCache, CompilerOptions);
                _typeChecker.ClearDiagnostics();
                _typeChecker.CreateProgram(CurrentDirectory, MakeSourceListArray());
                break;

            case TypeCheckChange.Once:
                if (_typeChecker != null)
                {
                    CompilerPool.ReleaseTs(_typeChecker);
                    _typeChecker = null;
                }
                _typeChecker = CompilerPool.GetTs(_diskCache, CompilerOptions);
                _typeChecker.ClearDiagnostics();
                _typeChecker.CheckProgram(CurrentDirectory, MakeSourceListArray());
                _lastSemantics = _typeChecker.GetDiagnostics();
                CompilerPool.ReleaseTs(_typeChecker);
                _typeChecker = null;
                return;
            }
            _lastSemantics = _typeChecker.GetDiagnostics();
        }