Skip to content

[sourcekitd] Rename module SwiftSourceKit to SwiftLang. #14497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2018
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
4 changes: 2 additions & 2 deletions test/SwiftSyntax/DeserializeFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import StdlibUnittest
import Foundation
import SwiftSyntax
import SwiftSourceKit
import SwiftLang

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

DecodeTests.test("Basic") {
expectDoesNotThrow({
let content = try SourceFileSyntax.encodeSourceFileSyntax(getInput("visitor.swift"))
let content = try SwiftLang.parse(getInput("visitor.swift"))
let source = try String(contentsOf: getInput("visitor.swift"))
let parsed = try SourceFileSyntax.decodeSourceFileSyntax(content)
expectEqual("\(parsed)", source)
Expand Down
4 changes: 2 additions & 2 deletions test/SwiftSyntax/ParseFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Foundation
import StdlibUnittest
import SwiftSyntax
import SwiftSourceKit
import SwiftLang

var ParseFile = TestSuite("ParseFile")

Expand All @@ -32,7 +32,7 @@ ParseFile.test("ParseSingleFile") {
expectDoesNotThrow({
let currentFileContents = try String(contentsOf: currentFile)
let parsed = try SourceFileSyntax.decodeSourceFileSyntax(try
SourceKitdService.encodeSourceFileSyntax(currentFile))
SwiftLang.parse(currentFile))
expectEqual("\(parsed)", currentFileContents)
})
}
Expand Down
4 changes: 2 additions & 2 deletions test/SwiftSyntax/VisitorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import StdlibUnittest
import Foundation
import SwiftSyntax
import SwiftSourceKit
import SwiftLang

func getInput(_ file: String) -> URL {
var result = URL(fileURLWithPath: #file)
Expand All @@ -28,7 +28,7 @@ VisitorTests.test("Basic") {
}
expectDoesNotThrow({
let parsed = try SourceFileSyntax.decodeSourceFileSyntax(try
SourceKitdService.encodeSourceFileSyntax(getInput("visitor.swift")))
SwiftLang.parse(getInput("visitor.swift")))
let counter = FuncCounter()
let hashBefore = parsed.hashValue
counter.visit(parsed)
Expand Down
3 changes: 2 additions & 1 deletion tools/SwiftSourceKitClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ set(EXTRA_COMPILE_FLAGS "-F" "${SWIFT_LIBRARY_OUTPUT_INTDIR}")
set(EXTRA_LINKER_FLAGS "-Xlinker" "-rpath" "-Xlinker" "${SWIFT_LIBRARY_OUTPUT_INTDIR}"
"-Xlinker" "-F" "-Xlinker" "${SWIFT_LIBRARY_OUTPUT_INTDIR}")

add_swift_library(swiftSwiftSourceKit SHARED
add_swift_library(swiftSwiftLang SHARED
SwiftLang.swift
SourceKitdClient.swift
SourceKitdRequest.swift
SourceKitdResponse.swift
Expand Down
19 changes: 0 additions & 19 deletions tools/SwiftSourceKitClient/SourceKitdClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,3 @@ public class SourceKitdService {
return SourceKitdResponse(resp: sourcekitd_send_request_sync(request.rawRequest))
}
}

extension SourceKitdService {
/// Parses the Swift file at the provided URL into a `Syntax` tree in Json
/// serialization format by querying SourceKitd service.
/// - Parameter url: The URL you wish to parse.
/// - Returns: The syntax tree in Json format string.
public static func encodeSourceFileSyntax(_ url: URL) throws -> String {
let Service = SourceKitdService()
let Request = SourceKitdRequest(uid: .source_request_editor_open)
let Path = url.path
Request.addParameter(.key_sourcefile, value: Path)
Request.addParameter(.key_name, value: Path)
Request.addParameter(.key_enable_syntax_tree, value: 1)

// FIXME: SourceKitd error handling.
let Resp = Service.sendSyn(request: Request)
return Resp.value.getString(.key_serialized_syntax_tree)
}
}
35 changes: 35 additions & 0 deletions tools/SwiftSourceKitClient/SwiftLang.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//===--------------------- SwiftLang.swift -------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// This file provides Swift language support by invoking SourceKit internally.
//===----------------------------------------------------------------------===//

import Foundation

public class SwiftLang {

/// Parses the Swift file at the provided URL into a `Syntax` tree in Json
/// serialization format by querying SourceKitd service.
/// - Parameter url: The URL you wish to parse.
/// - Returns: The syntax tree in Json format string.
public static func parse(_ url: URL) throws -> String {
let Service = SourceKitdService()
let Request = SourceKitdRequest(uid: .source_request_editor_open)
let Path = url.path
Request.addParameter(.key_sourcefile, value: Path)
Request.addParameter(.key_name, value: Path)
Request.addParameter(.key_enable_syntax_tree, value: 1)

// FIXME: SourceKitd error handling.
let Resp = Service.sendSyn(request: Request)
return Resp.value.getString(.key_serialized_syntax_tree)
}
}