sourcekit-lsp icon indicating copy to clipboard operation
sourcekit-lsp copied to clipboard

Add Remove unused parameter code action

Open amanmaurya92 opened this issue 9 months ago • 0 comments

Adds an LSP refactor that removes an unused function/initializer parameter and updates all call sites in the same file.

Example:

func greet(name: String, title: String) { 
print("Hello, \(name)") 
} 
With the cursor on the title → parameter and its argument at call sites are removed, so the signature becomes 
(name: String) 
and calls become greet(name: "Alice").

Changes:

RemoveUnusedParameter.swift (new):

Detects “unused” by checking that the parameter name does not appear as a DeclReferenceExpr in the body (syntactic only).

Builds a single declaration edit (range ends at rightParen.endPositionBeforeTrailingTrivia so the space before { is kept) and per-call-site edits by resolving relatedIdentifiers at the function name and removing the matching argument (and comma) from each FunctionCallExprSyntax.

SwiftLanguageService.swift:

Registers retrieveRemoveUnusedParameterCodeActions in the code action pipeline with kind .refactor.

CMakeLists.txt:

Adds the new file to the SwiftLanguageService target.

CodeActionTests.swift:

Adds testRemoveUnusedParameterCodeAction (request at parameter, apply edit to unmarked source, assert exact result).

amanmaurya92 avatar Mar 02 '26 20:03 amanmaurya92