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

code actions for dsls #402

Merged
merged 88 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
a7c55f7
added release notes symlink
jurgenvinju Feb 9, 2024
6c4c927
added first part of experimental CodeActionContributor
jurgenvinju Jul 1, 2024
41234a2
added beginning of quickfix via Message(Command quickfix=...)
jurgenvinju Jul 1, 2024
e6a0048
implemented codeActions LSP protocol, and also made sure that Diagnos…
jurgenvinju Jul 2, 2024
2e8287f
several fixes and more documentation
jurgenvinju Jul 3, 2024
9dfc1b0
working code for both diagnostic quickfixes and other code actions
jurgenvinju Jul 3, 2024
f017942
cleaning up
jurgenvinju Jul 4, 2024
b04466e
added utility to recover offsets from line and column
jurgenvinju Jul 4, 2024
1b507a1
use better offset computation to find actions
jurgenvinju Jul 4, 2024
19d1ef6
compilation errors
jurgenvinju Jul 4, 2024
2891649
fixed off-by-one
jurgenvinju Jul 4, 2024
8b2d52a
cleanup
jurgenvinju Jul 5, 2024
8d54756
rename
jurgenvinju Jul 5, 2024
b2a4c7a
comments
jurgenvinju Jul 5, 2024
b77d621
better handling of user exceptions
jurgenvinju Jul 5, 2024
291fb4d
experiment with easier interface for code action generation
jurgenvinju Jul 5, 2024
9678263
bug fixes
jurgenvinju Jul 5, 2024
8e575c2
comments fixed
jurgenvinju Jul 5, 2024
5ea4b32
fixed debug message
jurgenvinju Jul 5, 2024
7290cca
added test for quickfix
jurgenvinju Jul 8, 2024
62664f4
added uitests folder to .gitignore
jurgenvinju Jul 8, 2024
a9e5bf4
better tests but not working yet
jurgenvinju Jul 8, 2024
3bb07cf
fixed syntax errors
jurgenvinju Jul 8, 2024
a4b6624
should be hasErrorSquiqly
jurgenvinju Jul 8, 2024
fb57756
wrong line edited
jurgenvinju Jul 8, 2024
82d18b1
made more clear actions are never joined on the main thread by reffac…
jurgenvinju Jul 16, 2024
fc5176f
fixed broken default
jurgenvinju Jul 16, 2024
d4059c6
Lifted commands in quickfixes and codeActionsProviders to real
jurgenvinju Aug 29, 2024
36d3fea
documentation
jurgenvinju Aug 29, 2024
ea5098b
added release notes symlink
jurgenvinju Feb 9, 2024
1e1ad3a
manual merging here
jurgenvinju Aug 29, 2024
da196f1
guard against empty amb cluster per @sungshik suggestion
jurgenvinju Aug 29, 2024
c699404
factored clone as per @sungshik suggestion
jurgenvinju Aug 29, 2024
f40fd17
removed updates to launch.json
jurgenvinju Aug 29, 2024
3710c11
removed unnecessary null check as per @davylandman suggestion
jurgenvinju Aug 29, 2024
dbda191
fixed mistake, thanks @davylandman
jurgenvinju Aug 29, 2024
35c55a6
fixed error
jurgenvinju Aug 29, 2024
b301801
fixed codeactionkind name issue
jurgenvinju Aug 29, 2024
1315ebd
fixed compilation errors
jurgenvinju Aug 29, 2024
3109b72
removed dead import
jurgenvinju Aug 29, 2024
52e1232
removed superfluous release notes
jurgenvinju Aug 30, 2024
f47cc0d
enabled compiler again
jurgenvinju Aug 30, 2024
d07cd46
fixed fawlty import via @davylandman
jurgenvinju Aug 31, 2024
f1c0a2e
fixed links
jurgenvinju Sep 2, 2024
30b13c6
working on PR review by @davylandman; crossing the ts
jurgenvinju Sep 6, 2024
a7bc8fd
bracket
jurgenvinju Sep 6, 2024
8d20212
fixed name of action contributor in demo
jurgenvinju Sep 7, 2024
6428667
fixed error handling for missing command executors
jurgenvinju Sep 7, 2024
1973d56
improved the quickfix test
jurgenvinju Sep 7, 2024
16e2b94
documented commands for running ui tests on the commandline. Note tha…
jurgenvinju Sep 7, 2024
4fb1989
fixed compilation warning
jurgenvinju Sep 7, 2024
697cc1e
fixed channel name for failing tests
jurgenvinju Sep 7, 2024
d38e7ee
fixed off-by-one on code actions
jurgenvinju Sep 10, 2024
840bf20
fixes in output terminal identifiers
jurgenvinju Sep 10, 2024
ecbdf2f
finished first quickfix test
jurgenvinju Sep 19, 2024
ca6b6cf
omit to strong cleaning of environment while testing
jurgenvinju Sep 19, 2024
0af793c
rewrote undeclared variable quickfix demo to direct edits instead of …
jurgenvinju Sep 19, 2024
21a6a9d
Merge branch 'main' into code-actions-for-dsls
jurgenvinju Sep 19, 2024
fba774e
typos
jurgenvinju Sep 19, 2024
e957041
fixed trailing whitespace
jurgenvinju Sep 19, 2024
d9d396d
remove trailing spaces
jurgenvinju Sep 19, 2024
eb6fb74
Rewrote the test to use driver await to try and get the code-action
DavyLandman Sep 19, 2024
915ac40
fixed several issues identified by @davylandman
jurgenvinju Sep 19, 2024
2e71d6a
cleaning up off-by-ones
jurgenvinju Sep 19, 2024
12e9b6c
trimmed trailig whitespace
jurgenvinju Sep 19, 2024
35d1b70
added license
jurgenvinju Sep 19, 2024
604599e
fixed log name
jurgenvinju Sep 19, 2024
82da5f1
Debugging why the driver wait fails
DavyLandman Sep 20, 2024
3c9d5f3
Proper debug print
DavyLandman Sep 20, 2024
2165849
fixed documentation errors
jurgenvinju Sep 19, 2024
35b17a8
fixed more doc links
jurgenvinju Sep 20, 2024
b588610
fixed another doc link
jurgenvinju Sep 20, 2024
3f10cf9
fixed error with error log
jurgenvinju Sep 20, 2024
6916a92
improved quickfix test with more lower level CSS selectors. Not worki…
jurgenvinju Sep 20, 2024
14e49f4
re-enabled other dsl tests
jurgenvinju Sep 20, 2024
012f989
rascal default for action kind now also implemented in java; this ena…
jurgenvinju Sep 20, 2024
03dafd6
introduced looking for shadow root. have not found it yet but that is…
jurgenvinju Sep 21, 2024
7539384
current state of test
jurgenvinju Sep 21, 2024
2bdf8fe
almost there
jurgenvinju Sep 21, 2024
f7b2e8b
Improved the logic of finding elements
DavyLandman Sep 22, 2024
c775962
Fixed accidental committed code
DavyLandman Sep 22, 2024
c7e4917
Got the code action to trigger
DavyLandman Sep 26, 2024
823cc0a
uncommented the other tests and finished comments
jurgenvinju Sep 26, 2024
6d1fbf4
Tried fixing the race around the change to a option
DavyLandman Sep 26, 2024
a2afd55
Undoing some changes that reduce the diff to main
DavyLandman Sep 27, 2024
c949cf1
Merge remote-tracking branch 'origin/main' into code-actions-for-dsls
DavyLandman Sep 27, 2024
d0a4d08
Reduced some of the quality issues spotted by sonarcloud
DavyLandman Sep 27, 2024
f80d525
Merge branch 'main' into code-actions-for-dsls
DavyLandman Sep 27, 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
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ done

