Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing rascal without the lib scheme #454

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rascal-lsp/META-INF/RASCAL.MF
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
Project-Name: rascal-lsp
Source: src/main/rascal
Require-Libraries: |lib://typepal/|, |lib://rascal-core/|
4 changes: 2 additions & 2 deletions rascal-lsp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<dependency>
<groupId>org.rascalmpl</groupId>
<artifactId>rascal</artifactId>
<version>0.40.7</version>
<version>0.40.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.rascalmpl</groupId>
Expand Down Expand Up @@ -176,7 +176,7 @@
<ignore>${project.basedir}/src/main/rascal/lang/rascal/lsp/refactor/WorkspaceInfo.rsc</ignore>
<ignore>${project.basedir}/src/main/rascal/lang/rascal/tests/rename</ignore>
</srcIgnores>
<sourceLookup>|lib://rascal-lsp|</sourceLookup>
<sourceLookup>|mvn://${project.groupId}--${project.name}--${project.version}|</sourceLookup>
<enableStandardLibrary>false</enableStandardLibrary>
</configuration>
<executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,11 @@ public CompletableFuture<String[]> supplyProjectCompilationClasspath(URIParamete
return CompletableFuture.supplyAsync(() -> {
try {
if (projectFolder.getUri() == null) {
return classLoaderFiles(PathConfig.getDefaultClassloadersList());
return classLoaderFiles(IRascalValueFactory.getInstance().list(PathConfig.resolveCurrentRascalRuntimeJar()));
}

PathConfig pcfg = findPathConfig(projectFolder.getLocation(), RascalConfigMode.COMPILER);
return classLoaderFiles(pcfg.getClassloaders());
return classLoaderFiles(pcfg.getLibsAndTarget());
}
catch (IOException | URISyntaxException e) {
logger.catching(e);
Expand Down Expand Up @@ -288,12 +289,12 @@ private static URI[] toURIArray(IList src) {
public CompletableFuture<Two<String, URI[]>[]> supplyPathConfig(PathConfigParameter projectFolder) {
return CompletableFuture.supplyAsync(() -> {
try {
// TODO: why are we not communicating the JSON representation of the PathConfig constructor?
var pcfg = PathConfig.fromSourceProjectMemberRascalManifest(projectFolder.getLocation(), projectFolder.getMode().mapConfigMode());
Two<String, URI[]>[] result = new Two[4];
@SuppressWarnings("unchecked")
Two<String, URI[]>[] result = new Two[2];
result[0] = new Two<>("Sources", toURIArray(pcfg.getSrcs()));
result[1] = new Two<>("Libraries", toURIArray(pcfg.getLibs()));
result[2] = new Two<>("Java Compiler Path", toURIArray(pcfg.getJavaCompilerPath()));
result[3] = new Two<>("Classloaders", toURIArray(pcfg.getClassloaders()));
return result;
} catch (IOException | URISyntaxException e) {
logger.catching(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,7 @@ private static boolean hasParentSection(URIResolverRegistry reg, ISourceLocation
}

private static PathConfig actualBuild(ISourceLocation projectRoot) {
try {
return PathConfig.fromSourceProjectRascalManifest(projectRoot, RascalConfigMode.COMPILER);
}
catch (IOException e) {
logger.error("Could not figure out path config for: {}, falling back to default", projectRoot, e);
return new PathConfig();
}
return PathConfig.fromSourceProjectRascalManifest(projectRoot, RascalConfigMode.COMPILER);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
import org.rascalmpl.interpreter.result.IRascalResult;
import org.rascalmpl.interpreter.result.ResultFactory;
import org.rascalmpl.interpreter.utils.RascalManifest;
import org.rascalmpl.jline.Terminal;
import org.rascalmpl.jline.TerminalFactory;
import org.rascalmpl.library.util.PathConfig;
import org.rascalmpl.library.util.PathConfig.RascalConfigMode;
import org.rascalmpl.repl.BaseREPL;
Expand All @@ -62,6 +60,7 @@
import org.rascalmpl.uri.URIResolverRegistry;
import org.rascalmpl.uri.URIUtil;
import org.rascalmpl.uri.classloaders.SourceLocationClassLoader;
import org.rascalmpl.uri.jar.JarURIResolver;
import org.rascalmpl.values.ValueFactoryFactory;
import org.rascalmpl.vscode.lsp.dap.DebugSocketServer;
import org.rascalmpl.vscode.lsp.uri.ProjectURIResolver;
Expand All @@ -70,7 +69,8 @@
import io.usethesource.vallang.ISourceLocation;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.io.StandardTextWriter;
import org.rascalmpl.jline.TerminalFactory;
import org.rascalmpl.jline.Terminal;

/**
* This class runs a Rascal terminal REPL that
Expand All @@ -89,8 +89,9 @@ public LSPTerminalREPL(Terminal terminal, IDEServices services, OutputStream std

private static String getRascalLspVersion() {
try {
var lspJar = PathConfig.resolveProjectOnClasspath("rascal-lsp");
return new Manifest(URIResolverRegistry.getInstance()
.getInputStream(URIUtil.correctLocation("lib", "rascal-lsp", "META-INF/MANIFEST.MF")))
.getInputStream(URIUtil.getChildLocation(lspJar, "META-INF/MANIFEST.MF")))
.getMainAttributes().getValue("Specification-Version");
} catch (IOException e) {
return "Unknown";
Expand Down Expand Up @@ -144,35 +145,46 @@ protected Evaluator constructEvaluator(InputStream input, OutputStream stdout, O
IValueFactory vf = ValueFactoryFactory.getValueFactory();
Evaluator evaluator = new Evaluator(vf, input, stderr, stdout, services, root, heap);
evaluator.addRascalSearchPathContributor(StandardLibraryContributor.getInstance());
evaluator.addRascalSearchPath(URIUtil.correctLocation("lib", "rascal-lsp", ""));


URIResolverRegistry reg = URIResolverRegistry.getInstance();

ISourceLocation projectDir = ShellEvaluatorFactory.inferProjectRoot(new File(System.getProperty("user.dir")));
String projectName = "unknown-project";
if (projectDir != null) {
projectName = new RascalManifest().getProjectName(projectDir);
}

reg.registerLogical(new ProjectURIResolver(services::resolveProjectLocation));
reg.registerLogical(new TargetURIResolver(services::resolveProjectLocation));

debugServer = new DebugSocketServer(evaluator, (TerminalIDEClient) services);

try {
var lspJar = PathConfig.resolveProjectOnClasspath("rascal-lsp");
evaluator.addRascalSearchPath(lspJar);

PathConfig pcfg;
if (projectDir != null) {
pcfg = PathConfig.fromSourceProjectRascalManifest(projectDir, RascalConfigMode.INTERPETER);
pcfg = PathConfig.fromSourceProjectRascalManifest(projectDir, RascalConfigMode.INTERPRETER);
}
else {
pcfg = new PathConfig();
pcfg.addSourceLoc(URIUtil.rootLocation("std"));
}

evaluator.getErrorPrinter().println("Rascal Version: " + RascalManifest.getRascalVersionNumber());
evaluator.getErrorPrinter().println("Rascal-lsp Version: " + getRascalLspVersion());
new StandardTextWriter(true).write(pcfg.asConstructor(), evaluator.getErrorPrinter());

var rascalLspLib = PathConfig.resolveProjectOnClasspath("rascal-lsp");

// the interpreter must find the Rascal sources of util::LanguageServer etc.
pcfg = pcfg.addSourceLoc(JarURIResolver.jarify(rascalLspLib));

// the interpreter must load the Java parts for calling util::IDEServices and registerLanguage
pcfg = pcfg.addLibLoc(rascalLspLib);

var out = evaluator.getOutPrinter();

out.println("Rascal " + RascalManifest.getRascalVersionNumber());
out.println("Rascal-lsp " + getRascalLspVersion());

pcfg.printInterpreterConfigurationStatus(out);

services.registerDiagnostics(pcfg.getMessages());

for (IValue srcPath : pcfg.getSrcs()) {
ISourceLocation path = (ISourceLocation)srcPath;
evaluator.addRascalSearchPath(path);
Expand All @@ -184,16 +196,14 @@ protected Evaluator constructEvaluator(InputStream input, OutputStream stdout, O
}

ClassLoader cl = new SourceLocationClassLoader(
pcfg.getClassloaders()
.append(URIUtil.correctLocation("lib", "rascal",""))
.append(URIUtil.correctLocation("lib", "rascal-lsp",""))
.append(URIUtil.correctLocation("target", projectName, "")),
pcfg.getLibsAndTarget(),
ClassLoader.getSystemClassLoader()
);

evaluator.addClassLoader(cl);
}
catch (IOException e) {
// TODO: don't we have a logger for this?
e.printStackTrace(new PrintStream(stderr));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class TerminalIDEClient implements IDEServices {
private final IRascalMonitor monitor;

public TerminalIDEClient(int port, IRascalMonitor monitor) throws IOException {
@SuppressWarnings("java:S2095") // we don't have to close the socket, we are passing it off to the lsp4j framework
@SuppressWarnings({ "java:S2095", "resource" }) // we don't have to close the socket, we are passing it off to the lsp4j framework
Socket socket = new Socket(InetAddress.getLoopbackAddress(), port);
socket.setTcpNoDelay(true);
Launcher<ITerminalIDEServer> launch = new Launcher.Builder<ITerminalIDEServer>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public int getValue() {

public RascalConfigMode mapConfigMode() {
switch (this) {
case INTERPRETER: return RascalConfigMode.INTERPETER;
case INTERPRETER: return RascalConfigMode.INTERPRETER;
case COMPILER: return RascalConfigMode.COMPILER;
default: throw new IllegalArgumentException("Missing case: " + this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import org.rascalmpl.interpreter.utils.LimitedResultWriter;
import org.rascalmpl.library.util.PathConfig;
import org.rascalmpl.shell.ShellEvaluatorFactory;
import org.rascalmpl.uri.URIUtil;
import org.rascalmpl.vscode.lsp.BaseWorkspaceService;
import org.rascalmpl.vscode.lsp.IBaseLanguageClient;
import org.rascalmpl.vscode.lsp.IBaseTextDocumentService;
Expand Down Expand Up @@ -243,11 +242,17 @@ public static CompletableFuture<Evaluator> makeFutureEvaluator(ExecutorService e
eval.getConfiguration().setRascalJavaClassPathProperty(System.getProperty("rascal.compilerClasspath"));
eval.addClassLoader(RascalLanguageServer.class.getClassLoader());
eval.addClassLoader(IValue.class.getClassLoader());

if (addRascalCore) {
eval.addRascalSearchPath(URIUtil.correctLocation("lib", "typepal", ""));
eval.addRascalSearchPath(URIUtil.correctLocation("lib", "rascal-core", ""));
var rascalCoreJar = PathConfig.resolveProjectOnClasspath("rascal-core");
var typePalJar = PathConfig.resolveProjectOnClasspath("typepal");

eval.addRascalSearchPath(typePalJar);
eval.addRascalSearchPath(rascalCoreJar);
}
eval.addRascalSearchPath(URIUtil.correctLocation("lib", "rascal-lsp", ""));

var rascalLspJar = PathConfig.resolveProjectOnClasspath("rascal-lsp");
eval.addRascalSearchPath(rascalLspJar);

if (pcfg != null) {
for (IValue src : pcfg.getSrcs()) {
Expand All @@ -259,7 +264,11 @@ public static CompletableFuture<Evaluator> makeFutureEvaluator(ExecutorService e

jobSuccess = true;
return eval;
} finally {
}
catch (IOException e) {
throw new RuntimeException(e);
}
finally {
services.jobEnd(jobName, jobSuccess);
}
}, exec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

public class RascalServices {
public static ITree parseRascalModule(ISourceLocation loc, char[] input) {
IActionExecutor<ITree> actions = new NoActionExecutor();
return new RascalParser().parse(Parser.START_MODULE, loc.getURI(), input, actions,
new DefaultNodeFlattener<>(), new UPTRNodeFactory(true));
IActionExecutor<ITree> actions = new NoActionExecutor(); return new RascalParser().parse(Parser.START_MODULE, loc.getURI(), input, actions, new DefaultNodeFlattener<>(), new UPTRNodeFactory(true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ bool testRename(str stmtsStr, int cursorAtOldNameOccurrence = 0, str oldName = "
private PathConfig getTestPathConfig(loc testDir) {
return pathConfig(
bin=testDir + "bin",
libs=[|lib://rascal|],
libs=[|std://rascal|],
srcs=[testDir + "rascal"],
resources=testDir + "bin",
generatedSources=testDir + "generated-sources"
Expand Down
Loading