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

Commit c62839f

Browse files
committed
Index all swift files together when no Package.swift defined #14
1 parent b0d5dcf commit c62839f

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

.vscode/settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
"search.exclude": {
77
"out": true // set this to false to include "out" folder in search results
88
},
9-
"typescript.tsdk": "./node_modules/typescript/lib",
10-
"editor.quickSuggestions": false
9+
"typescript.tsdk": "./node_modules/typescript/lib"
1110
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Will no longer write `sde.buildOnSave` or `editor.quickSuggestions` to workspace settings
77
* `#` will now trigger completions
88
* `-target` will now be detected for `UIKit`, `AppKit` on macOS and linux
9+
* Index all swift files together when no `Package.swift` defined #14
910

1011
## 2.3.0
1112
* Fixes autocompletion for methods and invocations leading to invalid syntax #9

src/server/server.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ let documents: TextDocuments = new TextDocuments();
2828
// for open, change and close text document events
2929
documents.listen(connection);
3030

31-
let allModulePaths: Map<string, string>;
32-
let allModuleSources: Map<string, Set<string>>;
31+
let allModulePaths: Map<string | null, string>;
32+
let allModuleSources: Map<string | null, Set<string>>;
3333
export function initializeModuleMeta() {
3434
trace('***initializeModuleMeta***')
35-
allModulePaths = new Map()
36-
allModuleSources = new Map()
35+
allModulePaths = new Map([[null, workspaceRoot]])
36+
allModuleSources = new Map([[null, new Set()]])
3737
const shPath = getShellExecPath()
3838
trace('***getShellExecPath: ', shPath)
3939
const sp = spawn(shPath, ["-c",
@@ -84,7 +84,12 @@ export function getAllSourcePaths(srcPath: string): string[] {
8484
return Array.from(ss)
8585
}
8686
}
87-
return null//can not find?
87+
// when not found: interpret all global files
88+
const globalSources = allModuleSources.get(null)
89+
if (globalSources.has(srcPath) === false) {
90+
globalSources.add(srcPath)
91+
}
92+
return Array.from(allModuleSources.get(null))
8893
}
8994

9095
// After the server has started the client sends an initilize request. The server receives
@@ -201,23 +206,22 @@ documents.onDidChangeContent((change) => {
201206
connection.onDidChangeWatchedFiles((watched) => {
202207
// trace('---','onDidChangeWatchedFiles');
203208
watched.changes.forEach(e => {
204-
let file;
209+
let file: string;
210+
function targetEntryForFile(filePath: string): [string | null, string] {
211+
return Array.from(allModulePaths.entries())
212+
.find(([targetName,]) => file.startsWith(targetName))
213+
|| [null, allModulePaths.get(null)];
214+
}
205215
switch (e.type) {
206216
case FileChangeType.Created:
207217
file = fromUriString(e.uri)
208-
for (const [m, p] of allModulePaths) {
209-
if (file.startsWith(m)) {
210-
allModuleSources.get(m).add(file)
211-
}
212-
}
218+
const [targetNameToAdd,] = targetEntryForFile(file);
219+
allModuleSources.get(targetNameToAdd).add(file);
213220
break
214221
case FileChangeType.Deleted:
215222
file = fromUriString(e.uri)
216-
for (const [m, p] of allModulePaths) {
217-
if (file.startsWith(m)) {
218-
allModuleSources.get(m).delete(file)
219-
}
220-
}
223+
const [targetNameToDelete,] = targetEntryForFile(file);
224+
allModuleSources.get(targetNameToDelete).delete(file);
221225
break
222226
default:
223227
//do nothing

src/server/sourcekites.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function request(
207207
...server.loadArgsImportPaths(),
208208
...inferredTargetArgs
209209
])
210-
console.log(compilerargs)
210+
211211
srcText = JSON.stringify(srcText)
212212
let request = `{
213213
key.request: source.request.${requestType},

0 commit comments

Comments
 (0)