rm -f rascal-lsp/target/*.jar

(cd rascal-lsp && mvn $clean package $extra_flags )
(cd rascal-lsp && mvn $clean package -Drascal.monitor.batch $extra_flags )
(cd rascal-vscode-extension && npm run lsp4j:package )

Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ public CompletableFuture<Two<String, URI[]>[]> supplyPathConfig(PathConfigParame
return CompletableFuture.supplyAsync(() -> {
try {
var pcfg = PathConfig.fromSourceProjectMemberRascalManifest(projectFolder.getLocation(), projectFolder.getMode().mapConfigMode());
@SuppressWarnings("unchecked")
Two<String, URI[]>[] result = new Two[4];
result[0] = new Two<>("Sources", toURIArray(pcfg.getSrcs()));
result[1] = new Two<>("Libraries", toURIArray(pcfg.getLibs()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ public interface ILanguageContributions {
public InterruptibleFuture<IConstructor> build(ISourceLocation loc, ITree input);
public InterruptibleFuture<ISet> lenses(ITree input);
public InterruptibleFuture<@Nullable IValue> executeCommand(String command);
public CompletableFuture<IList> parseCodeActions(String command);
public InterruptibleFuture<IList> inlayHint(@Nullable ITree input);
public InterruptibleFuture<ISet> documentation(ISourceLocation loc, ITree input, ITree cursor);
public InterruptibleFuture<ISet> definitions(ISourceLocation loc, ITree input, ITree cursor);
public InterruptibleFuture<ISet> references(ISourceLocation loc, ITree input, ITree cursor);
public InterruptibleFuture<ISet> implementations(ISourceLocation loc, ITree input, ITree cursor);
public InterruptibleFuture<IList> codeActions(IList focus);

public CompletableFuture<Boolean> hasAnalyzer();
public CompletableFuture<Boolean> hasBuilder();
Expand All @@ -67,6 +69,7 @@ public interface ILanguageContributions {
public CompletableFuture<Boolean> hasDefiner();
public CompletableFuture<Boolean> hasReferrer();
public CompletableFuture<Boolean> hasImplementer();
public CompletableFuture<Boolean> hasCodeActionsContributor();

public CompletableFuture<SummaryConfig> getAnalyzerSummaryConfig();
public CompletableFuture<SummaryConfig> getBuilderSummaryConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.exceptions.FactTypeUseException;
import io.usethesource.vallang.io.StandardTextReader;
import io.usethesource.vallang.type.TypeFactory;
import io.usethesource.vallang.type.TypeStore;

public class InterpretedLanguageContributions implements ILanguageContributions {
Expand All @@ -84,6 +85,7 @@ public class InterpretedLanguageContributions implements ILanguageContributions
private final CompletableFuture<@Nullable IFunction> definer;
private final CompletableFuture<@Nullable IFunction> referrer;
private final CompletableFuture<@Nullable IFunction> implementer;
private final CompletableFuture<@Nullable IFunction> codeActionContributor;

private final CompletableFuture<Boolean> hasOutliner;
private final CompletableFuture<Boolean> hasAnalyzer;
Expand All @@ -95,6 +97,7 @@ public class InterpretedLanguageContributions implements ILanguageContributions
private final CompletableFuture<Boolean> hasDefiner;
private final CompletableFuture<Boolean> hasReferrer;
private final CompletableFuture<Boolean> hasImplementer;
private final CompletableFuture<Boolean> hasCodeActionContributor;

private final CompletableFuture<SummaryConfig> analyzerSummaryConfig;
private final CompletableFuture<SummaryConfig> builderSummaryConfig;
Expand Down Expand Up @@ -130,6 +133,7 @@ public InterpretedLanguageContributions(LanguageParameter lang, IBaseTextDocumen
this.definer = getFunctionFor(contributions, LanguageContributions.DEFINER);
this.referrer = getFunctionFor(contributions, LanguageContributions.REFERRER);
this.implementer = getFunctionFor(contributions, LanguageContributions.IMPLEMENTER);
this.codeActionContributor = getFunctionFor(contributions, LanguageContributions.CODE_ACTION_CONTRIBUTOR);

// assign boolean properties once instead of wasting futures all the time
this.hasOutliner = nonNull(this.outliner);
Expand All @@ -142,14 +146,15 @@ public InterpretedLanguageContributions(LanguageParameter lang, IBaseTextDocumen
this.hasDefiner = nonNull(this.definer);
this.hasReferrer = nonNull(this.referrer);
this.hasImplementer = nonNull(this.implementer);
this.hasCodeActionContributor = nonNull(this.codeActionContributor);

this.analyzerSummaryConfig = scheduledSummaryConfig(contributions, LanguageContributions.ANALYZER);
this.builderSummaryConfig = scheduledSummaryConfig(contributions, LanguageContributions.BUILDER);
this.ondemandSummaryConfig = ondemandSummaryConfig(contributions);

} catch (IOException e1) {
logger.catching(e1);
throw new RuntimeException(e1);
throw new IllegalArgumentException(e1);
}
}

Expand Down Expand Up @@ -207,12 +212,28 @@ private static ISet loadContributions(Evaluator eval, LanguageParameter lang) {
.getValue();
}

@Override
public CompletableFuture<IList> parseCodeActions(String command) {
return store.thenApply(commandStore -> {
try {
var TF = TypeFactory.getInstance();
return (IList) new StandardTextReader().read(VF, commandStore, TF.listType(commandStore.lookupAbstractDataType("CodeAction")), new StringReader(command));
} catch (FactTypeUseException | IOException e) {
// this should never happen as long as the Rascal code
// for creating errors is type-correct. So it _might_ happen
// when running the interpreter on broken code.
throw new IllegalArgumentException("The command could not be parsed", e);
}
});
}

private CompletableFuture<IConstructor> parseCommand(String command) {
return store.thenApply(commandStore -> {
try {
return (IConstructor) new StandardTextReader().read(VF, commandStore, commandStore.lookupAbstractDataType("Command"), new StringReader(command));
} catch (FactTypeUseException | IOException e) {
throw new RuntimeException(e);
logger.catching(e);
throw new IllegalArgumentException("The command could not be parsed", e);
}
});
}
Expand Down Expand Up @@ -287,12 +308,19 @@ public InterruptibleFuture<ISet> implementations(ISourceLocation loc, ITree inpu
debug(LanguageContributions.IMPLEMENTER, TreeAdapter.getLocation(cursor));
return execFunction(LanguageContributions.IMPLEMENTER, implementer, VF.set(), loc, input, cursor);
}

@Override
public InterruptibleFuture<ISet> references(ISourceLocation loc, ITree input, ITree cursor) {
debug(LanguageContributions.REFERRER, TreeAdapter.getLocation(cursor));
return execFunction(LanguageContributions.REFERRER, referrer, VF.set(), loc, input, cursor);
}

@Override
public InterruptibleFuture<IList> codeActions(IList focus) {
debug(LanguageContributions.CODE_ACTION_CONTRIBUTOR, "(focus list has " + focus.length() + " elements)");
return execFunction(LanguageContributions.CODE_ACTION_CONTRIBUTOR, codeActionContributor, VF.list(), focus);
}

private void debug(String name, Object param) {
logger.debug("{}({})", name, param);
}
Expand Down Expand Up @@ -341,6 +369,11 @@ public CompletableFuture<Boolean> hasOutliner() {
return hasOutliner;
}

@Override
public CompletableFuture<Boolean> hasCodeActionsContributor() {
return hasCodeActionContributor;
}

@Override
public CompletableFuture<Boolean> hasAnalyzer() {
return hasAnalyzer;
Expand Down Expand Up @@ -370,8 +403,26 @@ public CompletableFuture<SummaryConfig> getOndemandSummaryConfig() {
public InterruptibleFuture<@Nullable IValue> executeCommand(String command) {
logger.debug("executeCommand({}...) (full command value in TRACE level)", () -> command.substring(0, Math.min(10, command.length())));
logger.trace("Full command: {}", command);
return InterruptibleFuture.flatten(parseCommand(command).thenCombine(commandExecutor,
(cons, func) -> EvaluatorUtil.<@Nullable IValue>runEvaluator("executeCommand", eval, ev -> func.call(cons), null, exec, true, client)

return InterruptibleFuture.flatten(parseCommand(command).thenCombine(
commandExecutor,
(cons, func) -> {

if (func == null) {
logger.warn("Command is being executed without a registered command executor; for language {}", name);
throw new IllegalStateException("No command executor registered for " + name);
}

return EvaluatorUtil.<@Nullable IValue>runEvaluator(
jurgenvinju marked this conversation as resolved.
Show resolved Hide resolved
"executeCommand",
eval,
ev -> func.call(cons),
null,
exec,
true,
client
);
}
), exec);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ private static final <T> CompletableFuture<T> failedInitialization() {
private volatile CompletableFuture<ILanguageContributions> documenter = failedInitialization();
private volatile CompletableFuture<ILanguageContributions> referrer = failedInitialization();
private volatile CompletableFuture<ILanguageContributions> implementer = failedInitialization();
private volatile CompletableFuture<ILanguageContributions> codeActionContributor = failedInitialization();

private volatile CompletableFuture<Boolean> hasDocumenter = failedInitialization();
private volatile CompletableFuture<Boolean> hasDefiner = failedInitialization();
Expand All @@ -74,6 +75,7 @@ private static final <T> CompletableFuture<T> failedInitialization() {
private volatile CompletableFuture<Boolean> hasLensDetector = failedInitialization();
private volatile CompletableFuture<Boolean> hasCommandExecutor = failedInitialization();
private volatile CompletableFuture<Boolean> hasInlayHinter = failedInitialization();
private volatile CompletableFuture<Boolean> hasCodeActionContributor = failedInitialization();

private volatile CompletableFuture<SummaryConfig> analyzerSummaryConfig;
private volatile CompletableFuture<SummaryConfig> builderSummaryConfig;
Expand Down Expand Up @@ -143,6 +145,7 @@ private synchronized void calculateRouting() {
documenter = findFirstOrDefault(ILanguageContributions::hasDocumenter);
referrer = findFirstOrDefault(ILanguageContributions::hasReferrer);
implementer = findFirstOrDefault(ILanguageContributions::hasImplementer);
codeActionContributor = findFirstOrDefault(ILanguageContributions::hasCodeActionsContributor);

hasDocumenter = anyTrue(ILanguageContributions::hasDocumenter);
hasDefiner = anyTrue(ILanguageContributions::hasDefiner);
Expand Down Expand Up @@ -253,6 +256,11 @@ public InterruptibleFuture<ISet> lenses(ITree input) {
return flatten(commandExecutor, c -> c.executeCommand(command));
}

@Override
public CompletableFuture<IList> parseCodeActions(String command) {
return commandExecutor.thenApply(c -> c.parseCodeActions(command)).thenCompose(Function.identity());
}

@Override
public InterruptibleFuture<IList> inlayHint(@Nullable ITree input) {
return flatten(inlayHinter, c -> c.inlayHint(input));
Expand All @@ -278,6 +286,15 @@ public InterruptibleFuture<ISet> implementations(ISourceLocation loc, ITree inpu
return flatten(implementer, c -> c.implementations(loc, input, cursor));
}

@Override
public InterruptibleFuture<IList> codeActions(IList focus) {
return flatten(codeActionContributor, c -> c.codeActions(focus));
}

@Override
public CompletableFuture<Boolean> hasCodeActionsContributor() {
return hasCodeActionContributor;
}

@Override
public CompletableFuture<Boolean> hasDocumenter() {
Expand Down
Loading
Loading