/// <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. } }
public static TypeCobol.ExecutionStep?ExecutionStep(this LsrTestingOptions lsrOptions, TypeCobol.ExecutionStep? defaultValue) { switch (lsrOptions) { case LsrTestingOptions.NoLsrTesting: case LsrTestingOptions.LsrSourceDocumentTesting: return(defaultValue); case LsrTestingOptions.LsrScanningPhaseTesting: return(TypeCobol.ExecutionStep.Scanner); case LsrTestingOptions.LsrPreprocessingPhaseTesting: return(TypeCobol.ExecutionStep.Preprocessor); case LsrTestingOptions.LsrParsingPhaseTesting: return(TypeCobol.ExecutionStep.SyntaxCheck); case LsrTestingOptions.LsrSemanticPhaseTesting: return(TypeCobol.ExecutionStep.CrossCheck); } return(defaultValue); }
public static string ToLanguageServerOption(this LsrTestingOptions lsrOptions) { switch (lsrOptions) { case LsrTestingOptions.LsrSourceDocumentTesting: return("-tsource"); case LsrTestingOptions.LsrScanningPhaseTesting: return("-tscanner"); case LsrTestingOptions.LsrPreprocessingPhaseTesting: return("-tpreprocess"); case LsrTestingOptions.LsrParsingPhaseTesting: return("-tparser"); case LsrTestingOptions.LsrSemanticPhaseTesting: return("-tsemantic"); case LsrTestingOptions.NoLsrTesting: default: return(""); } }
public static void Test(string testFolderName, LsrTestingOptions lsrTestingOption, bool activateTdOption = false, string copyFolder = null, string customIntrinsicFile = null, string customDependenciesFolder = null) { var workingDirectory = "LSRTests"; var testWorkingDirectory = workingDirectory + Path.DirectorySeparatorChar + testFolderName; var scriptPath = Directory.GetFiles(testWorkingDirectory + Path.DirectorySeparatorChar + "input", "*.tlsp").FirstOrDefault(); var initializeFileInfo = new FileInfo(workingDirectory + Path.DirectorySeparatorChar + "initialize.json"); var configFileInfo = new FileInfo(workingDirectory + Path.DirectorySeparatorChar + "config.json"); var intrinsicFileInfo = new FileInfo(workingDirectory + Path.DirectorySeparatorChar + "DefaultIntrinsic.txt"); if (string.IsNullOrEmpty(scriptPath)) { Assert.Fail("Script path is null or empty"); } //Update Init FileInfo var initFileContent = File.ReadAllText(initializeFileInfo.FullName); initFileContent = initFileContent.Replace("{rootPath}", Directory.GetCurrentDirectory().Replace(@"\", @"\\")); initFileContent = initFileContent.Replace("{rootUri}", new Uri(Directory.GetCurrentDirectory()).ToString()); var initGeneratedFileInfo = new FileInfo(testWorkingDirectory + Path.DirectorySeparatorChar + "generatedInitialize.json"); //Write the initialize file content into generatedInitialize.json file File.WriteAllText(initGeneratedFileInfo.FullName, initFileContent); //Update config file var configFileContent = File.ReadAllText(configFileInfo.FullName); configFileContent = configFileContent.Replace("{CopyFolder}", new DirectoryInfo(testWorkingDirectory + Path.DirectorySeparatorChar + "input" + Path.DirectorySeparatorChar + copyFolder).FullName.Replace(@"\", @"\\")); configFileContent = configFileContent.Replace("{IntrinsicFile}", customIntrinsicFile == null ? intrinsicFileInfo.FullName.Replace(@"\", @"\\") : new FileInfo(testWorkingDirectory + Path.DirectorySeparatorChar + "input" + Path.DirectorySeparatorChar + customIntrinsicFile).FullName.Replace(@"\", @"\\")); configFileContent = configFileContent.Replace("{DependenciesFolder}", new DirectoryInfo(testWorkingDirectory + Path.DirectorySeparatorChar + "input" + Path.DirectorySeparatorChar + customDependenciesFolder).FullName.Replace(@"\", @"\\")); var configGeneratedFileInfo = new FileInfo(testWorkingDirectory + Path.DirectorySeparatorChar + "generatedConfig.json"); //Write the config file content into generatedConfig.json file File.WriteAllText(configGeneratedFileInfo.FullName, configFileContent); var scriptFileInfo = new FileInfo(scriptPath); //Setup the arguments //The path for LanguageServerRobot depends on the NuGetPackage. If the NuGet is not downloaded, it won't works var arguments = string.Format(defaultTypeCobolLSArgs, @"TypeCobol.LanguageServerRobot.exe", initGeneratedFileInfo.FullName, configGeneratedFileInfo.FullName, scriptFileInfo.FullName, activateTdOption ? "-td" : "", lsrTestingOption.ToLanguageServerOption()); System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "TypeCobol.LanguageServer.exe"; startInfo.WorkingDirectory = testWorkingDirectory; startInfo.Arguments = arguments; process.StartInfo = startInfo; process.Start(); process.WaitForExit(LSR_TEST_TIMEOUT); DirectoryInfo expectedOutputDir = new DirectoryInfo(testWorkingDirectory + Path.DirectorySeparatorChar + "output_expected"); DirectoryInfo resultOutputDir = new DirectoryInfo(testWorkingDirectory + Path.DirectorySeparatorChar + "input" + Path.DirectorySeparatorChar + "Results"); bool dirIdentical = UnitTestHelper.CompareDirectory(expectedOutputDir, resultOutputDir); if (!dirIdentical) { throw new Exception("directory not equals"); } }
public static bool HasFlag(this LsrTestingOptions value, LsrTestingOptions flag) { return((value & flag) != 0); }