Skip to content

Commit 8d83082

Browse files
committed
[IMP] attach additional stubs
1 parent b2da84a commit 8d83082

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

.github/workflows/build_plugin.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ jobs:
2626
run: |
2727
wget ${{ steps.version.outputs.changelog_url }} -O CHANGELOG.md
2828
29+
- name: Checkout additional stubs from OdooLS
30+
uses: actions/checkout@v4
31+
with:
32+
repository: odoo/odoo-ls
33+
ref: ${{ steps.version.outputs.version }}
34+
path: additional_stubs
35+
sparse-checkout: server/additional_stubs
36+
sparse-checkout-cone-mode: false
37+
38+
- name: Flatten additional_stubs and clean
39+
run: |
40+
# Move the stubs to the root of additional_stubs
41+
mv additional_stubs/server/additional_stubs/* src/main/resources/additional_stubs/
42+
rm -rf additional_stubs/server
43+
2944
- name: Download language server binaries
3045
run: |
3146
VERSION=${{ steps.version.outputs.version }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
build
88
src/main/resources/odools-binaries
99
src/main/resources/typeshed
10+
additional_stubs

src/main/kotlin/com/odoo/odools/OdooLSInstallationProjectActivity.kt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,17 @@ class OdooLSInstallationProjectActivity : ProjectActivity, DumbAware {
5353
}
5454

5555
fun copyDirectoryFromResourcesToInstallLocation(directoryPath: String, targetPath: String) {
56-
val targetLocation = Paths.get(targetPath, "typeshed")
56+
val targetLocation = Paths.get(targetPath, directoryPath)
5757
val resourceUrl = javaClass.classLoader.getResource(directoryPath)
5858
?: throw IllegalArgumentException("Resource not found: $directoryPath")
5959

6060
if (resourceUrl.protocol == "jar") {
61-
val fileSystem = FileSystems.newFileSystem(resourceUrl.toURI(), emptyMap<String, Any>())
61+
val uri = resourceUrl.toURI()
62+
val fileSystem = try {
63+
FileSystems.getFileSystem(uri)
64+
} catch (e: java.nio.file.FileSystemNotFoundException) {
65+
FileSystems.newFileSystem(uri, emptyMap<String, Any>())
66+
}
6267
val jarPath = fileSystem.getPath(directoryPath)
6368
Files.walk(jarPath).forEach { source ->
6469
val dest = targetLocation.resolve(jarPath.relativize(source).toString())
@@ -82,7 +87,7 @@ class OdooLSInstallationProjectActivity : ProjectActivity, DumbAware {
8287
}
8388
}
8489

85-
fun ressourceToInstallPath(resourcePath: String, targetPath: Path) {
90+
fun resourceToInstallPath(resourcePath: String, targetPath: Path) {
8691
javaClass.classLoader.getResourceAsStream(resourcePath).use { input ->
8792
requireNotNull(input) { "Resource not found: $resourcePath" }
8893
try {
@@ -192,23 +197,31 @@ class OdooLSInstallationProjectActivity : ProjectActivity, DumbAware {
192197

193198
installedVersionOlder(Paths.get(targetLocation, exeName)) { isOlder ->
194199
if (isOlder) {
195-
ressourceToInstallPath("odools-binaries/${targetOs}/$exeName", Paths.get(targetLocation, exeName))
200+
resourceToInstallPath("odools-binaries/${targetOs}/$exeName", Paths.get(targetLocation, exeName))
196201

197202
if (SystemInfo.isWindows &&
198203
(!Files.exists(Paths.get(targetLocation, "odoo_ls_server.pdb")))) {
199-
ressourceToInstallPath("odools-binaries/${targetOs}/odoo_ls_server.pdb", Paths.get(targetLocation, "odoo_ls_server.pdb"))
204+
resourceToInstallPath("odools-binaries/${targetOs}/odoo_ls_server.pdb", Paths.get(targetLocation, "odoo_ls_server.pdb"))
200205
}
201206
if (!SystemInfo.isWindows) {
202207
Paths.get(targetLocation, exeName).toFile().setExecutable(true, false)
203208
}
204209
}
205-
if (!Files.exists(Paths.get(targetLocation, "typeshed")) && isTypeshedOutDated(Paths.get(targetLocation, "typeshed"))) {
210+
if (!Files.exists(Paths.get(targetLocation, "typeshed")) || isTypeshedOutDated(Paths.get(targetLocation, "typeshed"))) {
206211
val file = Paths.get(targetLocation, "typeshed").toFile()
207212
if (file.exists()) {
208213
file.deleteRecursively()
209214
}
210215
copyDirectoryFromResourcesToInstallLocation("typeshed", targetLocation)
211216
}
217+
if (!Files.exists(Paths.get(targetLocation, "additional_stubs"))) {
218+
val file = Paths.get(targetLocation, "additional_stubs").toFile()
219+
if (file.exists()) {
220+
file.deleteRecursively()
221+
}
222+
copyDirectoryFromResourcesToInstallLocation("additional_stubs", targetLocation)
223+
224+
}
212225
println("Installation complete")
213226
callback()
214227
}

0 commit comments

Comments
 (0)