Skip to content

Commit

Permalink
Merge pull request #337 from usethesource/fix-336-cross-project-watches
Browse files Browse the repository at this point in the history
Fix cross project automatic reloading
  • Loading branch information
jurgenvinju authored Nov 10, 2023
2 parents 6564442 + 380246e commit edf9f36
Showing 1 changed file with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,14 @@ protected Evaluator constructEvaluator(InputStream input, OutputStream stdout, O
((TerminalIDEClient) services).registerErrorPrinter(evaluator.getErrorPrinter());
}

for (IValue path : pcfg.getSrcs()) {
evaluator.addRascalSearchPath((ISourceLocation) path);
reg.watch((ISourceLocation) path, true, d -> sourceLocationChanged(pcfg, d));
for (IValue srcPath : pcfg.getSrcs()) {
ISourceLocation path = (ISourceLocation)srcPath;
evaluator.addRascalSearchPath(path);
// since the watch function in rascal only works on resolved paths
// we have to resolve the path, until that issue is remedied.
// see issue: https://github.com/usethesource/rascal/issues/1884
ISourceLocation resolvedPath = safeResolve(reg, path);
reg.watch(resolvedPath, true, d -> sourceLocationChanged(resolvedPath, d));
}

ClassLoader cl = new SourceLocationClassLoader(
Expand All @@ -232,22 +237,28 @@ protected Evaluator constructEvaluator(InputStream input, OutputStream stdout, O
return evaluator;
}

private void sourceLocationChanged(PathConfig pcfg, ISourceLocationChanged d) {
for (IValue src : pcfg.getSrcs()) {
ISourceLocation srcPath = (ISourceLocation) src;
private ISourceLocation safeResolve(URIResolverRegistry reg, ISourceLocation path) {
try {
ISourceLocation result = reg.logicalToPhysical(path);
return result == null ? path : result;
}
catch (Exception e) {
return path;
}
}

if (URIUtil.isParentOf(srcPath, d.getLocation())) {
ISourceLocation relative = URIUtil.relativize(srcPath, d.getLocation());
relative = URIUtil.removeExtension(relative);
private void sourceLocationChanged(ISourceLocation srcPath, ISourceLocationChanged d) {
if (URIUtil.isParentOf(srcPath, d.getLocation()) && d.getLocation().getPath().endsWith(".rsc")) {
ISourceLocation relative = URIUtil.relativize(srcPath, d.getLocation());
relative = URIUtil.removeExtension(relative);

String modName = relative.getPath();
if (modName.startsWith("/")) {
modName = modName.substring(1);
}
modName = modName.replaceAll("/", "::");
modName = modName.replaceAll("\\\\", "::");
dirtyModules.add(modName);
String modName = relative.getPath();
if (modName.startsWith("/")) {
modName = modName.substring(1);
}
modName = modName.replace("/", "::");
modName = modName.replace("\\", "::");
dirtyModules.add(modName);
}
}

Expand Down

0 comments on commit edf9f36

Please sign in to comment.