File tree Expand file tree Collapse file tree 10 files changed +26
-26
lines changed
sourcekitd/include/sourcekitd Expand file tree Collapse file tree 10 files changed +26
-26
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ func getInput(_ file: String) -> URL {
17
17
}
18
18
19
19
func getSyntaxTree( _ url: URL ) throws -> SourceFileSyntax {
20
- let content = try SwiftLang . parse ( url) . data ( using: . utf8) !
20
+ let content = try SwiftLang . parse ( path : url. path ) . data ( using: . utf8) !
21
21
return try SyntaxTreeDeserializer ( ) . deserialize ( content)
22
22
}
23
23
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ var DecodeTests = TestSuite("DecodeSyntax")
20
20
21
21
DecodeTests . test ( " Basic " ) {
22
22
expectDoesNotThrow ( {
23
- let content = try SwiftLang . parse ( getInput ( " visitor.swift " ) )
23
+ let content = try SwiftLang . parse ( path : getInput ( " visitor.swift " ) . path )
24
24
let contentData = content. data ( using: . utf8) !
25
25
let source = try String ( contentsOf: getInput ( " visitor.swift " ) )
26
26
let parsed = try SyntaxTreeDeserializer ( ) . deserialize ( contentData)
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ ParseFile.test("ParseSingleFile") {
31
31
let currentFile = URL ( fileURLWithPath: #file)
32
32
expectDoesNotThrow ( {
33
33
let fileContents = try String ( contentsOf: currentFile)
34
- let syntaxTreeData = try SwiftLang . parse ( fileContents) . data ( using: . utf8) !
34
+ let syntaxTreeData = try SwiftLang . parse ( source : fileContents) . data ( using: . utf8) !
35
35
let parsed = try SyntaxTreeDeserializer ( ) . deserialize ( syntaxTreeData)
36
36
expectEqual ( " \( parsed) " , fileContents)
37
37
} )
@@ -40,7 +40,7 @@ ParseFile.test("ParseSingleFile") {
40
40
ParseFile . test ( " ParseBuffer " ) {
41
41
expectDoesNotThrow ( {
42
42
let content = " func foo() {} "
43
- let syntaxTreeData = try SwiftLang . parse ( content) . data ( using: . utf8) !
43
+ let syntaxTreeData = try SwiftLang . parse ( source : content) . data ( using: . utf8) !
44
44
let parsed = try SyntaxTreeDeserializer ( ) . deserialize ( syntaxTreeData)
45
45
expectEqual ( " \( parsed) " , content)
46
46
} )
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ func getInput(_ file: String) -> URL {
17
17
}
18
18
19
19
func getSyntaxTree( _ url: URL ) throws -> SourceFileSyntax {
20
- let content = try SwiftLang . parse ( url) . data ( using: . utf8) !
20
+ let content = try SwiftLang . parse ( path : url. path ) . data ( using: . utf8) !
21
21
return try SyntaxTreeDeserializer ( ) . deserialize ( content)
22
22
}
23
23
Original file line number Diff line number Diff line change @@ -10,6 +10,4 @@ if(HAVE_UNICODE_LIBEDIT)
10
10
add_swift_tool_subdirectory (sourcekitd-repl )
11
11
endif ()
12
12
add_swift_tool_subdirectory (complete-test )
13
- if (BUILD_FOUNDATION )
14
- add_subdirectory (swift-lang )
15
- endif ()
13
+ add_subdirectory (swift-lang )
Original file line number Diff line number Diff line change
1
+ module sourcekitd {
2
+ umbrella header "sourcekitd.h"
3
+ export *
4
+ }
Original file line number Diff line number Diff line change 1
- set (EXTRA_COMPILE_FLAGS "-F" "${SWIFT_LIBRARY_OUTPUT_INTDIR} " )
2
- set (EXTRA_LINKER_FLAGS "-Xlinker" "-rpath" "-Xlinker" "${SWIFT_LIBRARY_OUTPUT_INTDIR} "
3
- "-Xlinker" "-F" "-Xlinker" "${SWIFT_LIBRARY_OUTPUT_INTDIR} " )
1
+ if (SWIFT_SOURCEKIT_USE_INPROC_LIBRARY )
2
+ set (EXTRA_COMPILE_FLAGS "-I" "${SOURCEKITD_SOURCE_DIR} /include/sourcekitd" )
3
+ set (SOURCEKITD_LINK_LIBS sourcekitdInProc )
4
+ set (INSTALLED_COMP sourcekit-inproc )
5
+ else ()
6
+ set (EXTRA_COMPILE_FLAGS "-F" "${SWIFT_LIBRARY_OUTPUT_INTDIR} " )
7
+ set (SOURCEKITD_LINK_LIBS sourcekitd )
8
+ set (INSTALLED_COMP sourcekit-xpc-service )
9
+ endif ()
4
10
5
11
add_swift_library (swiftSwiftLang SHARED
6
12
SwiftLang.swift
@@ -11,10 +17,7 @@ add_swift_library(swiftSwiftLang SHARED
11
17
UIDs.swift.gyb
12
18
13
19
DEPENDS sourcekitd-test
14
- PRIVATE_LINK_LIBRARIES sourcekitd
20
+ PRIVATE_LINK_LIBRARIES ${SOURCEKITD_LINK_LIBS}
15
21
SWIFT_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
16
- LINK_FLAGS ${EXTRA_LINKER_FLAGS}
17
- SWIFT_MODULE_DEPENDS Foundation
18
- INSTALL_IN_COMPONENT sourcekit-xpc-service
19
- TARGET_SDKS OSX
22
+ INSTALL_IN_COMPONENT ${INSTALLED_COMP}
20
23
IS_STDLIB )
Original file line number Diff line number Diff line change 13
13
//===----------------------------------------------------------------------===//
14
14
15
15
import sourcekitd
16
- import Foundation
17
16
18
17
public class SourceKitdService {
19
18
Original file line number Diff line number Diff line change 12
12
// This file provides convenient APIs to interpret a SourceKitd response.
13
13
//===----------------------------------------------------------------------===//
14
14
15
- import Foundation
16
15
import sourcekitd
17
16
18
17
public class SourceKitdResponse : CustomStringConvertible {
@@ -253,6 +252,6 @@ extension sourcekitd_variant_t: CustomStringConvertible {
253
252
}
254
253
255
254
private func fromCStringLen( _ ptr: UnsafePointer < Int8 > , length: Int ) -> String ? {
256
- return NSString ( bytes : ptr, length : length,
257
- encoding : String . Encoding . utf8 . rawValue ) as String ?
255
+ return String ( decoding : Array ( UnsafeBufferPointer ( start : ptr, count : length) ) . map {
256
+ UInt8 ( bitPattern : $0 ) } , as : UTF8 . self )
258
257
}
Original file line number Diff line number Diff line change 12
12
// This file provides Swift language support by invoking SourceKit internally.
13
13
//===----------------------------------------------------------------------===//
14
14
15
- import Foundation
16
-
17
15
enum SourceKitdError : Error , CustomStringConvertible {
18
16
case EditorOpenError( message: String )
19
17
case EditorCloseError( message: String )
@@ -65,16 +63,15 @@ public class SwiftLang {
65
63
/// thread safe.
66
64
/// - Parameter url: The URL you wish to parse.
67
65
/// - Returns: The syntax tree in Json format string.
68
- public static func parse( _ url: URL ) throws -> String {
69
- let Path = url. path
70
- return try parse ( content: Path, name: Path, isURL: true )
66
+ public static func parse( path: String ) throws -> String {
67
+ return try parse ( content: path, name: path, isURL: true )
71
68
}
72
69
73
70
/// Parses a given source buffer into a `Syntax` tree in Json serialization
74
71
/// format by querying SourceKitd service. This function isn't thread safe.
75
72
/// - Parameter source: The source buffer you wish to parse.
76
73
/// - Returns: The syntax tree in Json format string.
77
- public static func parse( _ source: String ) throws -> String {
74
+ public static func parse( source: String ) throws -> String {
78
75
return try parse ( content: source, name: " foo " , isURL: false )
79
76
}
80
77
}
You can’t perform that action at this time.
0 commit comments