Skip to content

Commit

Permalink
Merge branch 'main' into feat/error-recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
PieterOlivier committed Nov 5, 2024
2 parents 37ce549 + 417887b commit 415773f
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.rascalmpl</groupId>
<artifactId>rascal</artifactId>
<version>0.40.13-SNAPSHOT</version>
<version>0.40.15-SNAPSHOT</version>
<packaging>jar</packaging>

<scm>
Expand Down Expand Up @@ -32,7 +32,7 @@
<exec.mainClass>org.rascalmpl.shell.RascalShell</exec.mainClass>
<rascal.test.memory>2</rascal.test.memory>
<maven.compiler.release>11</maven.compiler.release>
<rascal-maven.version>0.28.6</rascal-maven.version>
<rascal-maven.version>0.28.8</rascal-maven.version>
</properties>

<licenses>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

import io.usethesource.vallang.ISourceLocation;

/**
* This is a injected configuration parameter of a Rascal run-time
* environment like IRascalMonitor and IDEServices. The goal is
* to find all the file names that have the given `fileName` in
* the current run-time environment. For compiled Rascal this would
* be ClassLoader.findResources, while for the interpreter it is
* typically a search through all the roots of the source folders.
*/
public interface IResourceLocationProvider {
Set<ISourceLocation> findResources(String fileName);
}
3 changes: 2 additions & 1 deletion src/org/rascalmpl/interpreter/utils/JavaBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.rascalmpl.exceptions.JavaCompilation;
import org.rascalmpl.exceptions.JavaMethodLink;
import org.rascalmpl.exceptions.RuntimeExceptionFactory;
import org.rascalmpl.ideservices.BasicIDEServices;
import org.rascalmpl.ideservices.IDEServices;
import org.rascalmpl.interpreter.Configuration;
import org.rascalmpl.interpreter.IEvaluator;
Expand Down Expand Up @@ -445,7 +446,7 @@ else if (formals[i].isAssignableFrom(IDEServices.class)) {
args[i] = (IDEServices) monitor;
}
else {
throw new IllegalArgumentException("no IDE services are available in this environment");
args[i] = new BasicIDEServices(err, monitor);
}
}
else if (formals[i].isAssignableFrom(IResourceLocationProvider.class)) {
Expand Down
2 changes: 1 addition & 1 deletion src/org/rascalmpl/library/Content.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Content


@synopsis{Content wraps the HTTP Request/Response API to support interactive visualization types
on the terminal ((RascalShell)).}
on the terminal.}
@description{
Values wrapped in a `Content` wrapper will be displayed by interactive
Rascal applications such as the IDE, the REPL terminal and the documentation pages.
Expand Down
8 changes: 2 additions & 6 deletions src/org/rascalmpl/library/Set.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ power1({1,2,3,4});
}
public set[set[&T]] power1(set[&T] st) = power(st) - {{}};

@synopsis{Apply a function to successive elements of a set and combine the results (__deprecated__).}
@synopsis{Apply a function to successive elements of a set and combine the results.}
@description{
Apply the function `fn` to successive elements of set `s` starting with `unit`.
}
Expand All @@ -229,11 +229,7 @@ int add(int x, int y) { return x + y; }
reducer({10, 20, 30, 40}, add, 0);
```
}
@pitfalls{
:::warning
This function is *deprecated*, use a reducer expression instead, such as `(init | fn(it,e) | e <- st)`.
:::
}
@deprecated{Use a reducer expression instead, such as `(init | fn(it,e) | e <- st)`.}
public &T reducer(set[&T] st, &T (&T,&T) fn, &T unit) =
(unit | fn(it,elm) | elm <- st);

Expand Down
53 changes: 50 additions & 3 deletions src/org/rascalmpl/library/analysis/diff/edits/TextEdits.rsc
Original file line number Diff line number Diff line change
@@ -1,15 +1,62 @@
@license{
Copyright (c) 2022, NWO-I Centrum Wiskunde & Informatica (CWI)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
}
@synopsis{Intermediate representation for file creation, removal and changing, including textual (string) rewriting.}
@description{
((DocumentEdit))s can be produced by source-to-source transformation tools, and then executed
via ((executeDocumentEdits)) in the REPL or ((applyDocumentsEdits)) by the IDE.
}
@benefits{
* Document edits can be attached to ((data:CodeAction))s and error ((util::IDEServices-Message))s, to achieve interactive
source code rewriting utilities.
* Document edits can be tested via ((executeDocumentEdits))
* Document edits can be "high fidelity", avoiding unnecessary damage to a source text.
}
@pitfalls{
* Code edits depend on a specific state of the source file that may be transient while editing. Use the ((CodeAction)) interface
to avoid racing for the state of the source file.
}
module analysis::diff::edits::TextEdits

@synopsis{File changing operations}
data DocumentEdit
= removed(loc file)
| created(loc file)
| renamed(loc from, loc to)
| changed(loc file, list[TextEdit] edits)
;

@synopsis{Shorthand for file changes.}
DocumentEdit changed(list[TextEdit] edits:[replace(loc l, str _), *_])
= changed(l.top, edits);

@synopsis{String rewriting operations}
@description{
The core operation is to replace a substring with another.
The replace operator uses a `loc` value to point to a range inside a string,
and a `str` as its replacement.
}
data TextEdit
= replace(loc range, str replacement)
;
= replace(loc range, str replacement);

@synopsis{Deletion is replacement with an empty string.}
TextEdit delete(loc range)
= replace(range, "");

TextEdit delete(loc range) = replace(range, "");
@synopsis{Inserting before a given range.}
TextEdit insertBefore(loc range, str insertion, str separator=" ")
= replace(range.top(range.offset, 0), "<insertion><separator>");

@synopsis{Inserting after a given range.}
TextEdit insertAfter(loc range, str insertion, str separator=" ")
= replace(range.top(range.offset + range.length, 0), "<separator><insertion>");

26 changes: 25 additions & 1 deletion src/org/rascalmpl/library/util/IDEServices.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ extend analysis::diff::edits::TextEdits;
extend Content;
extend Message;


@synopsis{Open a browser for a given location.}
@javaClass{org.rascalmpl.library.util.IDEServicesLibrary}
java void browse(loc uri, str title = "<uri>", int viewColumn=1);
Expand Down Expand Up @@ -45,3 +44,28 @@ public java void registerDiagnostics(list[Message] messages);

@javaClass{org.rascalmpl.library.util.IDEServicesLibrary}
public java void unregisterDiagnostics(list[loc] resources);

@synopsis{Fixes are an extension to error messages that allow for interactive code fixes in the IDE.}
@description{
This definition adds lists of ((CodeAction))s as optional fields to any message. In collaboration
with a language server, these messages then lead to interactive quick fixes in IDEs.
}
data Message(list[CodeAction] fixes = []);

@synopsis{Code actions bundle synchronous text edits and command execution with a title for the menu option.}
@description{
For any action instance, the IDE will:
* show a menu option with the given title.
* if the title is selected, then the (optional) edits will be executed first
* and then the (optional) command is executed via the `execution` service of the language service protocol.
}
data CodeAction
= action(list[DocumentEdit] edits = [], Command command = noop(), str title = command.title);

@synopsis{Commands are an open data-type for describing interactive functions that may be attached to CodeActions.}
@description{
Commands are simply immutable constructors with parameters. To use a command you can attach it to a ((module:Message))
via a ((CodeAction)), and then have it executed by the respective language server.
}
data Command(str title="")
= noop();

0 comments on commit 415773f

Please sign in to comment.