0

I have an application that exposes some c# objects to an embedded IronPython interpreter like this:

using IronPython.Hosting;

namespace ironpy
{
    public class Foo
    {
        public void bar(string message)
        {
            System.Console.WriteLine(message);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var engine = Python.CreateEngine();
            var scope = engine.CreateScope();

            var test = new Foo();

            scope.SetVariable("foo", test);

            string code = "foo.bar('Hello')";

            engine.Execute(code, scope);
        }
    }
}

In practice the python source code comes from an textfile loaded at runtime.

When editing such a source file in VSCode or other editors the language server that provides code completion obviously doesn't have any idea about whats going to be available. So you have no code completion and annoying error squiggles everywhere.

Is it somehow possible to write some sort of plugin/hint/linting file for one of the commonly used language servers to tell them about the exported C# API to get working code completion when editing the python source files?

Eric
  • 1,183
  • 6
  • 17

2 Answers2

0

I found the solution to my problem in the meantime: IronPython Stubs files

https://github.com/gtalarico/ironpython-stubs

Eric
  • 1,183
  • 6
  • 17
0

In my opinion, defining .py file and implementing codes inside on it is the best way. Then you can execute your .py file like below;

https://stackoverflow.com/a/11779234/4582992

kemal akoğlu
  • 182
  • 13