Пример #1
0
        /// <summary>
        /// Update the text contents of the file
        /// </summary>
        public void UpdateSourceFile(Uri fileUri, TextChangedEvent textChangedEvent, bool bAsync)
        {
            FileCompiler fileCompilerToUpdate = null;

            if (OpenedFileCompiler.TryGetValue(fileUri, out fileCompilerToUpdate))
            {
                fileCompilerToUpdate.CompilationResultsForProgram.UpdateTextLines(textChangedEvent);
                if (!bAsync)
                {//Don't wait asynchroneous snapshot refresh.
                    fileCompilerToUpdate.CompilationResultsForProgram.UpdateTokensLines(
                        () =>
                    {
                        fileCompilerToUpdate.CompilationResultsForProgram.RefreshTokensDocumentSnapshot();
                        fileCompilerToUpdate.CompilationResultsForProgram.RefreshProcessedTokensDocumentSnapshot();
                        fileCompilerToUpdate.CompilationResultsForProgram.RefreshCodeElementsDocumentSnapshot();
                        fileCompilerToUpdate.CompilationResultsForProgram.RefreshProgramClassDocumentSnapshot();
                    }
                        );
                }
                else
                {
                    fileCompilerToUpdate.CompilationResultsForProgram.UpdateTokensLines();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Update the text contents of the file
        /// </summary>
        public void UpdateSourceFile(Uri fileUri, TextChangedEvent textChangedEvent)
        {
            FileCompiler fileCompilerToUpdate = null;

            if (OpenedFileCompiler.TryGetValue(fileUri, out fileCompilerToUpdate))
            {
                _semanticUpdaterTimer?.Stop();

                fileCompilerToUpdate.CompilationResultsForProgram.UpdateTextLines(textChangedEvent);
                if (IsLsrSourceTesting)
                {
                    //Log text lines string
                    var sb = new StringBuilder();
                    foreach (var cobolTextLine in fileCompilerToUpdate.CompilationResultsForProgram.CobolTextLines)
                    {
                        sb.AppendLine(cobolTextLine.SourceText);
                    }
                    _Logger(sb.ToString(), fileUri);
                }

                var handler = new Action <object, ExecutionStepEventArgs>((sender, args) => { ExecutionStepEventHandler(sender, args, fileUri); });
                //Subscribe to FileCompilerEvent
                fileCompilerToUpdate.ExecutionStepEventHandler += handler.Invoke;
                var execStep = LsrTestOptions.ExecutionStep(fileCompilerToUpdate.CompilerOptions.ExecToStep);
                if (execStep > ExecutionStep.SyntaxCheck)
                {
                    execStep = ExecutionStep.SyntaxCheck; //The maximum execstep authorize for incremental parsing is SyntaxCheck,
                }
                //further it's for semantic, which is handle by NodeRefresh method


                fileCompilerToUpdate.CompileOnce(execStep, fileCompilerToUpdate.CompilerOptions.HaltOnMissingCopy, fileCompilerToUpdate.CompilerOptions.UseAntlrProgramParsing);
                fileCompilerToUpdate.ExecutionStepEventHandler -= handler.Invoke;


                if (LsrTestOptions == LsrTestingOptions.NoLsrTesting || LsrTestOptions == LsrTestingOptions.LsrSemanticPhaseTesting)
                {
                    if (!_timerDisabled) //If TimerDisabled is false, create a timer to automatically launch Node phase
                    {
                        lock (_fileCompilerWaittingForNodePhase)
                        {
                            if (!_fileCompilerWaittingForNodePhase.Contains(fileCompilerToUpdate))
                            {
                                _fileCompilerWaittingForNodePhase.Add(fileCompilerToUpdate); //Store that this fileCompiler will soon need a Node Phase
                            }
                        }

                        _semanticUpdaterTimer          = new System.Timers.Timer(750);
                        _semanticUpdaterTimer.Elapsed += (sender, e) => TimerEvent(sender, e, fileCompilerToUpdate);
                        _semanticUpdaterTimer.Start();
                    }
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Stop continuous background compilation after a file has been closed
 /// </summary>
 public void CloseSourceFile(Uri fileUri)
 {
     lock (OpenedFileCompiler)
     {
         if (OpenedFileCompiler.ContainsKey(fileUri))
         {
             var fileCompilerToClose = OpenedFileCompiler[fileUri];
             OpenedFileCompiler.Remove(fileUri);
             fileCompilerToClose.CompilationResultsForProgram.ProgramClassChanged -= ProgramClassChanged;
         }
     }
 }
Пример #4
0
        /// <summary>
        /// Start continuous background compilation on a newly opened file
        /// </summary>
        public void OpenSourceFile(Uri fileUri, string sourceText, LsrTestingOptions lsrOptions)
        {
            string        fileName = Path.GetFileName(fileUri.LocalPath);
            ITextDocument initialTextDocumentLines = new ReadOnlyTextDocument(fileName, TypeCobolConfiguration.Format.Encoding, TypeCobolConfiguration.Format.ColumnsLayout, sourceText);
            FileCompiler  fileCompiler             = null;

#if EUROINFO_RULES //Issue #583
            SymbolTable arrangedCustomSymbol = null;
            var         inputFileName        = fileName.Substring(0, 8);
            var         matchingPgm          =
                _customSymbols.Programs.Keys.FirstOrDefault(
                    k => k.Equals(inputFileName, StringComparison.InvariantCultureIgnoreCase));
            if (matchingPgm != null)
            {
                arrangedCustomSymbol = new SymbolTable(_customSymbols, SymbolTable.Scope.Namespace);
                var prog = _customSymbols.Programs.Values.SelectMany(p => p).Where(p => p.Name != matchingPgm);
                arrangedCustomSymbol.CopyAllPrograms(new List <List <Program> >()
                {
                    prog.ToList()
                });
                arrangedCustomSymbol.Programs.Remove(matchingPgm);
            }
            fileCompiler = new FileCompiler(initialTextDocumentLines, CompilationProject.SourceFileProvider,
                                            CompilationProject, CompilationProject.CompilationOptions, arrangedCustomSymbol ?? _customSymbols,
                                            false, CompilationProject);
#else
            fileCompiler = new FileCompiler(initialTextDocumentLines, CompilationProject.SourceFileProvider, CompilationProject, CompilationProject.CompilationOptions, _customSymbols, false, CompilationProject);
#endif


            fileCompiler.CompilationResultsForProgram.UpdateTokensLines();

            lock (OpenedFileCompiler)
            {
                if (OpenedFileCompiler.ContainsKey(fileUri))
                {
                    CloseSourceFile(fileUri); //Close and remove the previous opened file.
                }
                OpenedFileCompiler.Add(fileUri, fileCompiler);
                fileCompiler.CompilationResultsForProgram.ProgramClassChanged += ProgramClassChanged;
            }

            fileCompiler.CompilationResultsForProgram.SetOwnerThread(Thread.CurrentThread);

            if (lsrOptions != LsrTestingOptions.LsrSourceDocumentTesting)
            {
                fileCompiler.CompileOnce(lsrOptions.ExecutionStep(fileCompiler.CompilerOptions.ExecToStep.Value), fileCompiler.CompilerOptions.HaltOnMissingCopy); //Let's parse file for the first time after opening.
            }
        }
Пример #5
0
        /// <summary>
        /// Stop continuous background compilation after a file has been closed
        /// </summary>
        public void CloseSourceFile(Uri fileUri)
        {
            FileCompiler fileCompilerToClose = null;

            lock (OpenedFileCompiler)
            {
                if (OpenedFileCompiler.ContainsKey(fileUri))
                {
                    fileCompilerToClose = OpenedFileCompiler[fileUri];
                    OpenedFileCompiler.Remove(fileUri);
                    fileCompilerToClose.StopContinuousBackgroundCompilation();
                    fileCompilerToClose.CompilationResultsForProgram.ProgramClassChanged -= ProgramClassChanged;
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Start continuous background compilation on a newly opened file
        /// </summary>
        public void OpenSourceFile(Uri fileUri, string sourceText)
        {
            string        fileName = Path.GetFileName(fileUri.LocalPath);
            ITextDocument initialTextDocumentLines = new ReadOnlyTextDocument(fileName, TypeCobolConfiguration.Format.Encoding, TypeCobolConfiguration.Format.ColumnsLayout, sourceText);
            var           fileCompiler             = new FileCompiler(initialTextDocumentLines, CompilationProject.SourceFileProvider, CompilationProject, CompilationProject.CompilationOptions, CustomSymbols, false, CompilationProject);

            fileCompiler.CompilationResultsForProgram.UpdateTokensLines();

            lock (OpenedFileCompiler)
            {
                if (OpenedFileCompiler.ContainsKey(fileUri))
                {
                    CloseSourceFile(fileUri); //Close and remove the previous opened file.
                }
                OpenedFileCompiler.Add(fileUri, fileCompiler);
                fileCompiler.CompilationResultsForProgram.ProgramClassChanged += ProgramClassChanged;
            }

            fileCompiler.CompilationResultsForProgram.SetOwnerThread(Thread.CurrentThread);
            fileCompiler.StartContinuousBackgroundCompilation(200, 500, 1000, 3000); //TODO: create a better refresh compilation
        }
Пример #7
0
        public void UpdateMissingCopies(Uri fileUri, List <string> RemainingMissingCopies)
        {
            if (!OpenedFileCompiler.Any())
            {
                return;
            }
            var fileCompiler = OpenedFileCompiler[fileUri];

            if (fileCompiler == null)
            {
                return;
            }

            if (RemainingMissingCopies == null || RemainingMissingCopies.Count == 0)
            {
                fileCompiler.CompilationResultsForProgram.MissingCopies.RemoveAll(c => true);
                return;
            }

            fileCompiler.CompilationResultsForProgram.MissingCopies =
                fileCompiler.CompilationResultsForProgram.MissingCopies.Where(
                    c => RemainingMissingCopies.Any(rc => rc == c.TextName)).ToList();
        }