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 a87d8b4
Showing
4 changed files
with
215 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
54 changes: 54 additions & 0 deletions
54
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,54 @@ | ||
import SKTestSupport | ||
@testable import SourceKitLSP | ||
import XCTest | ||
|
||
final class RewriteSourceKitPlaceholdersTests : XCTestCase { | ||
func testClientDoesNotSupportSnippets() { | ||
let input = "foo(bar: <#T##bar##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: <#T##bar##Int#>)" | ||
let rewritten = rewriteSourceKitPlaceholders(in: input, clientSupportsSnippets: true) | ||
|
||
XCTAssertEqual(rewritten, "foo(bar: ${1:Int})") | ||
} | ||
|
||
func testMultiplePlaceholders() { | ||
let input = "foo(bar: <#T##Int##Int#>, baz: <#T##String##String#>, quux: <#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: <#{ <#T##Int##Int#> }#>)" | ||
let rewritten = rewriteSourceKitPlaceholders(in: input, clientSupportsSnippets: true) | ||
|
||
XCTAssertEqual(rewritten, "foo(bar: ${1:\\{ ${2:Int} \\}})") | ||
} | ||
|
||
func testClosurePlaceholderArgumentType() { | ||
let input = "foo(bar: <#{ <#T##Int##Int#> in <#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(<#{ <#T##Int##Int#> }#>, baz: <#{ <#Int#> in <#T##Bool##Bool#> }#>)" | ||
let rewritten = rewriteSourceKitPlaceholders(in: input, clientSupportsSnippets: true) | ||
|
||
XCTAssertEqual(rewritten, "foo(${1:\\{ ${2:Int} \\}}, baz: ${3:\\{ ${4:Int} in ${5:Bool} \\}})") | ||
} | ||
} |
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