williamoberg / godot-dotnet-tools

Generate .NET related files for your Godot project
https://marketplace.visualstudio.com/items?itemName=woberg.godot-dotnet-tools
MIT License
10 stars 1 forks source link

Proposal: adding Node Path autocomplete #6

Open joined72 opened 10 months ago

joined72 commented 10 months ago

To add Node Path autocomplete I think to following some simple steps:

  1. check the current .cs filename and check if exists the same filename but with the .tscn extension
  2. if exists then iterate the entire text file creating an order list of all the included Node Paths (take a look here for the .tscn implementation)
  3. when the user write the "GetNode..." keyword start to show the list of node path as autocomplete

If you need some help (as for write the JavaScript code for point # 2) simply let me know, I'll be very happy to can help. ;)

To customize the VsCode autocompletion try to use a coce like this:

function activate(context) {
    context.subscriptions.push(vscode.languages.registerCompletionItemProvider(
        { language: 'csharp' },
        {
            provideCompletionItems(document, position, token, context) {
                const line = document.lineAt(position);
                const prefix = line.text.slice(0, position.character).trim();

                if (prefix === 'GetNode') {
                    return ['NodePath1', 'NodePath2', 'NodePath3'].map(keyword => {
                        const completionItem = new vscode.CompletionItem(keyword);
                        return completionItem;
                    });
                }
            }
        }
    ));
}

PS: otherwise you can check how the old C# plugin implemented this features on Godot 3.x here... https://github.com/godotengine/godot-csharp-vscode