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

Commit 4af9ade

Browse files
committed
Improved autocompletion #8 (partially)
1 parent fdc3fd6 commit 4af9ade

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 2.2.0
4+
* Autocompletion for external libraries like AppKit #8, UIKit still missing
5+
* Display short documentation on autocompletion
6+
* More reliable autocompletion, especially for global namespace
7+
38
## 2.1.3
49
* Improved new README
510
* Deprecated debugger, use [LLDB Debugger](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) instead

src/server/server.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,15 @@ connection.onCompletion(({textDocument, position}): Thenable<CompletionItem[]> =
231231
const offset = document.offsetAt(position) //FIXME
232232
return sourcekitProtocol
233233
.codeComplete(srcText, srcPath, offset)
234-
.then(function (completions) {
234+
.then(function (completions: Object[] | null) {
235235
let items = [];
236-
for (let c of <Array<Object>>completions) {
236+
for (let c of completions || []) {
237237
let item = CompletionItem.create(c["key.description"])
238238
item.kind = toCompletionItemKind(c["key.kind"])
239239
item.detail = `${c["key.modulename"]}.${c["key.name"]}`
240240
item.insertText = createSuggest(c["key.sourcetext"])
241241
item.insertTextFormat = InsertTextFormat.Snippet
242+
item.documentation = c["key.doc.brief"]
242243
items.push(item)
243244
}
244245
return items
@@ -510,14 +511,17 @@ export function getShellExecPath() {
510511
* TODO: to use build yaml?
511512
*/
512513
let argsImportPaths: string[] = null
513-
514514
export function loadArgsImportPaths(): string[] {
515515
if (!argsImportPaths) {
516516
argsImportPaths = []
517517
argsImportPaths.push("-I")
518518
argsImportPaths.push(path.join(workspaceRoot, '.build', 'debug'))
519519
//FIXME system paths can not be available automatically?
520520
// rt += " -I"+"/usr/lib/swift/linux/x86_64"
521+
argsImportPaths.push("-sdk")
522+
argsImportPaths.push("/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk")
523+
argsImportPaths.push("-I")
524+
argsImportPaths.push("/System/Library/Frameworks/")
521525
argsImportPaths.push("-I")
522526
argsImportPaths.push("/usr/lib/swift/pm/")
523527
return argsImportPaths

src/server/sourcekites.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function typedResponse<T>(request: string, requestType: RequestType,
144144
case "codecomplete":
145145
case "demangle":
146146
const res = JSON.parse(jsonify(resp))
147-
return res["key.results"]
147+
return res["key.results"] || []
148148
case "editor.formattext":
149149
const keyLine = extraState.keyLine
150150
const lineRange = extraState.lineRange
@@ -327,6 +327,6 @@ function cutOffResponse(s: string): string {
327327

328328
function jsonify(s: string): string {
329329
return s
330-
.replace(/(key.[a-z_.]+):/g, '"$1":')
331-
.replace(/(source.[a-z_.]+),/g, '"$1",')
330+
.replace(/(key\.[a-z_.]+):/g, '"$1":')
331+
.replace(/(source\.[a-z_.]+),/g, '"$1",')
332332
}

0 commit comments

Comments
 (0)