From 1b0e6ce76f284070eec2c0c3f820c33b57ba3fcd Mon Sep 17 00:00:00 2001 From: Pieter Olivier Date: Thu, 25 Sep 2025 13:17:37 +0200 Subject: [PATCH 1/2] Started working on better documentation of error recovery support for DSLs --- .../main/rascal/library/demo/lang/pico/LanguageServer.rsc | 5 +++++ rascal-lsp/src/main/rascal/library/util/LanguageServer.rsc | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/rascal-lsp/src/main/rascal/library/demo/lang/pico/LanguageServer.rsc b/rascal-lsp/src/main/rascal/library/demo/lang/pico/LanguageServer.rsc index 1ec7af63b..b2976d1f0 100644 --- a/rascal-lsp/src/main/rascal/library/demo/lang/pico/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/library/demo/lang/pico/LanguageServer.rsc @@ -234,6 +234,11 @@ Register the Pico language and the contributions that supply the IDE with featur ((registerLanguage)) is called twice here: 1. first for fast and cheap contributions 2. asynchronously for the full monty that loads slower + +The `errorRecovery` parameter can be set to `true` to enable error recovery in the parser. +When enabled, all the contributions in this file will mostly work when parse errors are +present in the input because the contributions are written to be robust +in the presence of error trees. See ((util::LanguageServer::LanguageServer)) for more details. } @benefits{ * You can run each contribution on an example in the terminal to test it first. diff --git a/rascal-lsp/src/main/rascal/library/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/library/util/LanguageServer.rsc index 2716255f5..d7b1c2abe 100644 --- a/rascal-lsp/src/main/rascal/library/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/library/util/LanguageServer.rsc @@ -182,6 +182,11 @@ interpreter lock will make the editor services less responsive. syntax highlighting can update their grammars and explicitly opt-out of the special case by passing `usesSpecialCaseHighlighting = false` when registering the ((parsing)) service. + * You can enable error recovery in the parser like by setting `allowRecovery` to `true`: `parser(#start[Program], allowRecovery=true)`. +With error recovery enabled "hard" parse errors can still occur but that will be rare. In most cases parsing with error recovery enabled +will produce a parse tree with error nodes. Syntax highlighting will still work on such trees. Note that any contributions that you add must be +able to handle such error trees or unexpected things will happen like strange results and crashes. More information on error recovery and error trees +can be found in ((ParseTree::Production)), ((ParseTree::parser)), and ((util::ParseErrorRecovery)). * The ((analysis)) service indexes a file as a ((Summary)), offering precomputed relations for looking up hover documentation, definition with uses, references to declarations, implementations of types and compiler errors and warnings. * ((analysis)) focuses on their own file, but may reuse cached or stored indices from other files. From 3f7b7cd15bc15b8942fff919118f756d35489c82 Mon Sep 17 00:00:00 2001 From: Pieter Olivier Date: Tue, 28 Oct 2025 12:05:50 +0100 Subject: [PATCH 2/2] Fixed broken concept link --- .../src/main/rascal/library/demo/lang/pico/LanguageServer.rsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rascal-lsp/src/main/rascal/library/demo/lang/pico/LanguageServer.rsc b/rascal-lsp/src/main/rascal/library/demo/lang/pico/LanguageServer.rsc index b2976d1f0..fc3aab312 100644 --- a/rascal-lsp/src/main/rascal/library/demo/lang/pico/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/library/demo/lang/pico/LanguageServer.rsc @@ -238,7 +238,7 @@ Register the Pico language and the contributions that supply the IDE with featur The `errorRecovery` parameter can be set to `true` to enable error recovery in the parser. When enabled, all the contributions in this file will mostly work when parse errors are present in the input because the contributions are written to be robust -in the presence of error trees. See ((util::LanguageServer::LanguageServer)) for more details. +in the presence of error trees. See ((util::LanguageServer)) for more details. } @benefits{ * You can run each contribution on an example in the terminal to test it first.