forked from swiftlang/sourcekit-lsp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle new swift-syntax closure expansion behavior
This resolves <swiftlang#1788>, following the discussion of alternatives on <https://github.com/swiftlang/sourcekit-lsp/pulls/1789>. The bulk of the change updates the translation from SourceKit placeholders to LSP placeholders to handle nesting.
- Loading branch information
1 parent
380ed38
commit 31fa3e9
Showing
4 changed files
with
223 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Tests/SourceKitLSPTests/RewriteSourceKitPlaceholdersTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import SKTestSupport | ||
@testable import SourceKitLSP | ||
import XCTest | ||
|
||
final class RewriteSourceKitPlaceholdersTests : XCTestCase { | ||
func testClientDoesNotSupportSnippets() { | ||
let input = "foo(bar: \(placeholder: "T##Int##Int#"))" | ||
let rewritten = rewriteSourceKitPlaceholders(in: input, clientSupportsSnippets: false) | ||
|
||
XCTAssertEqual(rewritten, "foo(bar: )") | ||
} | ||
|
||
func testInputWithoutPlaceholders() { | ||
let input = "foo()" | ||
let rewritten = rewriteSourceKitPlaceholders(in: input, clientSupportsSnippets: true) | ||
|
||
XCTAssertEqual(rewritten, "foo()") | ||
} | ||
|
||
func testPlaceholderWithType() { | ||
let input = "foo(bar: \(placeholder: "T##bar##Int"))" | ||
let rewritten = rewriteSourceKitPlaceholders(in: input, clientSupportsSnippets: true) | ||
|
||
XCTAssertEqual(rewritten, "foo(bar: ${1:Int})") | ||
} | ||
|
||
func testMultiplePlaceholders() { | ||
let input = "foo(bar: \(placeholder: "T##Int##Int"), baz: \(placeholder: "T##String##String"), quux: \(placeholder: "T##String##String"))" | ||
let rewritten = rewriteSourceKitPlaceholders(in: input, clientSupportsSnippets: true) | ||
|
||
XCTAssertEqual(rewritten, "foo(bar: ${1:Int}, baz: ${2:String}, quux: ${3:String})") | ||
} | ||
|
||
func testClosurePlaceholderReturnType() { | ||
let input = "foo(bar: \(placeholder: "{ \(placeholder: "T##Int##Int") }"))" | ||
let rewritten = rewriteSourceKitPlaceholders(in: input, clientSupportsSnippets: true) | ||
|
||
XCTAssertEqual(rewritten, "foo(bar: ${1:\\{ ${2:Int} \\}})") | ||
} | ||
|
||
func testClosurePlaceholderArgumentType() { | ||
let input = "foo(bar: \(placeholder: "{ \(placeholder: "T##Int##Int") in \(placeholder: "T##Void##Void") }"))" | ||
let rewritten = rewriteSourceKitPlaceholders(in: input, clientSupportsSnippets: true) | ||
|
||
XCTAssertEqual(rewritten, "foo(bar: ${1:\\{ ${2:Int} in ${3:Void} \\}})") | ||
} | ||
|
||
func testMultipleClosurePlaceholders() { | ||
let input = "foo(\(placeholder: "{ \(placeholder: "T##Int##Int") }"), baz: \(placeholder: "{ \(placeholder: "Int") in \(placeholder: "T##Bool##Bool") }"))" | ||
let rewritten = rewriteSourceKitPlaceholders(in: input, clientSupportsSnippets: true) | ||
|
||
XCTAssertEqual(rewritten, "foo(${1:\\{ ${2:Int} \\}}, baz: ${3:\\{ ${4:Int} in ${5:Bool} \\}})") | ||
} | ||
} | ||
|
||
private let placeholderStart = "<#" | ||
private let placeholderEnd = "#>" | ||
private extension DefaultStringInterpolation { | ||
mutating func appendInterpolation(placeholder string: String) { | ||
self.appendLiteral(placeholderStart + string + placeholderEnd) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters