I am working on a script editor that can provide code completion and on-the-fly compilation diagnostics. I started using CSharpScript.Create:
this._script = CSharpScript.Create<T>(sourceCode,ScriptOptions.Default,typeof(T));
diagnostics = this._script.Compile().ToList();
but noticed that the memory consumption was increasing at each script creation (triggered by source code modification). Then i looked upon using Document:
this.Document = this.Workspace
.AddProject("TestProject", LanguageNames.CSharp)
.WithMetadataReferences(...)
.AddDocument("", "")
.WithSourceCodeKind(SourceCodeKind.Script);
diagnostics=this.Document.WithText(SourceText.From(sourceCode)).GetSemanticModelAsync()
.Result.GetDiagnostics().ToList()
Memory consumption stays low but I don't know how to pass global variable information as easily than with CSharpScript.Create. Any reference to a global variable inside the script triggers a CS0103 error - "The name '' does not exist in the current context".
Is it possible with a document to pass global variable type information ?
How can we execute such a document / script ? (currently I am using CSharpScript.Create to compile and execute code, and Workspace / Document to provide code completion).