diff --git a/pom.xml b/pom.xml index f892531db7a..4e1c6aca3b6 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.rascalmpl rascal - 0.40.13-SNAPSHOT + 0.40.15-SNAPSHOT jar @@ -32,7 +32,7 @@ org.rascalmpl.shell.RascalShell 2 11 - 0.28.6 + 0.28.8 diff --git a/src/org/rascalmpl/interpreter/utils/IResourceLocationProvider.java b/src/org/rascalmpl/interpreter/utils/IResourceLocationProvider.java index 4721bbb4391..36b5521f36c 100644 --- a/src/org/rascalmpl/interpreter/utils/IResourceLocationProvider.java +++ b/src/org/rascalmpl/interpreter/utils/IResourceLocationProvider.java @@ -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 findResources(String fileName); } diff --git a/src/org/rascalmpl/interpreter/utils/JavaBridge.java b/src/org/rascalmpl/interpreter/utils/JavaBridge.java index 201703578f1..71362ef5f39 100644 --- a/src/org/rascalmpl/interpreter/utils/JavaBridge.java +++ b/src/org/rascalmpl/interpreter/utils/JavaBridge.java @@ -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; @@ -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)) { diff --git a/src/org/rascalmpl/library/Content.rsc b/src/org/rascalmpl/library/Content.rsc index 28be88bbe94..54600a5021f 100644 --- a/src/org/rascalmpl/library/Content.rsc +++ b/src/org/rascalmpl/library/Content.rsc @@ -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. diff --git a/src/org/rascalmpl/library/Set.rsc b/src/org/rascalmpl/library/Set.rsc index 10e0f819cdd..729b96ea4c0 100644 --- a/src/org/rascalmpl/library/Set.rsc +++ b/src/org/rascalmpl/library/Set.rsc @@ -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`. } @@ -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); diff --git a/src/org/rascalmpl/library/analysis/diff/edits/TextEdits.rsc b/src/org/rascalmpl/library/analysis/diff/edits/TextEdits.rsc index 55cf05f948b..8721673cd72 100644 --- a/src/org/rascalmpl/library/analysis/diff/edits/TextEdits.rsc +++ b/src/org/rascalmpl/library/analysis/diff/edits/TextEdits.rsc @@ -1,5 +1,33 @@ +@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) @@ -7,9 +35,28 @@ data DocumentEdit | 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), ""); +@synopsis{Inserting after a given range.} +TextEdit insertAfter(loc range, str insertion, str separator=" ") + = replace(range.top(range.offset + range.length, 0), ""); + diff --git a/src/org/rascalmpl/library/util/IDEServices.rsc b/src/org/rascalmpl/library/util/IDEServices.rsc index 32950e82142..2de6d3fac2a 100644 --- a/src/org/rascalmpl/library/util/IDEServices.rsc +++ b/src/org/rascalmpl/library/util/IDEServices.rsc @@ -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 = "", int viewColumn=1); @@ -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();