vshaxe / vshaxe

Haxe Support for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=nadako.vshaxe
MIT License
325 stars 58 forks source link

Feature Request: Safe Delete #633

Open dubspeed opened 2 months ago

dubspeed commented 2 months ago

Safe Delete

Description

I would like to suggest the addition of a "Safe Delete" feature to the VSHaxe. The feature is often found in IntelliJ based IDEs. Here is what it does:

Proposed Functionality

The "Safe Delete" feature should:

Examples

Example 1: Deleting a class

When attempting to delete a class, the feature should:

// Class to be deleted
class OldFeature {
    public function doSomething() {
        // ...
    }
}

// In another file
import OldFeature;

class Main {
    public function new() {
        var feature = new OldFeature(); // This should be identified and removed
        feature.doSomething(); // This should also be removed
    }
}

Example 2: Deleting a method

When deleting a method, the feature should:

class MyClass {
    public function deprecatedMethod() { // Method to be deleted
        // ...
    }

    public function anotherMethod() {
        deprecatedMethod(); // This call should be identified and removed
    }
}

// In another file
class AnotherClass {
    public function someFunction(instance:MyClass) {
        instance.deprecatedMethod(); // This should also be identified and removed
    }
}

Example 3: Deleting a field

When deleting a field, the feature should:

class MyClass {
    public var oldField:String; // Field to be deleted

    public function doSomething() {
        trace(oldField); // This should be identified and removed
    }
}

// In another file
class AnotherClass {
    public function process(instance:MyClass) {
        var value = instance.oldField; // This should be identified and removed
    }
}

Benefits

Implementation Considerations

We believe this feature would improve the development experience in Haxe and VSCode, and we would love to see it - or parts of it - being implemented. Thank you for considering this request!

kLabz commented 2 months ago

That sounds incredibly unsafe for something that has "safe" in its name :fearful:

dubspeed commented 2 months ago

Good point, allow me to highlight the "safety" aspect a bit better.

Imagine one wants to remove a function called add from FlxPoint in Flixel Library. The function might be called dozens of times, however, using a simple search in codebase for add gives hundreds of results, so no easy task.

So, using the "Safe Delete" would use the information gathered during compilation to only target all usages of add towards the FlxPoint, making the operation "safe" in the sense that the result will compile.

Deleting code in a larger codebase can be hard work when concepts (like add/remove, subscribe/unsubscribe) with namings that are typically used overlap in multiple instances. The tool would make the job much, much easier, and the user can be safe to be left with a compiling codebase.