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

Migrate to jline3 #2063

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
31cb437
Working on jline3
DavyLandman May 28, 2024
c67a197
Working on jline3
DavyLandman May 29, 2024
08ffabd
Working on jline3
DavyLandman May 30, 2024
b02f63f
Cleaning up pom to drop jline2 related dependencies
DavyLandman Oct 15, 2024
57b43d1
Removing InputStream and OutputStreams from the evaluator
DavyLandman Oct 15, 2024
61d4387
Rewriting away old parts of the jline2 code
DavyLandman Oct 15, 2024
94b9425
Rewrote TerminalProgressBarMonitor
DavyLandman Oct 15, 2024
1fd8348
Working on migrating to the new repl api
DavyLandman Oct 22, 2024
91998c1
Got the first working repl to do multiline
DavyLandman Oct 24, 2024
3aa2626
Got ctrl+c to work correctly
DavyLandman Oct 24, 2024
de6d79f
Added lines to the continuation prompt
DavyLandman Oct 24, 2024
38989b9
A bit more tweaking of the prompts
DavyLandman Oct 24, 2024
3145e2f
Added initial support for command completion
DavyLandman Nov 20, 2024
79bdf53
Added module completion support
DavyLandman Nov 21, 2024
27bf01f
Also added support for keywords and identifier completion
DavyLandman Nov 21, 2024
c0387b0
Support ctrl+c to interrupt a running rascal command
DavyLandman Nov 21, 2024
3d53007
Added location completion support
DavyLandman Nov 21, 2024
26d6052
Tuned completion a bit around locations and strings
DavyLandman Nov 25, 2024
922c61e
Fixed word lexer test
DavyLandman Nov 25, 2024
11a9103
Detect keywords and escape them in completions
DavyLandman Nov 25, 2024
4adaced
Updated todo list
DavyLandman Nov 25, 2024
2370802
Added queued command support
DavyLandman Nov 25, 2024
a58f57e
Added clear capability
DavyLandman Dec 17, 2024
0a911ac
Remove old implementation of REPL
DavyLandman Dec 17, 2024
43d4b65
Rewrote everything into output streams to reduce all the strings
DavyLandman Dec 18, 2024
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
10 changes: 10 additions & 0 deletions src/org/rascalmpl/ideservices/BasicIDEServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,26 @@
public class BasicIDEServices implements IDEServices {
private final IRascalMonitor monitor;
private final PrintWriter stderr;
private final Runnable clearRepl;

public BasicIDEServices(PrintWriter stderr, IRascalMonitor monitor){
this(stderr, monitor, () -> {});
}
public BasicIDEServices(PrintWriter stderr, IRascalMonitor monitor, Runnable clearRepl){
this.stderr = stderr;
this.monitor = monitor;
this.clearRepl = clearRepl;
}

@Override
public PrintWriter stderr() {
return stderr;
}

@Override
public void clearRepl() {
this.clearRepl.run();
}

public void browse(ISourceLocation loc, String title, int viewColumn){
browse(loc.getURI(), title, viewColumn);
Expand Down
4 changes: 4 additions & 0 deletions src/org/rascalmpl/ideservices/IDEServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ default void unregisterLanguage(IConstructor language) {
throw new UnsupportedOperationException("registerLanguage is not implemented in this environment.");
}

default void clearRepl() {
throw new UnsupportedOperationException("Clear REPL is not supported in this IDE Service");
}

/**
* Asks the IDE to apply document edits as defined in the standard library module
* analysis::diff::edits::TextEdits, according to the semantics defined in
Expand Down
2 changes: 2 additions & 0 deletions src/org/rascalmpl/repl/BaseREPL2.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jline.terminal.Terminal.Signal;
import org.jline.terminal.Terminal.SignalHandler;
import org.jline.utils.ShutdownHooks;
import org.jline.utils.InfoCmp.Capability;
DavyLandman marked this conversation as resolved.
Show resolved Hide resolved

public class BaseREPL2 {

Expand Down Expand Up @@ -89,6 +90,7 @@ public BaseREPL2(IREPLService replService, Terminal term) {
// - support for html results
// - measure time
// - history?
// - possible to tee output
}

public void run() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class RascalCommandCompletion implements Completer {
COMMAND_KEYWORDS.put("history", "history"); // TODO: figure out what it does
COMMAND_KEYWORDS.put("test", "run rest modules");
COMMAND_KEYWORDS.put("modules", "show imported modules");// TODO: figure out what it does
COMMAND_KEYWORDS.put("clear", "clear evaluator");// TODO: figure out what it does
COMMAND_KEYWORDS.put("clear", "clear repl screen");
}

private final NavigableMap<String, String> setOptions;
Expand Down
11 changes: 10 additions & 1 deletion src/org/rascalmpl/semantics/dynamic/ShellCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ public Clear(ISourceLocation __param1, IConstructor tree) {

@Override
public Result<IValue> interpret(IEvaluator<Result<IValue>> __eval) {
return null;
IRascalMonitor monitor = __eval.getMonitor();

if (monitor instanceof IDEServices) {
IDEServices services = (IDEServices) monitor;
services.clearRepl();
}
else {
__eval.getStdErr().println("The current Rascal execution environment does not know how to clear the REPL.");
}
return org.rascalmpl.interpreter.result.ResultFactory.nothing();
}

}
Expand Down
5 changes: 3 additions & 2 deletions src/org/rascalmpl/shell/RascalShell2.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.jline.terminal.TerminalBuilder;
import org.jline.utils.OSUtils;
import org.jline.utils.InfoCmp.Capability;
import org.rascalmpl.ideservices.BasicIDEServices;
import org.rascalmpl.ideservices.IDEServices;
import org.rascalmpl.interpreter.Evaluator;
Expand Down Expand Up @@ -55,13 +56,13 @@ public static void main(String[] args) throws IOException {

var repl = new BaseREPL2(new RascalReplServices((t) -> {
var monitor = new TerminalProgressBarMonitor(term);
IDEServices services = new BasicIDEServices(term.writer(), monitor);
DavyLandman marked this conversation as resolved.
Show resolved Hide resolved
IDEServices services = new BasicIDEServices(term.writer(), monitor, () -> term.puts(Capability.clear_screen));


GlobalEnvironment heap = new GlobalEnvironment();
ModuleEnvironment root = heap.addModule(new ModuleEnvironment(ModuleEnvironment.SHELL_MODULE, heap));
IValueFactory vf = ValueFactoryFactory.getValueFactory();
Evaluator evaluator = new Evaluator(vf, term.reader(), new PrintWriter(System.err, true), term.writer(), root, heap, monitor);
Evaluator evaluator = new Evaluator(vf, term.reader(), new PrintWriter(System.err, true), term.writer(), root, heap, services);
evaluator.addRascalSearchPathContributor(StandardLibraryContributor.getInstance());
return evaluator;
}), term);
Expand Down