ADDING REFERENCES TO ALTERNET.EDITOR.WPF.TEXTEDITOR

How do I add references to the Text Editor so that custom types that I've defined in another assembly get autocompletion and such?
Something like my Parameters and Results class below:

public static class Automation {

public static void Main(Parameters P, Results R) {

R.Output = $@"{P.Name} is {P.Age} years old!";

}
}
Hi Tony,
You can register any assembly for code completion using RegisterAssembly method of RoslynRepository (accessible via CsParser) like this:

var csParser = new Alternet.Syntax.Parsers.Roslyn.CsParser();
csParser.Repository.RegisterAssembly(@"..\..\..\CustomAssembly\bin\debug\CustomAssembly.dll");
// if already loaded in appdomain, can just use csParser.Repository.RegisterAssembly("CustomAssembly");

I've uploaded full demo project here:
https://drive.google.com/file/d/1GohDX2hMbBVpFiIu5vxSJ2DeWf905mAH/view?usp=sharing

Hope this helps.
Andrew
Hi Andrew,
I've tested out what you sent and it works great, however, I don't want to rely on hard coded paths or magic strings. I've made the following changes to your project and it will show the problem I'm facing:

1. In CodeCompletion, add a reference to CustomAssembly.
2. Set AssemblyPath as follows:
var AssemblyPath = typeof(CustomAssembly.Parameters).Assembly.Location;

If I do that, it seems as if the parse no longer loads the assembly. What do I need to do to make that work?
Hi Tony,
There seems to be a small issue with the order of initialization of roslyn engine.
This code should work:
public MainWindow()
{
InitializeComponent();
var csParser = new Alternet.Syntax.Parsers.Roslyn.CsParser();
syntaxEdit1.Lexer = csParser;
syntaxEdit1.Lines.LoadFile(@"..\..\file.cs");
var assemblyPath = typeof(CustomAssembly.Parameters).Assembly.Location; csParser.Repository.RegisterAssembly(assemblyPath);
}
you can also make sure that it's initialized before calling RegisterAssembly method:
private void InitWorkspace(Alternet.Syntax.Parsers.Roslyn.RoslynParser parser)
{
var workspace = parser.Repository.Solution.Workspace;
}
public MainWindow()
{
InitializeComponent();
var csParser = new Alternet.Syntax.Parsers.Roslyn.CsParser();
InitWorkspace(csParser);
var assemblyPath = typeof(CustomAssembly.Parameters).Assembly.Location;
csParser.Repository.RegisterAssembly(assemblyPath);
syntaxEdit1.Lexer = csParser;
syntaxEdit1.Lines.LoadFile(@"..\..\file.cs");
}
regards,
Andrew
When I add references via parser.Repository.RegisterAssembly() it works, but the editor still shows red lines under my related classes until I go to the editor and start typing. Once I start typing, the lines all go away. Is there some other step I'm missing to get the editor to refresh its references?
Hi,
after adding the reference, call this method (based on the code snippet in the previous post - you probably have a "RoslynParser" variable in your code):
csParser.ReparseText();
You can call this method only if you already have code in the parser, otherwise an exception will occur.
Best regards
Wolfgang