Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import SwiftSyntax
/// ConvertStringConcatenationToStringInterpolation is a code action that converts a valid string concatenation into a
/// string interpolation.
struct ConvertStringConcatenationToStringInterpolation: SyntaxRefactoringProvider {
static func refactor(syntax: SequenceExprSyntax, in context: Void) -> SequenceExprSyntax? {
static func refactor(syntax: SequenceExprSyntax, in context: Void) throws -> SequenceExprSyntax {
guard let (componentsOnly, commonPounds) = preflight(exprList: syntax.elements) else {
return nil
throw RefactoringNotApplicableError("unsupported expression")
}

var segments: StringLiteralSegmentListSyntax = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ extension SyntaxRefactoringCodeActionProvider where Self.Context == Void {
return []
}

let sourceEdits = Self.textRefactor(syntax: node)
guard let sourceEdits = try? Self.textRefactor(syntax: node) else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahoppen I assume this runs on cursor movement generally and thus logging the reasons here would be too spammy?

return []
}

let textEdits = sourceEdits.compactMap { (edit) -> TextEdit? in
let edit = TextEdit(
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftLanguageService/CodeCompletionSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ class CodeCompletionSession {
var parser = Parser(exprToExpand)
let expr = ExprSyntax.parse(from: &parser)
guard let call = OutermostFunctionCallFinder.findOutermostFunctionCall(in: expr),
let expandedCall = ExpandEditorPlaceholdersToLiteralClosures.refactor(
let expandedCall = try? ExpandEditorPlaceholdersToLiteralClosures.refactor(
syntax: Syntax(call),
in: ExpandEditorPlaceholdersToLiteralClosures.Context(
format: .custom(
Expand Down
4 changes: 2 additions & 2 deletions Tests/SourceKitLSPTests/SyntaxRefactorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ func assertRefactor<R: EditRefactoringProvider>(
file: StaticString = #filePath,
line: UInt = #line
) throws {
let edits = R.textRefactor(syntax: input, in: context)
guard !edits.isEmpty else {
let edits = try? R.textRefactor(syntax: input, in: context)
guard let edits, !edits.isEmpty else {
if !expected.isEmpty {
XCTFail(
"""
Expand Down