Opening a file with a custom file-extension in vscode at a specific line number

Greetings,
I have a EditorWindow script that references a TextAsset and has a int field to enter a line number (for simplification). I want to open the TextAsset at a specific line-number in vscode. I’m using the method AssetDatabase.OpenAsset().

public class EditTools : EditorWindow
{
    public TextAsset chapterFile;
    public int lineNumber = 1;

    private void OnGUI()
    {
        EditorGUILayout.IntField("Line Number", lineNumber);
        if (GUILayout.Button("Open File")) AssetDatabase.OpenAsset(chapterFile, lineNumber);
    }
}

It does work properly for .txt files. However, I have created a custom file-type “.aljs”. I created a ScriptImporter that imports those files as TextAssets.

[UnityEditor.AssetImporters.ScriptedImporter(1, "aljs")]
public class ALJSScriptedImporter : UnityEditor.AssetImporters.ScriptedImporter
{
    public override void OnImportAsset(UnityEditor.AssetImporters.AssetImportContext ctx)
    {
        TextAsset subAsset = new TextAsset(File.ReadAllText(ctx.assetPath));
        ctx.AddObjectToAsset("text", subAsset);
        ctx.SetMainObject(subAsset);
    }
}

I have a custom vscode extension for this file-type for syntax highlighting. AssetDatabase.OpenAsset(). opens the correct file, but it does not jump to the correct line.

The documentation (Unity - Scripting API: AssetDatabase.OpenAsset) states “If it is a text file, lineNumber and columnNumber instructs the text editor to go to that line and column.”

Is there a way to make it work for my custom file-type? I have a workaround in place, but it’s kinda bad. It starts a process before which opens a console window for short and it’s kinda slow.

string filePath = AssetDatabase.GetAssetPath(textAsset);
string fullPath = Application.dataPath + filePath.Substring("Assets".Length);
System.Diagnostics.Process.Start("code", "-g \"" + fullPath.Replace("\\", "/") + "\":" + 15);
AssetDatabase.OpenAsset(textAsset);

Does someone know how to make it work without having to start an additional process?

Kind regards.

By making use of System.Diagnostics.ProcessStartInfo I could get rid of the popping up command window.

            string args = $"-g \"{filePath}\":{lineIndex}";
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
            {
                FileName = editorPath,
                Arguments = args,
                UseShellExecute = false,
                CreateNoWindow = true
            };
            System.Diagnostics.Process.Start(startInfo);