Skip to content

Commit 43435af

Browse files
authored
[sourcekitd] Rename module SwiftSourceKit to SwiftLang. (#14497)
The sourcekitd client library provides parsing APIs for SwiftSyntax users. The internal use of sourcekit service is an implementation detail that end users shouldn't worry about.
1 parent f9299e7 commit 43435af

File tree

6 files changed

+43
-26
lines changed

6 files changed

+43
-26
lines changed

test/SwiftSyntax/DeserializeFile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import StdlibUnittest
77
import Foundation
88
import SwiftSyntax
9-
import SwiftSourceKit
9+
import SwiftLang
1010

1111
func getInput(_ file: String) -> URL {
1212
var result = URL(fileURLWithPath: #file)
@@ -20,7 +20,7 @@ var DecodeTests = TestSuite("DecodeSyntax")
2020

2121
DecodeTests.test("Basic") {
2222
expectDoesNotThrow({
23-
let content = try SourceFileSyntax.encodeSourceFileSyntax(getInput("visitor.swift"))
23+
let content = try SwiftLang.parse(getInput("visitor.swift"))
2424
let source = try String(contentsOf: getInput("visitor.swift"))
2525
let parsed = try SourceFileSyntax.decodeSourceFileSyntax(content)
2626
expectEqual("\(parsed)", source)

test/SwiftSyntax/ParseFile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import Foundation
77
import StdlibUnittest
88
import SwiftSyntax
9-
import SwiftSourceKit
9+
import SwiftLang
1010

1111
var ParseFile = TestSuite("ParseFile")
1212

@@ -32,7 +32,7 @@ ParseFile.test("ParseSingleFile") {
3232
expectDoesNotThrow({
3333
let currentFileContents = try String(contentsOf: currentFile)
3434
let parsed = try SourceFileSyntax.decodeSourceFileSyntax(try
35-
SourceKitdService.encodeSourceFileSyntax(currentFile))
35+
SwiftLang.parse(currentFile))
3636
expectEqual("\(parsed)", currentFileContents)
3737
})
3838
}

test/SwiftSyntax/VisitorTest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import StdlibUnittest
77
import Foundation
88
import SwiftSyntax
9-
import SwiftSourceKit
9+
import SwiftLang
1010

1111
func getInput(_ file: String) -> URL {
1212
var result = URL(fileURLWithPath: #file)
@@ -28,7 +28,7 @@ VisitorTests.test("Basic") {
2828
}
2929
expectDoesNotThrow({
3030
let parsed = try SourceFileSyntax.decodeSourceFileSyntax(try
31-
SourceKitdService.encodeSourceFileSyntax(getInput("visitor.swift")))
31+
SwiftLang.parse(getInput("visitor.swift")))
3232
let counter = FuncCounter()
3333
let hashBefore = parsed.hashValue
3434
counter.visit(parsed)

tools/SwiftSourceKitClient/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ set(EXTRA_COMPILE_FLAGS "-F" "${SWIFT_LIBRARY_OUTPUT_INTDIR}")
22
set(EXTRA_LINKER_FLAGS "-Xlinker" "-rpath" "-Xlinker" "${SWIFT_LIBRARY_OUTPUT_INTDIR}"
33
"-Xlinker" "-F" "-Xlinker" "${SWIFT_LIBRARY_OUTPUT_INTDIR}")
44

5-
add_swift_library(swiftSwiftSourceKit SHARED
5+
add_swift_library(swiftSwiftLang SHARED
6+
SwiftLang.swift
67
SourceKitdClient.swift
78
SourceKitdRequest.swift
89
SourceKitdResponse.swift

tools/SwiftSourceKitClient/SourceKitdClient.swift

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,3 @@ public class SourceKitdService {
2727
return SourceKitdResponse(resp: sourcekitd_send_request_sync(request.rawRequest))
2828
}
2929
}
30-
31-
extension SourceKitdService {
32-
/// Parses the Swift file at the provided URL into a `Syntax` tree in Json
33-
/// serialization format by querying SourceKitd service.
34-
/// - Parameter url: The URL you wish to parse.
35-
/// - Returns: The syntax tree in Json format string.
36-
public static func encodeSourceFileSyntax(_ url: URL) throws -> String {
37-
let Service = SourceKitdService()
38-
let Request = SourceKitdRequest(uid: .source_request_editor_open)
39-
let Path = url.path
40-
Request.addParameter(.key_sourcefile, value: Path)
41-
Request.addParameter(.key_name, value: Path)
42-
Request.addParameter(.key_enable_syntax_tree, value: 1)
43-
44-
// FIXME: SourceKitd error handling.
45-
let Resp = Service.sendSyn(request: Request)
46-
return Resp.value.getString(.key_serialized_syntax_tree)
47-
}
48-
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===--------------------- SwiftLang.swift -------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
// This file provides Swift language support by invoking SourceKit internally.
13+
//===----------------------------------------------------------------------===//
14+
15+
import Foundation
16+
17+
public class SwiftLang {
18+
19+
/// Parses the Swift file at the provided URL into a `Syntax` tree in Json
20+
/// serialization format by querying SourceKitd service.
21+
/// - Parameter url: The URL you wish to parse.
22+
/// - Returns: The syntax tree in Json format string.
23+
public static func parse(_ url: URL) throws -> String {
24+
let Service = SourceKitdService()
25+
let Request = SourceKitdRequest(uid: .source_request_editor_open)
26+
let Path = url.path
27+
Request.addParameter(.key_sourcefile, value: Path)
28+
Request.addParameter(.key_name, value: Path)
29+
Request.addParameter(.key_enable_syntax_tree, value: 1)
30+
31+
// FIXME: SourceKitd error handling.
32+
let Resp = Service.sendSyn(request: Request)
33+
return Resp.value.getString(.key_serialized_syntax_tree)
34+
}
35+
}

0 commit comments

Comments
 (0)