This repository has been archived by the owner on Jun 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed an issue preventing autocompletion to work reliably on Linux, f…
…ixes #54
- Loading branch information
Showing
8 changed files
with
198 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# Changelog | ||
|
||
## 2.8.1 | ||
|
||
- Fixed an issue preventing autocompletion to work reliably on Linux, fixes [#54](https://github.com/vknabel/vscode-swift-development-environment/issues/54) | ||
- Installation instructions now correctly link `/usr/lib/libsourcekitdInProc.so`, noticed by [@kennethz3](https://github.com/kennethz3) | ||
- Support quoted arguments in settings, fixed by [@haifengkao](https://github.com/haifengkao) | ||
|
||
## 2.8.0 | ||
|
||
- Now LSP-mode `sourcekite` supports `sourcekit-lsp.toolchainPath` after updating to [[email protected]](https://github.com/vknabel/sourcekite/releases/tag/0.6.0) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import { | ||
removingDuplicateSources, | ||
flatteningTargetsWithUniqueSources | ||
} from "./package-helpers"; | ||
import { Target } from "../package"; | ||
|
||
const uniqueTarget: Target = { | ||
name: "Unique", | ||
path: "Sources/Unique", | ||
sources: new Set(["Hello.swift", "main.swift"]), | ||
compilerArguments: [] | ||
}; | ||
|
||
const unrelatedTarget: Target = { | ||
name: "UnrelatedTarget", | ||
path: "Sources/UnrelatedTarget", | ||
sources: new Set(["Unrelated.swift"]), | ||
compilerArguments: [] | ||
}; | ||
|
||
describe("package helpers", () => { | ||
describe("removingDuplicateSources", () => { | ||
it("does not emit unique targets", () => { | ||
const emittedTargets = removingDuplicateSources([], [uniqueTarget]); | ||
expect(emittedTargets).toHaveLength(0); | ||
}); | ||
|
||
it("unrelated source sets will be kept", () => { | ||
const emittedTargets = removingDuplicateSources( | ||
[unrelatedTarget], | ||
[uniqueTarget] | ||
); | ||
expect(emittedTargets).toEqual([unrelatedTarget]); | ||
}); | ||
|
||
it("unrelated source sets with differing paths will be kept for same file names", () => { | ||
const unrelatedTargetWithSameFileNames: Target = { | ||
...unrelatedTarget, | ||
sources: uniqueTarget.sources | ||
}; | ||
|
||
const emittedTargets = removingDuplicateSources( | ||
[unrelatedTargetWithSameFileNames], | ||
[uniqueTarget] | ||
); | ||
expect(emittedTargets).toEqual([unrelatedTargetWithSameFileNames]); | ||
}); | ||
|
||
it("source sets with same paths but different file names are kept", () => { | ||
const samePathTargetWithDifferentSources = { | ||
...unrelatedTarget, | ||
path: uniqueTarget.path | ||
}; | ||
const emittedTargets = removingDuplicateSources( | ||
[samePathTargetWithDifferentSources], | ||
[uniqueTarget] | ||
); | ||
expect(emittedTargets).toEqual([samePathTargetWithDifferentSources]); | ||
}); | ||
|
||
it("source sets with different paths but same files will be deuplicated", () => { | ||
const differentPathTargetWithSameSources = { | ||
...unrelatedTarget, | ||
path: "./", | ||
sources: new Set( | ||
Array(uniqueTarget.sources.values()).map( | ||
sourceFile => `${uniqueTarget.path}/${sourceFile}` | ||
) | ||
) | ||
}; | ||
const emittedTargets = removingDuplicateSources( | ||
[differentPathTargetWithSameSources], | ||
[uniqueTarget] | ||
); | ||
expect(emittedTargets).toEqual([differentPathTargetWithSameSources]); | ||
}); | ||
}); | ||
|
||
describe("flatteningTargetsWithUniqueSources", () => { | ||
it("bug: configs did not override global paths", () => { | ||
// see https://github.com/vknabel/vscode-swift-development-environment/issues/55 | ||
const emittedTargets = flatteningTargetsWithUniqueSources( | ||
[ | ||
{ | ||
name: "HiModuleFromConfigs", | ||
path: "/Users/vknabel/Desktop/AutocompleteIos/Sources/Hi", | ||
sources: new Set(["Hi.swift"]), | ||
compilerArguments: [] | ||
} | ||
], | ||
[ | ||
{ | ||
name: "HiModuleFromDebugYaml", | ||
path: "/Users/vknabel/Desktop/AutocompleteIos", | ||
sources: new Set([ | ||
"/Users/vknabel/Desktop/AutocompleteIos/Sources/Hi/Hi.swift" | ||
]), | ||
compilerArguments: [] | ||
} | ||
], | ||
[ | ||
{ | ||
name: "AutocompleteIos", | ||
path: "/Users/vknabel/Desktop/AutocompleteIos", | ||
sources: new Set([ | ||
"/Users/vknabel/Desktop/AutocompleteIos/Package.swift" | ||
]), | ||
compilerArguments: [] | ||
} | ||
] | ||
); | ||
expect(emittedTargets).toEqual([ | ||
{ | ||
name: "HiModuleFromConfigs", | ||
path: "/Users/vknabel/Desktop/AutocompleteIos/Sources/Hi", | ||
sources: new Set(["Hi.swift"]), | ||
compilerArguments: [] | ||
}, | ||
{ | ||
name: "HiModuleFromDebugYaml", | ||
path: "/Users/vknabel/Desktop/AutocompleteIos", | ||
sources: new Set([]), | ||
compilerArguments: [] | ||
}, | ||
{ | ||
name: "AutocompleteIos", | ||
path: "/Users/vknabel/Desktop/AutocompleteIos", | ||
sources: new Set([ | ||
"/Users/vknabel/Desktop/AutocompleteIos/Package.swift" | ||
]), | ||
compilerArguments: [] | ||
} | ||
]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Target } from "../package"; | ||
import * as path from "path"; | ||
|
||
export function flatteningTargetsWithUniqueSources( | ||
...targets: Target[][] | ||
): Target[] { | ||
return targets.reduce( | ||
(current, next) => [ | ||
...current, | ||
...removingDuplicateSources(next, current.map(normalizedTarget)) | ||
], | ||
[] | ||
); | ||
} | ||
|
||
export function removingDuplicateSources( | ||
fromTargets: Target[], | ||
uniqueTargets: Target[] | ||
): Target[] { | ||
return fromTargets.map(target => { | ||
const swiftFilesWithoutTargets = Array.from(target.sources).filter( | ||
source => | ||
uniqueTargets.findIndex(desc => | ||
desc.sources.has(path.resolve(target.path, source)) | ||
) === -1 | ||
); | ||
return { ...target, sources: new Set(swiftFilesWithoutTargets) }; | ||
}); | ||
} | ||
|
||
function normalizedTarget(target: Target): Target { | ||
return { | ||
...target, | ||
sources: mapSet(target.sources, source => path.resolve(target.path, source)) | ||
}; | ||
} | ||
function mapSet<T, R>(set: Set<T>, transform: (element: T) => R): Set<R> { | ||
return new Set(Array.from(set.values()).map(element => transform(element))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters