Skip to content
This repository was archived by the owner on Jun 22, 2024. It is now read-only.

Commit 8712700

Browse files
committed
New Compiler options setting to support UIKit
1 parent 4af9ade commit 8712700

File tree

6 files changed

+49
-22
lines changed

6 files changed

+49
-22
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Changelog
22

33
## 2.2.0
4-
* Autocompletion for external libraries like AppKit #8, UIKit still missing
4+
* Autocompletion for external libraries like AppKit and UIKit after restart #8
55
* Display short documentation on autocompletion
66
* More reliable autocompletion, especially for global namespace
7+
* New `"sde.sourcekit.compilerOptions"` setting
8+
9+
### How do I get autocompletion for UIKit?
10+
11+
Just add `"sde.sourcekit.compilerOptions": ["-target", "arm64-apple-ios11.0"]` to your workspace settings in Visual Studio Code and restart it.
12+
713

814
## 2.1.3
915
* Improved new README

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
```bash
1616
$ git clone https://github.com/vknabel/sourcekite
1717
$ cd sourcekite
18-
18+
1919
# For Linux
2020
$ swift build
21-
21+
2222
# For macOS (when using swiftenv or multiple Toolchains)
2323
$ swift build -Xswiftc -framework -Xswiftc sourcekitd -Xswiftc -F -Xswiftc /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/lib -Xlinker -rpath -Xlinker /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/lib -c release
24-
24+
2525
# For macOS (using Xcode's Toolchain)
2626
$ swift build -Xswiftc -framework -Xswiftc sourcekitd -Xswiftc -F -Xswiftc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/ -Xlinker -rpath -Xlinker /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/ -c release
2727
```
@@ -35,7 +35,7 @@ SDE has a built-in Swift debugger which has been deprecated. Instead use [LLDB D
3535

3636
An example config can be seen below. `program` should contain the path to your built executable, the `preLaunchTask` is optional, but will run `swift build` before each debug session to keep your binaries up to date.
3737

38-
> **Note:** Currently I don't know of any reliable solution to debug your Swift tests.
38+
> **Note:** Currently I don't know of any reliable solution to debug your Swift tests.
3939
> If you do, please file an issue or write me an [email](mailto:[email protected]).
4040
4141
```js
@@ -83,6 +83,10 @@ If you mean contributions to the **sources**, this is truely another topic. The
8383

8484
There aren't too much documents about the development of this project. If you have any questions or interests, don't hesitate to file an [issue](https://github.com/vknabel/swift-development-environment/issues) or write me an [email](mailto:[email protected]). I will help you and then drop more readings as time goes by. This is **_the way of "open source"_**.
8585

86+
### How do I get autocompletion for UIKit?
87+
88+
Just add `"sde.sourcekit.compilerOptions": ["-target", "arm64-apple-ios11.0"]` to your workspace settings in Visual Studio Code and restart it.
89+
8690
### Other questions?
8791

8892
If so, file an [issue](https://github.com/vknabel/swift-development-environment/issues), please :)

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url": "https://github.com/vknabel"
99
},
1010
"license": "Apache-2.0",
11-
"version": "2.1.3",
11+
"version": "2.2.0",
1212
"publisher": "vknabel",
1313
"icon": "icons/icon.png",
1414
"galleryBanner": {
@@ -77,6 +77,14 @@
7777
"default": "/bin/sh",
7878
"description": "The fully path to the shell binary."
7979
},
80+
"sde.sourcekit.compilerOptions": {
81+
"type": "array",
82+
"description": "Optional compiler options like the target or search paths.",
83+
"default": [],
84+
"items": {
85+
"type": "string"
86+
}
87+
},
8088
"sde.enableTracing.client": {
8189
"type": "boolean",
8290
"default": false,

src/clientMain.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import { SwiftConfigurationProvider } from './SwiftConfigurationProvider';
1818
const LENGTH_PKG_FILE_NAME: number = "Package.swift".length
1919
const PUBLISHER_NAME = "jinmingjian.sde"
2020

21-
let swiftBinPath = null
22-
let swiftPackageManifestPath = null
23-
let skProtocolProcess = null
24-
let skProtocolProcessAsShellCmd = null
21+
let swiftBinPath: string | null = null
22+
let swiftPackageManifestPath: string | null = null
23+
let skProtocolProcess: string | null = null
24+
let skProtocolProcessAsShellCmd: string | null = null
2525
export let isTracingOn: boolean = false
2626
export let isLSPServerTracingOn: boolean = false
2727
export let diagnosticCollection: DiagnosticCollection
@@ -57,7 +57,8 @@ export function activate(context: ExtensionContext) {
5757
initializationOptions: {
5858
'isLSPServerTracingOn': isLSPServerTracingOn,
5959
'skProtocolProcess': skProtocolProcess,
60-
'skProtocolProcessAsShellCmd': skProtocolProcessAsShellCmd
60+
'skProtocolProcessAsShellCmd': skProtocolProcessAsShellCmd,
61+
'skCompilerOptions': workspace.getConfiguration().get('sde.sourcekit.compilerOptions')
6162
},
6263
}
6364

@@ -90,7 +91,11 @@ export function activate(context: ExtensionContext) {
9091
);
9192
// build on save
9293
workspace.onDidSaveTextDocument(
93-
document => buildSPMPackage(),//FIXME filter to swift files
94+
document => {
95+
if (document.languageId === 'swift') {
96+
buildSPMPackage()
97+
}
98+
},
9499
null,
95100
context.subscriptions
96101
);
@@ -104,14 +109,9 @@ function initConfig() {
104109

105110
workspace.getConfiguration().update('editor.quickSuggestions', false, false)
106111
workspace.getConfiguration().update('sde.buildOnSave', true, false)
107-
// console.log('sde.enableTracing: '+workspace.getConfiguration().get('sde.enableTracing.client'))
108112

109113
isTracingOn = <boolean>workspace.getConfiguration().get('sde.enableTracing.client')
110114
isLSPServerTracingOn = <boolean>workspace.getConfiguration().get('sde.enableTracing.LSPServer')
111-
console.log('isTracingOn: ' + isTracingOn)
112-
if (isTracingOn) {
113-
//TODO
114-
}
115115
//FIXME rootPath may be undefined for adhoc file editing mode???
116116
swiftPackageManifestPath = path.join(workspace.rootPath, "Package.swift");
117117

@@ -126,7 +126,7 @@ function initBuildStatusItem() {
126126
}
127127

128128
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
129-
let building = null
129+
let building: NodeJS.Timer | null = null
130130

131131
function makeBuildStatusStarted() {
132132
buildStatusItem.color = originalBuildStatusItemColor
@@ -165,9 +165,9 @@ function isSPMProject(): boolean {
165165
}
166166

167167

168-
export function trace(msg) {
168+
export function trace(...msg: any[]) {
169169
if (isTracingOn) {
170-
console.log(msg)
170+
console.log(...msg)
171171
}
172172
}
173173

src/server/server.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ connection.onInitialize((params: InitializeParams, cancellationToken): Initializ
9494
isTracingOn = params.initializationOptions.isLSPServerTracingOn
9595
skProtocolPath = params.initializationOptions.skProtocolProcess
9696
skProtocolProcessAsShellCmd = params.initializationOptions.skProtocolProcessAsShellCmd
97+
skCompilerOptions = params.initializationOptions.skCompilerOptions
9798
trace("-->onInitialize ", `isTracingOn=[${isTracingOn}],
9899
skProtocolProcess=[${skProtocolPath}],skProtocolProcessAsShellCmd=[${skProtocolProcessAsShellCmd}]`)
99100
workspaceRoot = params.rootPath
@@ -134,6 +135,7 @@ export let maxBytesAllowedForCodeCompletionResponse: number = 0;
134135
//internal
135136
export let skProtocolPath = null
136137
export let skProtocolProcessAsShellCmd = false
138+
export let skCompilerOptions: string[] = []
137139
let maxNumProblems = null
138140
let shellPath = null
139141
// The settings have changed. Is send on server activation
@@ -519,11 +521,18 @@ export function loadArgsImportPaths(): string[] {
519521
//FIXME system paths can not be available automatically?
520522
// rt += " -I"+"/usr/lib/swift/linux/x86_64"
521523
argsImportPaths.push("-sdk")
522-
argsImportPaths.push("/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk")
524+
argsImportPaths.push("/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk")
525+
argsImportPaths.push("-sdk")
526+
argsImportPaths.push("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk")
527+
argsImportPaths.push("-sdk")
528+
argsImportPaths.push("/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk")
529+
argsImportPaths.push("-sdk")
530+
argsImportPaths.push("/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk")
523531
argsImportPaths.push("-I")
524532
argsImportPaths.push("/System/Library/Frameworks/")
525533
argsImportPaths.push("-I")
526534
argsImportPaths.push("/usr/lib/swift/pm/")
535+
argsImportPaths.push(...skCompilerOptions)
527536
return argsImportPaths
528537
} else {
529538
return argsImportPaths

src/server/sourcekites.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function request(
172172
offset: number): Promise<any> {
173173

174174
const sourcePaths = server.getAllSourcePaths(srcPath)
175-
const compilerargs = JSON.stringify((sourcePaths ? sourcePaths : [srcPath])
175+
const compilerargs = JSON.stringify(sourcePaths || [srcPath]
176176
.concat(server.loadArgsImportPaths())
177177
)
178178
srcText = JSON.stringify(srcText)

0 commit comments

Comments
 (0)