Skip to content

Commit

Permalink
Support configurable libs dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenLooman committed Nov 20, 2023
1 parent 8f23739 commit 48c9bae
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

0.9.0 (unreleased)

- Support configurable libs dirs.

0.8.3 (unreleased)

- Fix error finding start/end line/column for Scopes, when encountering an empty block.
Expand Down
4 changes: 4 additions & 0 deletions magik-language-server/client-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@
"description": "Path to Smallworld Core.",
"type": "string"
},
"magik.libsDirs": {
"description": "Paths to libs dirs of Smallworld products",
"type": "array"
},
"magik.aliases": {
"description": "Path to gis_aliases file.",
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ public String getSmallworldGis() {
return smallworldGis.getAsString();
}

/**
* Get magik.libsDirs.
* @return magik.libsDirs.
*/
public List<String> getLibsDirs() {
final JsonObject magik = this.settings.getAsJsonObject(TOP_LEVEL);
if (magik == null) {
return Collections.emptyList();
}

final JsonArray libsDirs = magik.getAsJsonArray("libsDirs");
if (libsDirs == null) {
return Collections.emptyList();
}

final List<String> paths = new ArrayList<>();
libsDirs.forEach(jsonElement -> {
final String path = jsonElement.getAsString();
paths.add(path);
});
return paths;
}

/**
* Get magik.typing.typeDatabasePath.
* @return magik.typing.typeDatabasePath.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import nl.ramsolutions.sw.IgnoreHandler;
import nl.ramsolutions.sw.magik.analysis.typing.ClassInfoTypeKeeperReader;
import nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper;
Expand Down Expand Up @@ -106,7 +105,7 @@ private void runIgnoreFilesIndexer() {
.forEach(path -> {
try {
this.ignoreHandler.addIgnoreFile(path);
} catch (IOException exception) {
} catch (final IOException exception) {
LOGGER.error(exception.getMessage(), exception);
}
});
Expand All @@ -129,26 +128,22 @@ private void runIndexer() {
}
}

private void readLibsDocs(final @Nullable String smallworldGisDir) {
LOGGER.trace("Reading libs docs from: {}", smallworldGisDir);
private void readLibsClassInfos(final List<String> libsDirs) {
LOGGER.trace("Reading libs docs from: {}", libsDirs);

if (smallworldGisDir == null
|| smallworldGisDir.trim().isEmpty()) {
LOGGER.info("No smallworld gis directory configured");
return;
}

final Path libsDirPath = Path.of(smallworldGisDir).resolve("sw_core").resolve("libs");
if (!Files.exists(libsDirPath)) {
return;
}
libsDirs.forEach(pathStr -> {
final Path path = Path.of(pathStr);
if (!Files.exists(path)) {
LOGGER.warn("Path to libs dir does not exist: {}", pathStr);
return;
}

// Move to ClassInfoTypeKeeperReader class.
try {
ClassInfoTypeKeeperReader.readLibsDirectory(libsDirPath, this.typeKeeper);
} catch (IOException exception) {
LOGGER.error(exception.getMessage(), exception);
}
try {
ClassInfoTypeKeeperReader.readLibsDirectory(path, this.typeKeeper);
} catch (final IOException exception) {
LOGGER.error(exception.getMessage(), exception);
}
});
}

/**
Expand All @@ -166,8 +161,8 @@ public void readTypesDbs(final List<String> typeDbPaths) {
}

try {
JsonTypeKeeperReader.readTypes(path, this.typeKeeper);
} catch (IOException exception) {
JsonTypeKeeperReader.read(path, this.typeKeeper);
} catch (final IOException exception) {
LOGGER.error(exception.getMessage(), exception);
}
});
Expand Down Expand Up @@ -289,11 +284,9 @@ private void runIndexers() {
final List<String> typesDbPaths = MagikSettings.INSTANCE.getTypingTypeDatabasePaths();
this.readTypesDbs(typesDbPaths);

// Read method docs.
final String smallworldGisDir = MagikSettings.INSTANCE.getSmallworldGis();
if (smallworldGisDir != null) {
this.readLibsDocs(smallworldGisDir);
}
// Read class_infos from libs/ dirs.
final List<String> libsDirs = MagikSettings.INSTANCE.getLibsDirs();
this.readLibsClassInfos(libsDirs);

// Index .magik-tools-ignore files.
this.runIgnoreFilesIndexer();
Expand Down Expand Up @@ -324,7 +317,7 @@ private void runIndexersInBackground() {

try {
this.runIndexers();
} catch (Exception exception) {
} catch (final Exception exception) {
LOGGER.error(exception.getMessage(), exception);
}

Expand Down

0 comments on commit 48c9bae

Please sign in to comment.