public IEnumerable<EditorError> GetCompilationErrors(ICodeProject post) { var result = compiler.RoslynCompile(post).EmitToMemory(); return result.Diagnostics .Where(x => x.Info.Severity == DiagnosticSeverity.Error) .Select(x => new EditorError { Location = DocumentLineSpan.Create(x.Location.GetLineSpan(true)), Message = x.Info.GetMessage() }); }
NormalizedPath WriteProjectFolder(NormalizedPath folder, ICodeProject project) { folder = folder.AppendPart(project.ProjectName); Directory.CreateDirectory(folder); project.CreateRootElement().Save(folder.AppendPart(project.ProjectName + ".csproj")); using (var source = new StreamWriter(folder.AppendPart("Program.cs"))) { project.Code.WriteGlobalSource(source); } return(folder); }
public ITypeDeclaration FindTypeInFile(object solution, object projectItemObject, IEnumerable <string> locations, string typeName) { IProjectItem projectItem = projectItemObject as IProjectItem; if (projectItem == null) { return((ITypeDeclaration)null); } ICodeProject codeProject = this.codeProjectService.GetCodeProject(projectItem.Project); return((ITypeDeclaration) new CodeModelService.ActiproCodeModelService.TypeWrapper(typeName, projectItem, codeProject)); }
public IEnumerable <EditorError> GetCompilationErrors(ICodeProject post) { var result = compiler.RoslynCompile(post).EmitToMemory(); return(result.Diagnostics .Where(x => x.Info.Severity == DiagnosticSeverity.Error) .Select(x => new EditorError { Location = DocumentLineSpan.Create(x.Location.GetLineSpan(true)), Message = x.Info.GetMessage() })); }
internal CodeView(IDocument document, ICodeProject codeProject, IMessageDisplayService messageDisplayService, IViewService viewService, CodeOptionsModel codeOptionsModel, Microsoft.Expression.Framework.UserInterface.IWindowService windowService) : base(document) { Application.Current.Activated += new EventHandler(this.Application_Activated); this.codeDocument = (CodeDocument)document; this.messageDisplayService = messageDisplayService; this.viewService = viewService; this.codeOptionsModel = codeOptionsModel; this.actiproEditor = new ActiproEditor(this.codeDocument.Document, this.codeOptionsModel, this.messageDisplayService, this.viewService, codeProject, windowService); this.actiproEditor.CommandExecutionRequested += new EventHandler <CommandExecutionRequestedEventArgs>(this.ActiproEditor_CommandExecutionRequested); this.actiproEditor.EventInserted += new EventHandler <InsertEventHandlerEventArgs>(this.Editor_EventInserted); this.AddCommands(); }
internal CodeDocument(DocumentReference documentReference, bool isReadOnly, Encoding encoding, Stream stream, CodeDomProvider codeDomProvider, CodeDocumentType codeDocumentType, ICodeProjectService codeProjectService, ICodeProject codeProject, IProject project, IViewService viewService, IWindowService windowService) : base(documentReference, isReadOnly) { this.filename = documentReference.Path; this.codeDomProvider = codeDomProvider; this.codeDocumentType = codeDocumentType; this.codeOptionsModel = this.codeDocumentType.CodeOptionsModel; this.codeProjectService = codeProjectService; this.viewService = viewService; this.codeProject = codeProject; this.project = project; this.windowService = windowService; this.encoding = encoding; this.stream = stream; }
private static ISolution CreateSolution(ICodeProject codeProject, out ProjectId projectId) { DocumentId entryPointDocumentId; DocumentId consoleDocumentId; var solutionId = SolutionId.CreateNewId(); return (Solution.Create(solutionId) .AddCSharpProject(codeProject.Name ?? "Untitled", codeProject.Name ?? "Untitled", out projectId) .AddMetadataReferences(projectId, DefaultReferences) .UpdateCompilationOptions(projectId, DefaultCompilationOptions) .UpdateParseOptions(projectId, DefaultParseOptions) .AddDocument(projectId, "EntryPoint", EntryPoint, out entryPointDocumentId) .AddDocument(projectId, "Console", Console, out consoleDocumentId)); }
public CommonCompilation RoslynCompile(ICodeProject codeProject) { if (codeProject == null) { throw new ArgumentNullException("codeProject"); } ProjectId projectId; var solution = CreateSolution(codeProject, out projectId); var documentIds = new Dictionary<string, DocumentId>(); foreach (var document in codeProject.Documents) { var documentId = DocumentId.CreateNewId(projectId, document.Name); var text = document.GetText(); if (string.Equals(document.Name, "Content")) { // This smells terrible. text = BuildScript(text); } solution = solution.AddDocument(documentId, document.Name, new StringText(text)); documentIds.Add(document.Name, documentId); } foreach (var documentId in solution.GetProject(projectId).DocumentIds) { var document = solution.GetDocument(documentId); var root = document.GetSyntaxRoot(); var semanticModel = document.GetSemanticModel(); var rewriter = new ConsoleRewriter("__Console", semanticModel); solution = solution.UpdateDocument(documentId, rewriter.Visit((SyntaxNode)root)); } return solution.GetProject(projectId).GetCompilation(); }
public CommonCompilation RoslynCompile(ICodeProject codeProject) { if (codeProject == null) { throw new ArgumentNullException("codeProject"); } ProjectId projectId; var solution = CreateSolution(codeProject, out projectId); var documentIds = new Dictionary <string, DocumentId>(); foreach (var document in codeProject.Documents) { var documentId = DocumentId.CreateNewId(projectId, document.Name); var text = document.GetText(); if (string.Equals(document.Name, "Content")) { // This smells terrible. text = BuildScript(text); } solution = solution.AddDocument(documentId, document.Name, new StringText(text)); documentIds.Add(document.Name, documentId); } foreach (var documentId in solution.GetProject(projectId).DocumentIds) { var document = solution.GetDocument(documentId); var root = document.GetSyntaxRoot(); var semanticModel = document.GetSemanticModel(); var rewriter = new ConsoleRewriter("__Console", semanticModel); solution = solution.UpdateDocument(documentId, rewriter.Visit((SyntaxNode)root)); } return(solution.GetProject(projectId).GetCompilation()); }
public ICodeAssembly Compile(ICodeProject program) { var compilation = RoslynCompile(program); var assembly = new ProgramAssembly { EntryPointClassName = "Script+EntryPoint", EntryPointMethodName = "Main" }; using (var stream = new MemoryStream()) { var emitResult = compilation.Emit(stream); if (!emitResult.Success) { return null; } assembly.CompiledAssembly = stream.ToArray(); } return assembly; }
public void full_run_test() { var f = TestHelper.TestProjectFolder.AppendPart("TestCodeProject"); TestHelper.CleanupFolder(f); ICodeProject project = CodeWorkspace.CreateProject("MyProject"); project.TargetFrameworks.Add("netcoreapp3.1"); project.OutputType = "Exe"; project.Code.Global.EnsureUsing("System"); ITypeScope program = project.Code.Global.CreateType("public static class Program"); IFunctionScope main = program.GeneratedByComment() .CreateFunction("public static int Main()"); main.Append("Console.WriteLine(").AppendSourceString("Hop!").Append(" );").NewLine(); main.Append("return 0;"); var projectFolder = WriteProjectFolder(f, project); Run(projectFolder, "dotnet", "run", out string output); output.Should().Contain("Hop!"); }
public ICodeAssembly Compile(ICodeProject program) { var compilation = RoslynCompile(program); var assembly = new ProgramAssembly { EntryPointClassName = "Script+EntryPoint", EntryPointMethodName = "Main" }; using (var stream = new MemoryStream()) { var emitResult = compilation.Emit(stream); if (!emitResult.Success) { return(null); } assembly.CompiledAssembly = stream.ToArray(); } return(assembly); }
private IEnumerable<EditorError> GetErrorsInPost(ICodeProject post) { return validator.GetCompilationErrors(post); }
private static ISolution CreateSolution(ICodeProject codeProject, out ProjectId projectId) { DocumentId entryPointDocumentId; DocumentId consoleDocumentId; var solutionId = SolutionId.CreateNewId(); return Solution.Create(solutionId) .AddCSharpProject(codeProject.Name ?? "Untitled", codeProject.Name ?? "Untitled", out projectId) .AddMetadataReferences(projectId, DefaultReferences) .UpdateCompilationOptions(projectId, DefaultCompilationOptions) .UpdateParseOptions(projectId, DefaultParseOptions) .AddDocument(projectId, "EntryPoint", EntryPoint, out entryPointDocumentId) .AddDocument(projectId, "Console", Console, out consoleDocumentId); }
private IEnumerable <EditorError> GetErrorsInPost(ICodeProject post) { return(validator.GetCompilationErrors(post)); }
public TypeWrapper(string typeName, IProjectItem projectItem, ICodeProject codeProject) { this.typeName = typeName; this.projectItem = projectItem; this.codeProject = codeProject; }
private void InitializeEditor(ActiproSoftware.SyntaxEditor.Document document, ICodeProject codeProject) { this.editor.LineNumberMarginVisible = true; this.editor.BracketHighlightingVisible = true; this.editor.IndentationGuidesVisible = true; this.editor.AllowDrag = true; this.editor.AllowDrop = true; this.editor.SplitType = SyntaxEditorSplitType.None; this.editor.IndentType = IndentType.Smart; this.editor.Document = document; if (document != null) { this.editor.Document.SemanticParsingEnabled = true; this.editor.Document.LexicalParsingEnabled = true; } else { this.editor.Enabled = false; } this.SetEditorTheme(); this.editor.ContextMenuRequested += new ContextMenuRequestEventHandler(this.Editor_ContextMenuRequested); this.editor.GotFocus += new EventHandler(this.OnEditorGotFocus); this.editor.LostFocus += new EventHandler(this.OnEditorLostFocus); if (this.editor.Document.Language is CSharpSyntaxLanguage) { this.cSharpLanguage = new CSharpExtendedSyntaxLanguage(codeProject); this.editor.Document.Language = (SyntaxLanguage)this.cSharpLanguage; this.cSharpLanguage.EventInserted += new EventHandler <InsertEventHandlerEventArgs>(this.OnEventInserted); this.editor.IntelliPrompt.QuickInfo.HideOnMouseMove = false; } else if (this.editor.Document.Language.Key.Equals("JScript", StringComparison.OrdinalIgnoreCase)) { this.editor.Document.Language.LineCommentDelimiter = "//"; } this.editor.KeyTyping += new KeyTypingEventHandler(this.Editor_KeyTyping); }
public ActiproEditor(ActiproSoftware.SyntaxEditor.Document document, CodeOptionsModel codeOptionsModel, IMessageDisplayService messageDisplayService, IViewService viewService, ICodeProject codeProject, Microsoft.Expression.Framework.UserInterface.IWindowService windowService) { this.editor = new SyntaxEditor(); this.InitializeEditor(document, codeProject); this.host = new WindowsFormsHost(); this.host.Background = (System.Windows.Media.Brush)System.Windows.Media.Brushes.White; this.editor.IndicatorMarginVisible = false; this.host.Child = (Control)this.editor; this.codeOptionsModel = codeOptionsModel; this.codeOptionsModel.PropertyChanged += new PropertyChangedEventHandler(this.Actipro_PropertyChanged); this.editorSpecificOptionsModel = this.codeOptionsModel.GetEditorModel(EditorType.CodeEditor); this.editorSpecificOptionsModel.PropertyChanged += new PropertyChangedEventHandler(this.Actipro_PropertyChanged); this.messageDisplayService = messageDisplayService; this.viewService = viewService; this.windowService = windowService; this.windowService.ThemeChanged += new EventHandler(this.WindowService_ThemeChanged); this.UpdateOptions(); }
internal CSharpExtendedSyntaxLanguage(ICodeProject codeProject) { this.codeProject = codeProject; }