dotnet / dotnet/vscode-csharp

[Feature Request] Change Function Signature

Open
#4,613 0 comments 0 reactions 0 assignees View on GitHub
OmniSharp
Dominant language
TypeScript
Stars
3.1k
Forks
737
Avg merge
18h 40m
Merged PRs (30d)
31

Description

Being able to change a function's signature has been a staple of many popular IDEs such as Visual Studio and Intellij's IDEs.

I believe this feature greatly helps during refactoring, specifically for the following actions:

- Reordering function parameters.
- Adding/removing function parameters.

### Example of Reordering Parameters:

**_Original Code:_**

```
namespace MyProject
{
class Program
{
static void Main()
{
Add(2, 3);
}

static int Add(int a, int b)
{
return a + b;
}
}
}
```

**_Code After Reordering Parameters:_**

```
namespace MyProject
{
class Program
{
static void Main()
{
Add(3, 2);
}

static int Add(int b, int a)
{
return a + b;
}
}
}
```

Above, not only did the function's signature change but all callers have also been updated to conform with the new signature.

### Example of Adding Parameters:

**_Original Code:_**

```
namespace MyProject
{
class Program
{
static void Main()
{
Add(2, 3);
}

static int Add(int a, int b)
{
return a + b;
}
}
}
```

**_Code After Adding Parameter(s):_**

```
namespace MyProject
{
class Program
{
static void Main()
{
Add(2, 3, 4);
}

static int Add(int a, int b, int c, int d = 0)
{
return a + b + c + d;
}
}
}
```

During refactoring, the extension will ask the developer for the name, type, and value to use for each new parameter.

If the new parameter is required, the extension will inject the new value to all existing callers. If the new parameter is optional with a default value, it will simply be inserted into the signature and no change to the callers will be made.

Above, a value of `4` was inserted to all callers for the new required `c` parameter, and because the new `d` parameter is optional, no changes to the callers were made for it.

### Example of Removing Parameters:

**_Original Code:_**

```
namespace MyProject
{
class Program
{
static void Main()
{
Add(2, 3, 4);
}

static int Add(int a, int b, int c)
{
return a + b + c;
}
}
}
```

**_Code After Removing Parameter(s):_**

```
namespace MyProject
{
class Program
{
static void Main()
{
Add(2, 3);
}

static int Add(int a, int b)
{
return a + b;
}
}
}
```

Above, the extension updates all callers to conform with the new function signature.

The extension should pattern this feature on **_[the existing one inside Visual Studio](https://docs.microsoft.com/en-us/visualstudio/ide/reference/change-method-signature?view=vs-2019)_** which supports C#.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.