From 7791a571aa209c050afab9cdd192f9ed634bfe39 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Fri, 11 Oct 2024 09:49:37 +0200 Subject: [PATCH 01/57] renamed all language services towards consistency. All verbs or all nouns did not work. Instead these are all proper adjectives to the word "service". E.g. "parsing service" and "references service" and "build service" --- .../src/main/rascal/util/LanguageServer.rsc | 95 +++++++++++++------ 1 file changed, 68 insertions(+), 27 deletions(-) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 22c6deb2f..2589c1433 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -260,34 +260,35 @@ alias FocusImplementer = set[loc] (Focus _focus); @synopsis{Each kind of service contibutes the implementation of one (or several) IDE features.} @description{ Each LanguageService provides one aspect of definining the language server protocol. -* ((parser)) maps source code to a parse tree and indexes each part based on offset and length -* ((analyzer)) indexes a file as a ((Summary)), offering precomputed relations for looking up +* The ((parsing)) service maps source code to a parse tree and indexes each part based on offset and length +* The ((analysis)) service indexes a file as a ((Summary)), offering precomputed relations for looking up documentation, definitions, references, implementations and compiler errors and warnings. - * ((analyzer))s focus on their own file, but may reuse cached or stored indices from other files. - * ((analyzer))s have to be quick since they run in an interactive editor setting. - * ((analyzer))s may store previous results (in memory) for incremental updates. - * ((analyzer))s are triggered during typing, in a short typing pause. -* ((builder)) is similar to an `analyzer`, but it may perform computation-heavier additional checks. - * ((builder))s typically run whole-program analyses and compilation steps. - * ((builder))s have side-effects, they store generated code or code indices for future usage by the next build step, or by the next analysis step. - * ((builder))s are triggered on _save-file_ events; they _push_ information to an internal cache. - * Warning: ((builder))s are _not_ triggered when a file changes on disk outside of VS Code; instead, this results in a change event (not a save event), which triggers the ((analyzer)). + * ((analysis)) focuses on their own file, but may reuse cached or stored indices from other files. + * ((analysis)) has to be quick since they run in an interactive editor setting. + * ((analysis)) may store previous results (in memory) for incremental updates. + * ((analysis)) is triggered during typing, in a short typing pause. +* The ((build)) service is similar to an `analyzer`, but it may perform computation-heavier additional checks. + * ((build))s typically run whole-program analyses and compilation steps. + * ((build))s have side-effects, they store generated code or code indices for future usage by the next build step, or by the next analysis step. + * ((build))s are triggered on _save-file_ events; they _push_ information to an internal cache. + * Warning: ((build))s are _not_ triggered when a file changes on disk outside of VS Code; instead, this results in a change event (not a save event), which triggers the ((analyzer)). * the following contributions are _on-demand_ (pull) versions of information also provided by the analyzer and builder summaries. - * a ((documenter)) is a fast and location specific version of the `documentation` relation in a ((Summary)). - * a ((definer)) is a fast and location specific version of the `definitions` relation in a ((Summary)). - * a ((referrer)) is a fast and location specific version of the `references` relation in a ((Summary)). - * an ((implementer)) is a fast and location specific version of the `implementations` relation in a ((Summary)). -* ((outliner)) maps a source file to a pretty hierarchy for visualization in the "outline" view -* ((lenses)) discovers places to add "lenses" (little views embedded in the editor on a separate line) and connects commands to execute to each lense -* ((inlayHinter)) discovers plances to add "inlays" (little views embedded in the editor on the same line). Unlike ((lenses)) inlays do not offer command execution. -* ((executor)) executes the commands registered by ((lenses)) and ((inlayHinter))s. + * a ((documentation)) service is a fast and location specific version of the `documentation` relation in a ((Summary)). + * a ((definition)) service is a fast and location specific version of the `definitions` relation in a ((Summary)). + * a ((reference)) service is a fast and location specific version of the `references` relation in a ((Summary)). + * an ((implementation)) service is a fast and location specific version of the `implementations` relation in a ((Summary)). +* The ((outline)) service maps a source file to a pretty hierarchy for visualization in the "outline" view +* The ((lenses)) service discovers places to add "lenses" (little views embedded in the editor on a separate line) and connects commands to execute to each lense +* The ((inlays)) service discovers plances to add "inlays" (little views embedded in the editor on the same line). Unlike ((lenses)) inlays do not offer command execution. +* The ((execution)) service executes the commands registered by ((lenses)) and ((inlayHinter))s. +* The ((actions)) service discovers palces to add "code actions" (little hints in the margin next to where the action is relevant) and connects ((CodeAction))s to execute when the users selects the action from a menu. Many language contributions received a ((Focus)) parameter. This helps to create functionality that is syntax-directed: relevant to the current syntactical constructs under the cursor. } data LanguageService - = parser(Parser parser) - | analyzer(Summarizer summarizer + = parsing(Parser parser) + | analysis(Summarizer summarizer , bool providesDocumentation = true , bool providesDefinitions = true , bool providesReferences = true @@ -297,17 +298,57 @@ data LanguageService , bool providesDefinitions = true , bool providesReferences = true , bool providesImplementations = true) - | outliner(Outliner outliner) + | outline(Outliner outliner) | lenses(LensDetector detector) - | inlayHinter(InlayHinter hinter) - | executor(CommandExecutor executor) - | documenter(FocusDocumenter documenter) - | definer(FocusDefiner definer) - | referrer(FocusReferrer reference) + | inlays(InlayHinter hinter) + | execution(CommandExecutor executor) + | documentation(FocusDocumenter documenter) + | definition(FocusDefiner definer) + | reference(FocusReferrer reference) | implementer(FocusImplementer implementer) | actions(CodeActionContributor actions) ; +@deprecated{Backward compatible with `parsing`} +@synopsis{Construct a `parsing` LanguageService} +LanguageService parser(Parser parser) = parsing(parser); + +@deprecated{Backward compatible with `analysis`} +@synopsis{Construct a `analysis` LanguageService} +LanguageService analyzer(Summarizer summarizer) = analysis(summarizer); + +@deprecated{Backward compatible with `build`} +@synopsis{Construct a `build` LanguageService} +LanguageService builder(Summarizer summarizer) = builder(summarizer); + +@deprecated{Backward compatible with `outline`} +@synopsis{Construct a `build` LanguageService} +LanguageService outliner(Summarizer summarizer) = outline(summarizer); + +@deprecated{Backward compatible with `inlays`} +@synopsis{Construct a `inlays` LanguageService} +LanguageService inlayHinter(InlayHinter hinter) = inlays(hinter); + +@deprecated{Backward compatible with `execution`} +@synopsis{Construct a `execution` LanguageService} +LanguageService executor(CommandExecutor executor) = execution(executor); + +@deprecated{Backward compatible with `documentation`} +@synopsis{Construct a `documentation` LanguageService} +LanguageService documenter(FocusDocumenter documentor) = documentation(documentor); + +@deprecated{Backward compatible with `definition`} +@synopsis{Construct a `definition` LanguageService} +LanguageService definer(FocusDefiner definer) = definition(definer); + +@deprecated{Backward compatible with `reference`} +@synopsis{Construct a `reference` LanguageService} +LanguageService referer(FocusReferrer referer) = reference(referer); + +@deprecated{Backward compatible with `implementation`} +@synopsis{Construct a `implementation` LanguageService} +LanguageService implementer(FocusImplementer implementer) = implementation(implementer); + @deprecated{ This is a backward compatibility layer for the pre-existing ((Documenter)) alias. From 0d862060dac8cda21c62711c528876230ebf064b Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Fri, 11 Oct 2024 11:54:44 +0200 Subject: [PATCH 02/57] made plural/singular consistent --- .../src/main/rascal/util/LanguageServer.rsc | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 2589c1433..289130c4b 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -299,35 +299,43 @@ data LanguageService , bool providesReferences = true , bool providesImplementations = true) | outline(Outliner outliner) - | lenses(LensDetector detector) - | inlays(InlayHinter hinter) + | lense(LensDetector detector) + | inlay(InlayHinter hinter) | execution(CommandExecutor executor) | documentation(FocusDocumenter documenter) | definition(FocusDefiner definer) | reference(FocusReferrer reference) | implementer(FocusImplementer implementer) - | actions(CodeActionContributor actions) + | action(CodeActionContributor actions) ; @deprecated{Backward compatible with `parsing`} @synopsis{Construct a `parsing` LanguageService} LanguageService parser(Parser parser) = parsing(parser); +@deprecated{Backward compatible with `lenses`} +@synopsis{Construct a `lense` LanguageService} +LanguageService lenses(LensDetector detector) = lense(detector); + +@deprecated{Backward compatible with `action`} +@synopsis{Construct a `lense` LanguageService} +LanguageService actios(CodeActionContributor contributor) = action(contributor); + @deprecated{Backward compatible with `analysis`} @synopsis{Construct a `analysis` LanguageService} LanguageService analyzer(Summarizer summarizer) = analysis(summarizer); @deprecated{Backward compatible with `build`} @synopsis{Construct a `build` LanguageService} -LanguageService builder(Summarizer summarizer) = builder(summarizer); +LanguageService builder(Summarizer summarizer) = build(summarizer); @deprecated{Backward compatible with `outline`} @synopsis{Construct a `build` LanguageService} -LanguageService outliner(Summarizer summarizer) = outline(summarizer); +LanguageService outliner(Summarizer summarizer) = LanguageService::outline(summarizer); @deprecated{Backward compatible with `inlays`} @synopsis{Construct a `inlays` LanguageService} -LanguageService inlayHinter(InlayHinter hinter) = inlays(hinter); +LanguageService inlayHinter(InlayHinter hinter) = inlay(hinter); @deprecated{Backward compatible with `execution`} @synopsis{Construct a `execution` LanguageService} From 31e9417ac4de2bc5d5866c502fac4fa5182a0649 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Fri, 11 Oct 2024 11:57:06 +0200 Subject: [PATCH 03/57] added missing renaming --- rascal-lsp/src/main/rascal/util/LanguageServer.rsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 289130c4b..467ab8a37 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -293,7 +293,7 @@ data LanguageService , bool providesDefinitions = true , bool providesReferences = true , bool providesImplementations = true) - | builder(Summarizer summarizer + | build(Summarizer summarizer , bool providesDocumentation = true , bool providesDefinitions = true , bool providesReferences = true From c926ef9a979bd09a19a48e9bcdd96ff374f7a111 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Fri, 11 Oct 2024 12:00:33 +0200 Subject: [PATCH 04/57] fixed errors detected by static checker --- rascal-lsp/src/main/rascal/util/LanguageServer.rsc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 467ab8a37..deb9c7e1e 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -305,7 +305,7 @@ data LanguageService | documentation(FocusDocumenter documenter) | definition(FocusDefiner definer) | reference(FocusReferrer reference) - | implementer(FocusImplementer implementer) + | implementation(FocusImplementer implementer) | action(CodeActionContributor actions) ; @@ -331,7 +331,7 @@ LanguageService builder(Summarizer summarizer) = build(summarizer); @deprecated{Backward compatible with `outline`} @synopsis{Construct a `build` LanguageService} -LanguageService outliner(Summarizer summarizer) = LanguageService::outline(summarizer); +LanguageService outliner(Outliner outliner) = outline(outliner); @deprecated{Backward compatible with `inlays`} @synopsis{Construct a `inlays` LanguageService} @@ -480,7 +480,7 @@ LanguageService implementer(Implementer d) { return implementer(focusAcceptor); } -@deprecated{Please use ((builder)) or ((analyzer))} +@deprecated{Please use ((build)) or ((analysis))} @synopsis{A summarizer collects information for later use in interactive IDE features.} LanguageService summarizer(Summarizer summarizer , bool providesDocumentation = true @@ -488,7 +488,7 @@ LanguageService summarizer(Summarizer summarizer , bool providesReferences = true , bool providesImplementations = true) { println("Summarizers are deprecated. Please use builders (triggered on save) and analyzers (triggered on change) instead."); - return builder(summarizer + return build(summarizer , providesDocumentation = providesDocumentation , providesDefinitions = providesDefinitions , providesReferences = providesReferences From d861a8d6fe136f4df594cb85a639151cb4ec7539 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Fri, 11 Oct 2024 12:02:01 +0200 Subject: [PATCH 05/57] more typos --- rascal-lsp/src/main/rascal/util/LanguageServer.rsc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index deb9c7e1e..1d2fb8d0d 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -364,15 +364,15 @@ To replace an old-style ((Documenter)) with a new style ((FocusDocumenter)) foll this scheme: ```rascal -set[loc] oldImplementer(loc document, Tree selection, Tree fullTree) { +set[loc] oldDocumenter(loc document, Tree selection, Tree fullTree) { ... } // by this scheme: -set[loc] newImplementer([Tree selection, *Tree _spine, Tree fullTree]) { +set[loc] newDocumenter([Tree selection, *Tree _spine, Tree fullTree]) { loc document = selection@\loc.top; ... } -default set[loc] newImplementer(list[Tree] _focus) = {}; +default set[loc] newDocumenter(list[Tree] _focus) = {}; ``` } LanguageService documenter(Documenter d) { @@ -384,7 +384,7 @@ LanguageService documenter(Documenter d) { return {}; } - return documenter(focusAcceptor); + return documentation(focusAcceptor); } @@ -415,7 +415,7 @@ LanguageService definer(Definer d) { return {}; } - return definer(focusAcceptor); + return definition(focusAcceptor); } @@ -447,7 +447,7 @@ LanguageService referrer(Referrer d) { return {}; } - return referrer(focusAcceptor); + return reference(focusAcceptor); } @synopsis{Registers an old-style ((Implementer))} @@ -477,7 +477,7 @@ LanguageService implementer(Implementer d) { return {}; } - return implementer(focusAcceptor); + return implementation(focusAcceptor); } @deprecated{Please use ((build)) or ((analysis))} From 64f8804f871a5f457c23e6e3775efdb2bab972b7 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Fri, 11 Oct 2024 23:23:23 +0200 Subject: [PATCH 06/57] fixes #472 --- .../src/main/rascal/util/LanguageServer.rsc | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 1d2fb8d0d..7e339cee6 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -72,6 +72,7 @@ This parse tree is then used for both syntax highlighting and other language ser @pitfalls { * use `ParseTree::parser` instead of writing your own function to ensure syntax highlighting is fast } +@deprecated{Used only in deprecated functions} alias Parser = Tree (str _input, loc _origin); @synopsis{Function profile for summarizer contributions to a language server} @@ -93,6 +94,7 @@ A summarizer provides the same information as the following contributors combine The difference is that these contributions are executed on-demand (pulled), while Summarizers are executed after build or after typing (push). } +@deprecated{Used only in deprecated functions} alias Summarizer = Summary (loc _origin, Tree _input); @synopsis{A focus provides the currently selected language constructs around the cursor.} @@ -124,15 +126,19 @@ of the user. alias Focus = list[Tree]; @synopsis{Function profile for outliner contributions to a language server} +@deprecated{Only in use in deprecated functions.} alias Outliner = list[DocumentSymbol] (Tree _input); @synopsis{Function profile for lenses contributions to a language server} +@deprecated{Only in use in deprecated functions.} alias LensDetector = rel[loc src, Command lens] (Tree _input); @synopsis{Function profile for executor contributions to a language server} +@deprecated{Only in use in deprecated functions.} alias CommandExecutor = value (Command _command); @synopsis{Function profile for inlay contributions to a language server} +@deprecated{Only in use in deprecated functions.} alias InlayHinter = list[InlayHint] (Tree _input); @synopsis{Function profile for documentation contributions to a language server} @@ -146,7 +152,7 @@ A documenter is called on-demand, when documentation is requested by the IDE use * should be extremely fast in order to provide interactive access. * careful use of `@memo` may help to cache dependencies, but this is tricky! } -@deprecated{The ((FocusDocumenter)) has replaced this type.} +@deprecated{Only in use in deprecated functions} alias Documenter = set[str] (loc _origin, Tree _fullTree, Tree _lexicalAtCursor); @synopsis{Function profile for documentation contributions to a language server} @@ -287,39 +293,45 @@ Many language contributions received a ((Focus)) parameter. This helps to create is syntax-directed: relevant to the current syntactical constructs under the cursor. } data LanguageService - = parsing(Parser parser) - | analysis(Summarizer summarizer + = parsing(Tree (str _input, loc _origin) parser) + | analysis(Summary (loc _origin, Tree _input) summarizer , bool providesDocumentation = true , bool providesDefinitions = true , bool providesReferences = true , bool providesImplementations = true) - | build(Summarizer summarizer + | build(Summary (loc _origin, Tree _input) summarizer , bool providesDocumentation = true , bool providesDefinitions = true , bool providesReferences = true , bool providesImplementations = true) - | outline(Outliner outliner) - | lense(LensDetector detector) - | inlay(InlayHinter hinter) - | execution(CommandExecutor executor) - | documentation(FocusDocumenter documenter) - | definition(FocusDefiner definer) - | reference(FocusReferrer reference) - | implementation(FocusImplementer implementer) - | action(CodeActionContributor actions) + | outline(list[DocumentSymbol] (Tree _input) labeler) + | codeLense(lrel[loc src, Command lens] (Tree _input) detector) + | inlay(list[InlayHint] (Tree _input) hinter) + | execution(value (Command _command) executor) + | documentation(set[str] (Focus _focus) documentor) + | definition(set[loc] (Focus _focus) linker) + | reference(set[loc] (Focus _focus) linker) + | implementation(set[loc] (Focus _focus) linker) + | action(list[CodeAction] (Focus _focus) actions) ; @deprecated{Backward compatible with `parsing`} @synopsis{Construct a `parsing` LanguageService} LanguageService parser(Parser parser) = parsing(parser); -@deprecated{Backward compatible with `lenses`} -@synopsis{Construct a `lense` LanguageService} -LanguageService lenses(LensDetector detector) = lense(detector); +@deprecated{Backward compatible with `codeLense`} +@synopsis{Construct a `codeLense` LanguageService} +@description{ +Not only translates to the old name of the LanguageService, +it also maps the list to an arbitrarily ordered set as it was before. +} +LanguageService lenses(LensDetector detector) = codeLense(lrel[loc src, Command lens] (Tree input) { + return [*detector(input)]; +}); @deprecated{Backward compatible with `action`} @synopsis{Construct a `lense` LanguageService} -LanguageService actios(CodeActionContributor contributor) = action(contributor); +LanguageService actions(CodeActionContributor contributor) = action(contributor); @deprecated{Backward compatible with `analysis`} @synopsis{Construct a `analysis` LanguageService} From 3d2ea0af48781fe9e6c077a0585a82fb9bc2b564 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Fri, 11 Oct 2024 23:27:40 +0200 Subject: [PATCH 07/57] getting the names right --- rascal-lsp/src/main/rascal/util/LanguageServer.rsc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 7e339cee6..b8952112a 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -283,7 +283,7 @@ documentation, definitions, references, implementations and compiler errors and * a ((definition)) service is a fast and location specific version of the `definitions` relation in a ((Summary)). * a ((reference)) service is a fast and location specific version of the `references` relation in a ((Summary)). * an ((implementation)) service is a fast and location specific version of the `implementations` relation in a ((Summary)). -* The ((outline)) service maps a source file to a pretty hierarchy for visualization in the "outline" view +* The ((documentSymbol)) service maps a source file to a pretty hierarchy for visualization in the "outline" view and "symbol search" features. * The ((lenses)) service discovers places to add "lenses" (little views embedded in the editor on a separate line) and connects commands to execute to each lense * The ((inlays)) service discovers plances to add "inlays" (little views embedded in the editor on the same line). Unlike ((lenses)) inlays do not offer command execution. * The ((execution)) service executes the commands registered by ((lenses)) and ((inlayHinter))s. @@ -304,9 +304,9 @@ data LanguageService , bool providesDefinitions = true , bool providesReferences = true , bool providesImplementations = true) - | outline(list[DocumentSymbol] (Tree _input) labeler) + | documentSymbol(list[DocumentSymbol] (Tree _input) labeler) | codeLense(lrel[loc src, Command lens] (Tree _input) detector) - | inlay(list[InlayHint] (Tree _input) hinter) + | inlayHint(list[InlayHint] (Tree _input) hinter) | execution(value (Command _command) executor) | documentation(set[str] (Focus _focus) documentor) | definition(set[loc] (Focus _focus) linker) @@ -341,13 +341,13 @@ LanguageService analyzer(Summarizer summarizer) = analysis(summarizer); @synopsis{Construct a `build` LanguageService} LanguageService builder(Summarizer summarizer) = build(summarizer); -@deprecated{Backward compatible with `outline`} +@deprecated{Backward compatible with `documentSymbol`} @synopsis{Construct a `build` LanguageService} -LanguageService outliner(Outliner outliner) = outline(outliner); +LanguageService outliner(Outliner outliner) = documentSymbol(outliner); @deprecated{Backward compatible with `inlays`} @synopsis{Construct a `inlays` LanguageService} -LanguageService inlayHinter(InlayHinter hinter) = inlay(hinter); +LanguageService inlayHinter(InlayHinter hinter) = inlayHint(hinter); @deprecated{Backward compatible with `execution`} @synopsis{Construct a `execution` LanguageService} From 5037798bef32a7c540a1b5b2b6261658ab569d17 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Fri, 11 Oct 2024 23:30:51 +0200 Subject: [PATCH 08/57] removed superfluous documentation --- .../src/main/rascal/util/LanguageServer.rsc | 115 +----------------- 1 file changed, 4 insertions(+), 111 deletions(-) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index b8952112a..25dec54a7 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -141,128 +141,21 @@ alias CommandExecutor = value (Command _command); @deprecated{Only in use in deprecated functions.} alias InlayHinter = list[InlayHint] (Tree _input); -@synopsis{Function profile for documentation contributions to a language server} -@description{ -A documenter is called on-demand, when documentation is requested by the IDE user. -} -@benefits{ -* is focused on a single documentation request, so does not need full program analysis. -} -@pitfalls{ -* should be extremely fast in order to provide interactive access. -* careful use of `@memo` may help to cache dependencies, but this is tricky! -} @deprecated{Only in use in deprecated functions} alias Documenter = set[str] (loc _origin, Tree _fullTree, Tree _lexicalAtCursor); -@synopsis{Function profile for documentation contributions to a language server} -@description{ -A ((FocusDocumenter)) is called on-demand, when documentation is requested by the IDE user. -The current selection is used to create a ((Focus)) that we can use to select the right -functionality with. It is possible several constructs are in "focus", and then we can -provide several pieces of documentation. -} -@benefits{ -* is focused on a single documentation request, so does not need full program analysis. -} -@pitfalls{ -* should be extremely fast in order to provide interactive access. -* careful use of `@memo` may help to cache dependencies, but this is tricky! -} -alias FocusDocumenter = set[str] (Focus _focus); - -@synopsis{Function profile for retrieving code actions focused around the current cursor} -@description{ -Next to the quickfix commands that may be attached to diagnostic ((Message))s, the LSP -can produce refactoring and quickfix or visualization actions specific for what is near -or under the current cursor. - -An action contributor is called on demand when a user presses a light-bulb or asks for quick-fixes. -The implementor is asked to produce only actions that pertain what is under the current cursor. -} +@deprecated{Only in use in deprecated functions} alias CodeActionContributor = list[CodeAction] (Focus _focus); -@synopsis{Function profile for definer contributions to a language server} -@description{ -A definer is called on-demand, when a definition is requested by the IDE user. -} -@benefits{ -* is focused on a single definition request, so does not need full program analysis. -} -@pitfalls{ -* should be extremely fast in order to provide interactive access. -* careful use of `@memo` may help to cache dependencies, but this is tricky! -} -@deprecated{Use ((FocusDefiner)) instead.} +@deprecated{Only in use in deprecated functions} alias Definer = set[loc] (loc _origin, Tree _fullTree, Tree _lexicalAtCursor); -@synopsis{Function profile for definer contributions to a language server} -@description{ -A definer is called on-demand, when a definition is requested by the IDE user. -} -@benefits{ -* is focused on a single definition request, so does not need full program analysis. -} -@pitfalls{ -* should be extremely fast in order to provide interactive access. -* careful use of `@memo` may help to cache dependencies, but this is tricky! -} -alias FocusDefiner = set[loc] (Focus _focus); - -@synopsis{Function profile for referrer contributions to a language server} -@description{ -A referrer is called on-demand, when a reference is requested by the IDE user. -} -@benefits{ -* is focused on a single reference request, so does not need full program analysis. -} -@pitfalls{ -* should be extremely fast in order to provide interactive access. -* careful use of `@memo` may help to cache dependencies, but this is tricky! -} -@deprecated{Use ((FocusReferrer)) instead} +@deprecated{Only in use in deprecated functions} alias Referrer = set[loc] (loc _origin, Tree _fullTree, Tree _lexicalAtCursor); -@synopsis{Function profile for referrer contributions to a language server} -@description{ -A referrer is called on-demand, when a reference is requested by the IDE user. -} -@benefits{ -* is focused on a single reference request, so does not need full program analysis. -} -@pitfalls{ -* should be extremely fast in order to provide interactive access. -* careful use of `@memo` may help to cache dependencies, but this is tricky! -} -alias FocusReferrer = set[loc] (list[Tree] _focus); - -@synopsis{Function profile for implementer contributions to a language server} -@description{ -An implementer is called on-demand, when an implementation is requested by the IDE user. -} -@benefits{ -* is focused on a single implementation request, so does not need full program analysis. -} -@pitfalls{ -* should be extremely fast in order to provide interactive access. -* careful use of `@memo` may help to cache dependencies, but this is tricky! -} -@deprecated{Use ((FocusImplementer)) instead.} +@deprecated{Only in use in deprecated functions} alias Implementer = set[loc] (loc _origin, Tree _fullTree, Tree _lexicalAtCursor); -@synopsis{Function profile for implementer contributions to a language server} -@description{ -An implementer is called on-demand, when an implementation is requested by the IDE user. -} -@benefits{ -* is focused on a single implementation request, so does not need full program analysis. -} -@pitfalls{ -* should be extremely fast in order to provide interactive access. -* careful use of `@memo` may help to cache dependencies, but this is tricky! -} -alias FocusImplementer = set[loc] (Focus _focus); - @synopsis{Each kind of service contibutes the implementation of one (or several) IDE features.} @description{ Each LanguageService provides one aspect of definining the language server protocol. From 34a6481ed0b37d143650b7da33cb0f2e9619248b Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Fri, 11 Oct 2024 23:32:35 +0200 Subject: [PATCH 09/57] more doc cleanup --- .../src/main/rascal/util/LanguageServer.rsc | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 25dec54a7..6c2e8d777 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -76,24 +76,6 @@ This parse tree is then used for both syntax highlighting and other language ser alias Parser = Tree (str _input, loc _origin); @synopsis{Function profile for summarizer contributions to a language server} -@description{ -Summarizers provide information about the declarations and uses in the current file -which can be used to populate the information needed to implement interactive IDE -features. - -There are two places a Summarizer can be called: -* Summarizers can be called after _file save_, in this case we use ((builder))s. Builders typically also have side-effects on disk (leaving generated code or API descriptions in the target folder), and they may run whole-program analysis and compilation steps. -* Or they can be called while typing, in this case we use ((analyzer))s. Analyzers typically use stored or cached information from other files, but focus their own analysis on their own file. Analyzers may use incremental techniques. - -A summarizer provides the same information as the following contributors combined: -* ((documenter)) -* ((definer)) -* ((referrer)) -* ((implementer)) - -The difference is that these contributions are executed on-demand (pulled), while Summarizers -are executed after build or after typing (push). -} @deprecated{Used only in deprecated functions} alias Summarizer = Summary (loc _origin, Tree _input); @@ -147,13 +129,16 @@ alias Documenter = set[str] (loc _origin, Tree _fullTree, Tree _lexicalAtCursor) @deprecated{Only in use in deprecated functions} alias CodeActionContributor = list[CodeAction] (Focus _focus); -@deprecated{Only in use in deprecated functions} +@synopsis{Function profile for definer contributions to a language server} +@deprecated{Use ((FocusDefiner)) instead.} alias Definer = set[loc] (loc _origin, Tree _fullTree, Tree _lexicalAtCursor); -@deprecated{Only in use in deprecated functions} +@synopsis{Function profile for referrer contributions to a language server} +@deprecated{Use ((FocusReferrer)) instead} alias Referrer = set[loc] (loc _origin, Tree _fullTree, Tree _lexicalAtCursor); -@deprecated{Only in use in deprecated functions} +@synopsis{Function profile for implementer contributions to a language server} +@deprecated{Use ((FocusImplementer)) instead.} alias Implementer = set[loc] (loc _origin, Tree _fullTree, Tree _lexicalAtCursor); @synopsis{Each kind of service contibutes the implementation of one (or several) IDE features.} From bed2e0e4bd4ae7625018ae506fe57a5582054833 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Sat, 12 Oct 2024 15:32:38 +0200 Subject: [PATCH 10/57] aligned all the service names with their LSP sources, and extrapolated new ones for parsing, build, analysis and execution services --- .../src/main/rascal/util/LanguageServer.rsc | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 6c2e8d777..6b6360967 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -186,11 +186,11 @@ data LanguageService | codeLense(lrel[loc src, Command lens] (Tree _input) detector) | inlayHint(list[InlayHint] (Tree _input) hinter) | execution(value (Command _command) executor) - | documentation(set[str] (Focus _focus) documentor) + | hover(set[str] (Focus _focus) documentor) | definition(set[loc] (Focus _focus) linker) | reference(set[loc] (Focus _focus) linker) | implementation(set[loc] (Focus _focus) linker) - | action(list[CodeAction] (Focus _focus) actions) + | codeAction(list[CodeAction] (Focus _focus) actions) ; @deprecated{Backward compatible with `parsing`} @@ -203,6 +203,11 @@ LanguageService parser(Parser parser) = parsing(parser); Not only translates to the old name of the LanguageService, it also maps the list to an arbitrarily ordered set as it was before. } +@benefits{ +* If you need your lenses in a stable order in the editor, +use the `codeLense` constructor instead to provide a function that +uses an ordered list. +} LanguageService lenses(LensDetector detector) = codeLense(lrel[loc src, Command lens] (Tree input) { return [*detector(input)]; }); @@ -231,22 +236,6 @@ LanguageService inlayHinter(InlayHinter hinter) = inlayHint(hinter); @synopsis{Construct a `execution` LanguageService} LanguageService executor(CommandExecutor executor) = execution(executor); -@deprecated{Backward compatible with `documentation`} -@synopsis{Construct a `documentation` LanguageService} -LanguageService documenter(FocusDocumenter documentor) = documentation(documentor); - -@deprecated{Backward compatible with `definition`} -@synopsis{Construct a `definition` LanguageService} -LanguageService definer(FocusDefiner definer) = definition(definer); - -@deprecated{Backward compatible with `reference`} -@synopsis{Construct a `reference` LanguageService} -LanguageService referer(FocusReferrer referer) = reference(referer); - -@deprecated{Backward compatible with `implementation`} -@synopsis{Construct a `implementation` LanguageService} -LanguageService implementer(FocusImplementer implementer) = implementation(implementer); - @deprecated{ This is a backward compatibility layer for the pre-existing ((Documenter)) alias. @@ -274,7 +263,7 @@ LanguageService documenter(Documenter d) { return {}; } - return documentation(focusAcceptor); + return hover(focusAcceptor); } From 71a8ad611baf0ec5fb5558e66c5bfc1c671add5b Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Sat, 12 Oct 2024 15:53:10 +0200 Subject: [PATCH 11/57] fixed reference to old name --- rascal-lsp/src/main/rascal/util/LanguageServer.rsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 6b6360967..66a654c91 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -214,7 +214,7 @@ LanguageService lenses(LensDetector detector) = codeLense(lrel[loc src, Command @deprecated{Backward compatible with `action`} @synopsis{Construct a `lense` LanguageService} -LanguageService actions(CodeActionContributor contributor) = action(contributor); +LanguageService actions(CodeActionContributor contributor) = codeAction(contributor); @deprecated{Backward compatible with `analysis`} @synopsis{Construct a `analysis` LanguageService} From f946b1c42ccdc71ca86b798a0197770394085e57 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Sat, 12 Oct 2024 16:19:04 +0200 Subject: [PATCH 12/57] fixing minor issues and added demo of using the new API --- .../rascal/demo/lang/pico/LanguageServer.rsc | 1 + .../demo/lang/pico/NewLanguageServer.rsc | 187 ++++++++++++++++++ .../src/main/rascal/util/LanguageServer.rsc | 18 +- 3 files changed, 202 insertions(+), 4 deletions(-) create mode 100644 rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc index 39eca22f6..c700046c3 100644 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc @@ -24,6 +24,7 @@ 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. } +// @deprecated{This demo has been superseded by ((NewLanguageServer)) which avoids the use of deprecated API.} module demo::lang::pico::LanguageServer import util::LanguageServer; diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc new file mode 100644 index 000000000..8f116758e --- /dev/null +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc @@ -0,0 +1,187 @@ +@license{ +Copyright (c) 2018-2023, NWO-I CWI and Swat.engineering +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. +} +module demo::lang::pico::NewLanguageServer + +import util::LanguageServer; +import util::IDEServices; +import ParseTree; +import util::Reflective; +import lang::pico::\syntax::Main; + +@synopsis{Provides each contribution (IDE feature) as a callback element of the set of LanguageServices.} +set[LanguageService] picoLanguageContributor() = { + parsing(parser(#start[Program])), + documentSymbol(picoOutliner), + codeLense(picoLenses), + execution(picoCommands), + inlayHint(picoHinter), + definition(lookupDef), + codeAction(picoActions) +}; + +@synopsis{This set of contributions runs slower but provides more detail.} +set[LanguageService] picoLanguageContributorSlowSummary() = { + parsing(parser(#start[Program])), + analysis(picoAnalyzer, providesImplementations = false), + build(picoBuilder) +}; + +@synopsis{The outliner maps pico syntax trees to lists of DocumentSymbols.} +list[DocumentSymbol] picoOutliner(start[Program] input) + = [symbol("", DocumentSymbolKind::\file(), input.src, children=[ + *[symbol("", \variable(), var.src) | /IdType var := input] + ])]; + +@synopsis{The analyzer maps pico syntax trees to error messages and references} +Summary picoAnalyzer(loc l, start[Program] input) = picoSummarizer(l, input, analyze()); + +@synopsis{The builder does a more thorough analysis then the analyzer, providing more detail} +Summary picoBuilder(loc l, start[Program] input) = picoSummarizer(l, input, build()); + +@synopsis{A simple "enum" data type for switching between analysis modes} +data PicoSummarizerMode + = analyze() + | build() + ; + +@synopsis{Translates a pico syntax tree to a model (Summary) of everything we need to know about the program in the IDE.} +Summary picoSummarizer(loc l, start[Program] input, PicoSummarizerMode mode) { + Summary s = summary(l); + + // definitions of variables + rel[str, loc] defs = {<"", var.src> | /IdType var := input}; + + // uses of identifiers + rel[loc, str] uses = {"> | /Id id := input}; + + // documentation strings for identifier uses + rel[loc, str] docs = {"> | /IdType var := input}; + + // Provide errors (cheap to compute) both in analyze mode and in build mode. + s.messages += { is not defined", src, fixes=prepareNotDefinedFixes(src, defs))> + | <- uses, id notin defs<0>}; + + // "references" are links for loc to loc (from def to use) + s.references += (uses o defs)<1,0>; + + // "definitions" are also links from loc to loc (from use to def) + s.definitions += uses o defs; + + // "documentation" maps locations to strs + s.documentation += (uses o defs) o docs; + + // Provide warnings (expensive to compute) only in build mode + if (build() := mode) { + rel[loc, str] asgn = {"> | /Statement stmt := input, (Statement) ` := ` := stmt}; + s.messages += { is not assigned", src)> | <- defs, id notin asgn<1>}; + } + + return s; +} + +@synopsis{Looks up the declaration for any variable use using a list match into a ((Focus))} +set[loc] lookupDef([*_, Id use, *_, start[Program] input]) = { d.src | /IdType def := input, def.id := use}; + +@synopsis{If a variable is not defined, we list a fix of fixes to replace it with a defined variable instead.} +list[CodeAction] prepareNotDefinedFixes(loc src, rel[str, loc] defs) + = [action(title="Change to >", edits=[changed(src.top, [replace(src, existing<0>)])]) | existing <- defs]; + +@synopsis{Finds a declaration that the cursor is on and proposes to remove it.} +list[CodeAction] picoActions([*_, IdType x, *_, start[Program] program]) + = [action(command=removeDecl(program, x, title="remove "))]; + +default list[CodeAction] picoActions(Focus _focus) = []; + +@synsopsis{Defines three example commands that can be triggered by the user (from a code lens, from a diagnostic, or just from the cursor position)} +data Command + = renameAtoB(start[Program] program) + | removeDecl(start[Program] program, IdType toBeRemoved) + ; + +@synopsis{Adds an example lense to the entire program.} +lrel[loc,Command] picoLenses(start[Program] input) + = []; + +@synopsis{Generates inlay hints that explain the type of each variable usage.} +list[InlayHint] picoHinter(start[Program] input) { + typeLookup = ( "" : "" | /(IdType)` : ` := input); + + return [ + hint(name.src, " : "]>", \type(), atEnd = true) + | /(Expression)`` := input + , "" in typeLookup + ]; +} + +@synopsis{Helper function to generate actual edit actions for the renameAtoB command} +list[DocumentEdit] getAtoBEdits(start[Program] input) + = [changed(input@\loc.top, [replace(id@\loc, "b") | /id:(Id) `a` := input])]; + +@synopsis{Command handler for the renameAtoB command} +value picoCommands(renameAtoB(start[Program] input)) { + applyDocumentsEdits(getAtoBEdits(input)); + return ("result": true); +} + +@synopsis{Command handler for the removeDecl command} +value picoCommands(removeDecl(start[Program] program, IdType toBeRemoved)) { + applyDocumentsEdits([changed(program@\loc.top, [replace(toBeRemoved@\loc, "")])]); + return ("result": true); +} + +@synopsis{The main function registers the Pico language with the IDE} +@description{ +Register the Pico language and the contributions that supply the IDE with features. + +((registerLanguage)) is called twice here: +1. first for fast and cheap contributions +2. asynchronously for the full monty that loads slower +} +@benefits{ +* You can run each contribution on an example in the terminal to test it first. +Any feedback (errors and exceptions) is faster and more clearly printed in the terminal. +} +void main() { + registerLanguage( + language( + pathConfig(), + "Pico", + {"pico", "pico-new"}, + "demo::lang::pico::LanguageServer", + "picoLanguageContributor" + ) + ); + registerLanguage( + language( + pathConfig(), + "Pico", + {"pico", "pico-new"}, + "demo::lang::pico::LanguageServer", + "picoLanguageContributorSlowSummary" + ) + ); +} diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 66a654c91..6b677b6de 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -216,10 +216,6 @@ LanguageService lenses(LensDetector detector) = codeLense(lrel[loc src, Command @synopsis{Construct a `lense` LanguageService} LanguageService actions(CodeActionContributor contributor) = codeAction(contributor); -@deprecated{Backward compatible with `analysis`} -@synopsis{Construct a `analysis` LanguageService} -LanguageService analyzer(Summarizer summarizer) = analysis(summarizer); - @deprecated{Backward compatible with `build`} @synopsis{Construct a `build` LanguageService} LanguageService builder(Summarizer summarizer) = build(summarizer); @@ -374,6 +370,20 @@ LanguageService summarizer(Summarizer summarizer , providesImplementations = providesImplementations); } +@deprecated{Please use ((build)) or ((analysis))} +@synopsis{An analyzer collects information for later use in interactive IDE features.} +LanguageService analyzer(Summarizer summarizer + , bool providesDocumentation = true + , bool providesDefinitions = true + , bool providesReferences = true + , bool providesImplementations = true) { + return analysis(summarizer + , providesDocumentation = providesDocumentation + , providesDefinitions = providesDefinitions + , providesReferences = providesReferences + , providesImplementations = providesImplementations); +} + @synopsis{A model encodes all IDE-relevant information about a single source file.} @description{ * `src` refers to the "compilation unit" or "file" that this model is for. From 364c3933878789efb020bce3593f6518d419b5a6 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Sun, 13 Oct 2024 14:10:46 +0200 Subject: [PATCH 13/57] fixed issues in documentation --- .../rascal/demo/lang/pico/NewLanguageServer.rsc | 2 +- rascal-lsp/src/main/rascal/util/LanguageServer.rsc | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc index 8f116758e..b2c2cfe6d 100644 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc @@ -104,7 +104,7 @@ Summary picoSummarizer(loc l, start[Program] input, PicoSummarizerMode mode) { } @synopsis{Looks up the declaration for any variable use using a list match into a ((Focus))} -set[loc] lookupDef([*_, Id use, *_, start[Program] input]) = { d.src | /IdType def := input, def.id := use}; +set[loc] lookupDef([*_, Id use, *_, start[Program] input]) = { d.src | /IdType def := input, use := def.id}; @synopsis{If a variable is not defined, we list a fix of fixes to replace it with a defined variable instead.} list[CodeAction] prepareNotDefinedFixes(loc src, rel[str, loc] defs) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 6b677b6de..a8e3f96e9 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -151,19 +151,19 @@ documentation, definitions, references, implementations and compiler errors and * ((analysis)) has to be quick since they run in an interactive editor setting. * ((analysis)) may store previous results (in memory) for incremental updates. * ((analysis)) is triggered during typing, in a short typing pause. -* The ((build)) service is similar to an `analyzer`, but it may perform computation-heavier additional checks. - * ((build))s typically run whole-program analyses and compilation steps. - * ((build))s have side-effects, they store generated code or code indices for future usage by the next build step, or by the next analysis step. - * ((build))s are triggered on _save-file_ events; they _push_ information to an internal cache. - * Warning: ((build))s are _not_ triggered when a file changes on disk outside of VS Code; instead, this results in a change event (not a save event), which triggers the ((analyzer)). +* The ((util::LanguageServer::build)) service is similar to an `analyzer`, but it may perform computation-heavier additional checks. + * ((util::LanguageServer::build))s typically run whole-program analyses and compilation steps. + * ((util::LanguageServer::build))s have side-effects, they store generated code or code indices for future usage by the next build step, or by the next analysis step. + * ((util::LanguageServer::build))s are triggered on _save-file_ events; they _push_ information to an internal cache. + * Warning: ((util::LanguageServer::build))s are _not_ triggered when a file changes on disk outside of VS Code; instead, this results in a change event (not a save event), which triggers the ((analyzer)). * the following contributions are _on-demand_ (pull) versions of information also provided by the analyzer and builder summaries. - * a ((documentation)) service is a fast and location specific version of the `documentation` relation in a ((Summary)). + * a ((hover)) service is a fast and location specific version of the `documentation` relation in a ((Summary)). * a ((definition)) service is a fast and location specific version of the `definitions` relation in a ((Summary)). * a ((reference)) service is a fast and location specific version of the `references` relation in a ((Summary)). * an ((implementation)) service is a fast and location specific version of the `implementations` relation in a ((Summary)). * The ((documentSymbol)) service maps a source file to a pretty hierarchy for visualization in the "outline" view and "symbol search" features. * The ((lenses)) service discovers places to add "lenses" (little views embedded in the editor on a separate line) and connects commands to execute to each lense -* The ((inlays)) service discovers plances to add "inlays" (little views embedded in the editor on the same line). Unlike ((lenses)) inlays do not offer command execution. +* The ((inlayHint)) service discovers plances to add "inlays" (little views embedded in the editor on the same line). Unlike ((lenses)) inlays do not offer command execution. * The ((execution)) service executes the commands registered by ((lenses)) and ((inlayHinter))s. * The ((actions)) service discovers palces to add "code actions" (little hints in the margin next to where the action is relevant) and connects ((CodeAction))s to execute when the users selects the action from a menu. From 0d995d5d66d334247259428c0064d0c396d7fe7c Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Sun, 13 Oct 2024 14:39:55 +0200 Subject: [PATCH 14/57] fixed parse error --- rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc index b2c2cfe6d..49884055f 100644 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc @@ -104,7 +104,7 @@ Summary picoSummarizer(loc l, start[Program] input, PicoSummarizerMode mode) { } @synopsis{Looks up the declaration for any variable use using a list match into a ((Focus))} -set[loc] lookupDef([*_, Id use, *_, start[Program] input]) = { d.src | /IdType def := input, use := def.id}; +set[loc] lookupDef([*_, Id use, *_, start[Program] input]) = { def.src | /IdType def := input, use := def.id}; @synopsis{If a variable is not defined, we list a fix of fixes to replace it with a defined variable instead.} list[CodeAction] prepareNotDefinedFixes(loc src, rel[str, loc] defs) From 1d19a4a70a13d7af2c237721d2cf4bd82c790fac Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Sun, 13 Oct 2024 14:58:06 +0200 Subject: [PATCH 15/57] renamed constructor names of services in Java side --- .../lsp/parametric/model/RascalADTs.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java index b9c4400da..c974a77c5 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java @@ -33,18 +33,18 @@ public class RascalADTs { private RascalADTs() {} public static class LanguageContributions { private LanguageContributions () {} - public static final String PARSER = "parser"; - public static final String ANALYZER = "analyzer"; - public static final String BUILDER = "builder"; - public static final String OUTLINER = "outliner"; + public static final String PARSER = "parsing"; + public static final String ANALYZER = "analysis"; + public static final String BUILDER = "build"; + public static final String OUTLINER = "documentSymbol"; public static final String LENS_DETECTOR = "lenses"; - public static final String INLAY_HINTER = "inlayHinter"; - public static final String COMMAND_EXECUTOR = "executor"; - public static final String DOCUMENTER = "documenter"; - public static final String DEFINER = "definer"; - public static final String REFERRER = "referrer"; - public static final String IMPLEMENTER = "implementer"; - public static final String CODE_ACTION_CONTRIBUTOR = "actions"; + public static final String INLAY_HINTER = "inlayHint"; + public static final String COMMAND_EXECUTOR = "execution"; + public static final String DOCUMENTER = "hover"; + public static final String DEFINER = "definition"; + public static final String REFERRER = "reference"; + public static final String IMPLEMENTER = "implementation"; + public static final String CODE_ACTION_CONTRIBUTOR = "codeAction"; public static class Summarizers { private Summarizers() {} From 33f86d175cfaa88d5c2a905cba7b54119556a80b Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Sun, 13 Oct 2024 15:07:48 +0200 Subject: [PATCH 16/57] better types for the picoActions function --- rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc index c700046c3..0533dcff9 100644 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc @@ -114,7 +114,7 @@ list[CodeAction] prepareNotDefinedFixes(loc src, rel[str, loc] defs) = [action(title="Change to >", edits=[changed(src.top, [replace(src, existing<0>)])]) | existing <- defs]; @synopsis{Finds a declaration that the cursor is on and proposes to remove it.} -list[CodeAction] picoActions([*_, IdType x, *_, start[Program] program]) +list[CodeAction] picoActions([*Tree _, IdType x, *Tree _, start[Program] program]) = [action(command=removeDecl(program, x, title="remove "))]; default list[CodeAction] picoActions(Focus _focus) = []; From 5518859e2258d4c772c239a90744a5a366863d40 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Mon, 14 Oct 2024 12:24:48 +0200 Subject: [PATCH 17/57] Update rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc Co-authored-by: sungshik <16154899+sungshik@users.noreply.github.com> --- rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc index 49884055f..c22845ff0 100644 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc @@ -171,7 +171,7 @@ void main() { pathConfig(), "Pico", {"pico", "pico-new"}, - "demo::lang::pico::LanguageServer", + "demo::lang::pico::NewLanguageServer", "picoLanguageContributor" ) ); From 60f17541f2a233e82ff2e3bb92926e181602479b Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Mon, 14 Oct 2024 17:14:31 +0200 Subject: [PATCH 18/57] fixes based on feedback by @sungshik and @davylandman, plus renamed Summary.documentation to Summary.hovers and added documentation about the specific language services that used to be with the aliases --- .../lsp/parametric/model/RascalADTs.java | 6 +- .../src/main/rascal/util/LanguageServer.rsc | 106 +++++++++++++----- 2 files changed, 81 insertions(+), 31 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java index c974a77c5..89f8284ee 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java @@ -37,12 +37,12 @@ private LanguageContributions () {} public static final String ANALYZER = "analysis"; public static final String BUILDER = "build"; public static final String OUTLINER = "documentSymbol"; - public static final String LENS_DETECTOR = "lenses"; + public static final String LENS_DETECTOR = "codeLense"; public static final String INLAY_HINTER = "inlayHint"; public static final String COMMAND_EXECUTOR = "execution"; public static final String DOCUMENTER = "hover"; public static final String DEFINER = "definition"; - public static final String REFERRER = "reference"; + public static final String REFERRER = "references"; public static final String IMPLEMENTER = "implementation"; public static final String CODE_ACTION_CONTRIBUTOR = "codeAction"; @@ -59,7 +59,7 @@ private Summarizers() {} public static class SummaryFields { private SummaryFields() {} - public static final String DOCUMENTATION = "documentation"; + public static final String DOCUMENTATION = "hovers"; public static final String DEFINITIONS = "definitions"; public static final String REFERENCES = "references"; public static final String IMPLEMENTATIONS = "implementations"; diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 491452472..cf659bdd6 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -147,54 +147,102 @@ alias Implementer = set[loc] (loc _origin, Tree _fullTree, Tree _lexicalAtCursor @synopsis{Each kind of service contibutes the implementation of one (or several) IDE features.} @description{ -Each LanguageService provides one aspect of definining the language server protocol. -* The ((parsing)) service maps source code to a parse tree and indexes each part based on offset and length +Each LanguageService constructor provides one aspect of definining the language server protocol (LSP). +Their names coincide exactly with the services which are documented [here](https://microsoft.github.io/language-server-protocol/). + +* The ((parsing)) service that maps source code strings to a ((Tree)) is essential and non-optional. +All other other services are optional. + * By providing a parser which produces annotated parse ((Tree))s, editor features such as parse error locations, syntax highlighting and +selection assistance are immediately enabled. + * The ((parsing)) service is activated after every change in an editor document (when a suitable pause has occurred) + * All downstream services are based on the ((Tree)) that is produced here. In +particular downstream services make use of the `src` origin fields that the parser must produce. + * Parsers can be obtained automatically using the ((ParseTree::parser)) or ((ParseTree::parsers)) functions, like so `parser(#start[Program])`. +Like this a fast parser is obtained that does not require a global interpreter lock. If you pass in a normal Rascal function, which is fine, the global +interpreter lock will make the editor services less responsive. * The ((analysis)) service indexes a file as a ((Summary)), offering precomputed relations for looking up -documentation, definitions, references, implementations and compiler errors and warnings. +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. * ((analysis)) has to be quick since they run in an interactive editor setting. * ((analysis)) may store previous results (in memory) for incremental updates. - * ((analysis)) is triggered during typing, in a short typing pause. -* The ((util::LanguageServer::build)) service is similar to an `analyzer`, but it may perform computation-heavier additional checks. + * ((analysis)) is triggered on-demand during typing, in a short typing pause. So you have to provide a reasonable fast function (0.5 seconds is a good target response time). + * ((analysis)) pushes their result on a local stack; which is efficiently queried by the LSP features on-demand. +* The ((util::LanguageServer::build)) service is similar to an ((analysis)), but it may perform computation-heavier additional checks or take time generate source code and binary code that makes the code in the editor executable. * ((util::LanguageServer::build))s typically run whole-program analyses and compilation steps. * ((util::LanguageServer::build))s have side-effects, they store generated code or code indices for future usage by the next build step, or by the next analysis step. * ((util::LanguageServer::build))s are triggered on _save-file_ events; they _push_ information to an internal cache. * Warning: ((util::LanguageServer::build))s are _not_ triggered when a file changes on disk outside of VS Code; instead, this results in a change event (not a save event), which triggers the ((analyzer)). -* the following contributions are _on-demand_ (pull) versions of information also provided by the analyzer and builder summaries. + * If `providesDocumentation` is false, then the ((hover)) service may be activated. Same for `providesDefinitions` and `providesDocumentation` +)) +* the following contributions are _on-demand_ (pull) versions of information also provided by the ((analysis)) and ((build)) summaries. + * you can provide these more lightweight on-demand services _instead of_ the ((Summary)) versions. + * these functions are run synchronously after a user interaction. The run-time of each service corresponds directly to the UX response time. * a ((hover)) service is a fast and location specific version of the `documentation` relation in a ((Summary)). * a ((definition)) service is a fast and location specific version of the `definitions` relation in a ((Summary)). - * a ((reference)) service is a fast and location specific version of the `references` relation in a ((Summary)). + * a ((references)) service is a fast and location specific version of the `references` relation in a ((Summary)). * an ((implementation)) service is a fast and location specific version of the `implementations` relation in a ((Summary)). * The ((documentSymbol)) service maps a source file to a pretty hierarchy for visualization in the "outline" view and "symbol search" features. -* The ((lenses)) service discovers places to add "lenses" (little views embedded in the editor on a separate line) and connects commands to execute to each lense +* The ((codeLense)) service discovers places to add "lenses" (little views embedded in the editor on a separate line) and connects commands to execute to each lense * The ((inlayHint)) service discovers plances to add "inlays" (little views embedded in the editor on the same line). Unlike ((lenses)) inlays do not offer command execution. * The ((execution)) service executes the commands registered by ((lenses)) and ((inlayHinter))s. -* The ((actions)) service discovers palces to add "code actions" (little hints in the margin next to where the action is relevant) and connects ((CodeAction))s to execute when the users selects the action from a menu. - -Many language contributions received a ((Focus)) parameter. This helps to create functionality that -is syntax-directed: relevant to the current syntactical constructs under the cursor. +* The ((actions)) service discovers places in the editor to add "code actions" (little hints in the margin next to where the action is relevant) and connects ((CodeAction))s to execute when the users selects the action from a menu. + +Many services receive a ((Focus)) parameter. The focus lists the syntactical constructs under the current cursor, from the current +leaf all the way up to the root of the tree. This list helps to create functionality that is syntax-directed, and always relevant to the +programmer. + +To start developing an LSP extension step-by-step: +1. first write a ((SyntaxDefinition)) in Rascal and register it via the ((parsing)) service. Use ((registerLanguage)) from the terminal ((REPL)) to +test it immediately. Create some example files for your language to play around with. +2. either make an ((analysis)) service that produces a ((Summary)) _or_ start ((hover)), ((definition)), ((references)) and ((implementation)) +lookup services. Each of those four services require the same information that is useful for filling a ((Summary)) with an ((analysis)) or a ((builder)). +3. the ((documentSymbol)) service is next, good for the outline view and also quick search features. +4. the to add interactive features, optionally ((inlayHint)), ((codeLens)) and ((codeAction)) can be created to add visible hooks in the UI to trigger +your own ((CodeAction))s and ((Commands)) + * create an ((execution)) service to give semantics to each command. This includes creating ((DocumentEdit))s but also ((IDEServices)) + can be used to have interesting effects in the IDE. + * ((CodeAction))s can also be attached to error, warning and into ((Message))s as a result of ((parsing)), ((analysis)) or ((build)). + Such actions will lead to "quick-fix" UX options in the editor. +} +@benefits{ +* You can create editor services thinking only of your programming language or domain-specific language constructs. All of the communication +and (de)serialization and scheduling is taken care of. +* It is always possible and useful to test your services manually in the ((REPL)). This is the preferred way of testing and debugging language services. +* Except for the ((parsing)) service, all services are independent of each other. If one fails, or is removed, the others still work. +* Language services in general can be unit-tested easily by providing example parse trees and testing properties of their output. Write lots of test functions! +* LanguageServices are editor-independent/IDE-independent via the LSP protocol. In principle they can work with any editor that implements LSP 3.17 or higher. +* Older Eclipse DSL plugins via the rascal-eclipse plugin are easily ported to ((util::LanguageServer)). +} +@pitfalls{ +* If one of the services does not type-check in Rascal, or throws an exception at ((registerLanguage)) time, the extension fails completely. Typically the editor produces a parse error on the first line of the code. The +failure is printed in the log window of the IDE. +* Users have expectations with the concepts of ((references)), ((definitions)), ((implementation)) which are based on +typical programming language concepts. Since these are all just `rel[loc, loc]` it can be easy to confound them. + * ((references)) point from declarations sites to use sites + * ((definition)) points the other way around, from a use to the declaration, but only if a value is associated there explicitly or implicitly. + * ((implementation)) points from abstract declarations (interfaces, classes, function signatures) to more concrete realizations of those declarations. } data LanguageService - = parsing(Tree (str _input, loc _origin) parser) - | analysis(Summary (loc _origin, Tree _input) summarizer - , bool providesDocumentation = true + = parsing(Tree (str _input, loc _origin)) + | analysis(Summary (loc _origin, Tree _input) + , bool providesHovers = true , bool providesDefinitions = true , bool providesReferences = true , bool providesImplementations = true) - | build(Summary (loc _origin, Tree _input) summarizer - , bool providesDocumentation = true + | build(Summary (loc _origin, Tree _input) + , bool providesHovers = true , bool providesDefinitions = true , bool providesReferences = true , bool providesImplementations = true) - | documentSymbol(list[DocumentSymbol] (Tree _input) labeler) - | codeLense(lrel[loc src, Command lens] (Tree _input) detector) - | inlayHint(list[InlayHint] (Tree _input) hinter) - | execution(value (Command _command) executor) - | hover(set[str] (Focus _focus) documentor) - | definition(set[loc] (Focus _focus) linker) - | reference(set[loc] (Focus _focus) linker) - | implementation(set[loc] (Focus _focus) linker) - | codeAction(list[CodeAction] (Focus _focus) actions) + | documentSymbol(list[DocumentSymbol] (Tree _input)) + | codeLens (lrel[loc src, Command lens] (Tree _input)) + | inlayHint (list[InlayHint] (Tree _input)) + | execution (value (Command _command)) + | hover (set[str] (Focus _focus)) + | definition (set[loc] (Focus _focus)) + | references (set[loc] (Focus _focus)) + | implementation(set[loc] (Focus _focus)) + | codeAction (list[CodeAction] (Focus _focus)) ; @deprecated{Backward compatible with `parsing`} @@ -212,7 +260,7 @@ it also maps the list to an arbitrarily ordered set as it was before. use the `codeLense` constructor instead to provide a function that uses an ordered list. } -LanguageService lenses(LensDetector detector) = codeLense(lrel[loc src, Command lens] (Tree input) { +LanguageService lenses(LensDetector detector) = codeLens(lrel[loc src, Command lens] (Tree input) { return [*detector(input)]; }); @@ -392,7 +440,8 @@ LanguageService analyzer(Summarizer summarizer @description{ * `src` refers to the "compilation unit" or "file" that this model is for. * `messages` collects all the errors, warnings and error messages. -* `documentation` maps uses of concepts to a documentation message that can be shown as a hover. +* `documentation` is the deprecated name for `hovers` +* `hovers` maps uses of concepts to a documentation message that can be shown as a hover. * `definitions` maps use locations to declaration locations to implement "jump-to-definition". * `references` maps declaration locations to use locations to implement "jump-to-references". * `implementations` maps the declaration of a type/class to its implementations "jump-to-implementations". @@ -400,6 +449,7 @@ LanguageService analyzer(Summarizer summarizer data Summary = summary(loc src, rel[loc, Message] messages = {}, rel[loc, str] documentation = {}, + rel[loc, str] hovers = documentation, rel[loc, loc] definitions = {}, rel[loc, loc] references = {}, rel[loc, loc] implementations = {} From cec6310ad347aac01f0ce5f3e9677e31317fb2ba Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Mon, 14 Oct 2024 17:26:16 +0200 Subject: [PATCH 19/57] setting more things straight, especially in the example code --- .../demo/lang/pico/NewLanguageServer.rsc | 38 +++++++++---------- .../src/main/rascal/util/LanguageServer.rsc | 11 ++++-- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc index c22845ff0..cd546ceb8 100644 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc @@ -35,12 +35,12 @@ import lang::pico::\syntax::Main; @synopsis{Provides each contribution (IDE feature) as a callback element of the set of LanguageServices.} set[LanguageService] picoLanguageContributor() = { parsing(parser(#start[Program])), - documentSymbol(picoOutliner), - codeLense(picoLenses), - execution(picoCommands), - inlayHint(picoHinter), - definition(lookupDef), - codeAction(picoActions) + documentSymbol(picoDocumentSymbolService), + codeLens(picoCodeLenseService), + execution(picoExecutionService), + inlayHint(picoInlayHintService), + definition(picoDefinitionService), + codeAction(picoCodeActionService) }; @synopsis{This set of contributions runs slower but provides more detail.} @@ -50,17 +50,17 @@ set[LanguageService] picoLanguageContributorSlowSummary() = { build(picoBuilder) }; -@synopsis{The outliner maps pico syntax trees to lists of DocumentSymbols.} -list[DocumentSymbol] picoOutliner(start[Program] input) +@synopsis{The documentSymbol service maps pico syntax trees to lists of DocumentSymbols.} +list[DocumentSymbol] picoDocumentSymbolService(start[Program] input) = [symbol("", DocumentSymbolKind::\file(), input.src, children=[ *[symbol("", \variable(), var.src) | /IdType var := input] ])]; @synopsis{The analyzer maps pico syntax trees to error messages and references} -Summary picoAnalyzer(loc l, start[Program] input) = picoSummarizer(l, input, analyze()); +Summary picoAnalysisService(loc l, start[Program] input) = picoSummaryService(l, input, analyze()); @synopsis{The builder does a more thorough analysis then the analyzer, providing more detail} -Summary picoBuilder(loc l, start[Program] input) = picoSummarizer(l, input, build()); +Summary picoBuildService(loc l, start[Program] input) = picoSummaryService(l, input, build()); @synopsis{A simple "enum" data type for switching between analysis modes} data PicoSummarizerMode @@ -69,7 +69,7 @@ data PicoSummarizerMode ; @synopsis{Translates a pico syntax tree to a model (Summary) of everything we need to know about the program in the IDE.} -Summary picoSummarizer(loc l, start[Program] input, PicoSummarizerMode mode) { +Summary picoSummaryService(loc l, start[Program] input, PicoSummarizerMode mode) { Summary s = summary(l); // definitions of variables @@ -104,17 +104,17 @@ Summary picoSummarizer(loc l, start[Program] input, PicoSummarizerMode mode) { } @synopsis{Looks up the declaration for any variable use using a list match into a ((Focus))} -set[loc] lookupDef([*_, Id use, *_, start[Program] input]) = { def.src | /IdType def := input, use := def.id}; +set[loc] picoDefinitionService([*_, Id use, *_, start[Program] input]) = { def.src | /IdType def := input, use := def.id}; @synopsis{If a variable is not defined, we list a fix of fixes to replace it with a defined variable instead.} list[CodeAction] prepareNotDefinedFixes(loc src, rel[str, loc] defs) = [action(title="Change to >", edits=[changed(src.top, [replace(src, existing<0>)])]) | existing <- defs]; @synopsis{Finds a declaration that the cursor is on and proposes to remove it.} -list[CodeAction] picoActions([*_, IdType x, *_, start[Program] program]) +list[CodeAction] picoCodeActionService([*_, IdType x, *_, start[Program] program]) = [action(command=removeDecl(program, x, title="remove "))]; -default list[CodeAction] picoActions(Focus _focus) = []; +default list[CodeAction] picoCodeActionService(Focus _focus) = []; @synsopsis{Defines three example commands that can be triggered by the user (from a code lens, from a diagnostic, or just from the cursor position)} data Command @@ -123,11 +123,11 @@ data Command ; @synopsis{Adds an example lense to the entire program.} -lrel[loc,Command] picoLenses(start[Program] input) +lrel[loc,Command] picoCodeLenseService(start[Program] input) = []; @synopsis{Generates inlay hints that explain the type of each variable usage.} -list[InlayHint] picoHinter(start[Program] input) { +list[InlayHint] picoInlayHintService(start[Program] input) { typeLookup = ( "" : "" | /(IdType)` : ` := input); return [ @@ -142,13 +142,13 @@ list[DocumentEdit] getAtoBEdits(start[Program] input) = [changed(input@\loc.top, [replace(id@\loc, "b") | /id:(Id) `a` := input])]; @synopsis{Command handler for the renameAtoB command} -value picoCommands(renameAtoB(start[Program] input)) { +value picoExecutionService(renameAtoB(start[Program] input)) { applyDocumentsEdits(getAtoBEdits(input)); return ("result": true); } @synopsis{Command handler for the removeDecl command} -value picoCommands(removeDecl(start[Program] program, IdType toBeRemoved)) { +value picoExecutionService(removeDecl(start[Program] program, IdType toBeRemoved)) { applyDocumentsEdits([changed(program@\loc.top, [replace(toBeRemoved@\loc, "")])]); return ("result": true); } @@ -180,7 +180,7 @@ void main() { pathConfig(), "Pico", {"pico", "pico-new"}, - "demo::lang::pico::LanguageServer", + "demo::lang::pico::NewLanguageServer", "picoLanguageContributorSlowSummary" ) ); diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index cf659bdd6..0a99d5af0 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -221,16 +221,19 @@ typical programming language concepts. Since these are all just `rel[loc, loc]` * ((references)) point from declarations sites to use sites * ((definition)) points the other way around, from a use to the declaration, but only if a value is associated there explicitly or implicitly. * ((implementation)) points from abstract declarations (interfaces, classes, function signatures) to more concrete realizations of those declarations. +* `providesDocumentation` is deprecated. Use `providesHovers` instead. } data LanguageService = parsing(Tree (str _input, loc _origin)) | analysis(Summary (loc _origin, Tree _input) - , bool providesHovers = true + , bool providesDocumentation = true + , bool providesHovers = providesDocumentation , bool providesDefinitions = true , bool providesReferences = true , bool providesImplementations = true) | build(Summary (loc _origin, Tree _input) - , bool providesHovers = true + , bool providesDocumentation = true + , bool providesHovers = providesDocumentation , bool providesDefinitions = true , bool providesReferences = true , bool providesImplementations = true) @@ -374,7 +377,7 @@ LanguageService referrer(Referrer d) { return {}; } - return reference(focusAcceptor); + return references(focusAcceptor); } @synopsis{Registers an old-style ((Implementer))} @@ -411,12 +414,14 @@ LanguageService implementer(Implementer d) { @synopsis{A summarizer collects information for later use in interactive IDE features.} LanguageService summarizer(Summarizer summarizer , bool providesDocumentation = true + , bool providesHovers = providesDocumentation , bool providesDefinitions = true , bool providesReferences = true , bool providesImplementations = true) { println("Summarizers are deprecated. Please use builders (triggered on save) and analyzers (triggered on change) instead."); return build(summarizer , providesDocumentation = providesDocumentation + , providesHovers = providesHovers , providesDefinitions = providesDefinitions , providesReferences = providesReferences , providesImplementations = providesImplementations); From 50409fe0f5d1ce430d3a665cff315ae169945a7c Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Mon, 14 Oct 2024 17:26:58 +0200 Subject: [PATCH 20/57] forgot to add --- .../src/main/rascal/demo/lang/pico/NewLanguageServer.rsc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc index cd546ceb8..ea565d1b0 100644 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc @@ -46,8 +46,8 @@ set[LanguageService] picoLanguageContributor() = { @synopsis{This set of contributions runs slower but provides more detail.} set[LanguageService] picoLanguageContributorSlowSummary() = { parsing(parser(#start[Program])), - analysis(picoAnalyzer, providesImplementations = false), - build(picoBuilder) + analysis(picoAnalysisService, providesImplementations = false), + build(picoBuildService) }; @synopsis{The documentSymbol service maps pico syntax trees to lists of DocumentSymbols.} From 87f09e6f9c0c17a64dcb7b6ae6c4ac78c0193429 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Mon, 14 Oct 2024 18:04:45 +0200 Subject: [PATCH 21/57] added pitfall --- .../src/main/rascal/demo/lang/pico/NewLanguageServer.rsc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc index ea565d1b0..829c60e6b 100644 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc @@ -104,6 +104,9 @@ Summary picoSummaryService(loc l, start[Program] input, PicoSummarizerMode mode) } @synopsis{Looks up the declaration for any variable use using a list match into a ((Focus))} +@pitfalls{ +This demo actually finds the declaration rather than the definition of a variable in Pico. +} set[loc] picoDefinitionService([*_, Id use, *_, start[Program] input]) = { def.src | /IdType def := input, use := def.id}; @synopsis{If a variable is not defined, we list a fix of fixes to replace it with a defined variable instead.} From 8820535f490c029f02c5c72b7b5872c87236832d Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Mon, 14 Oct 2024 18:55:30 +0200 Subject: [PATCH 22/57] picoLanguageServer not Contribution --- .../main/rascal/demo/lang/pico/NewLanguageServer.rsc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc index 829c60e6b..4215e3566 100644 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc @@ -32,8 +32,8 @@ import ParseTree; import util::Reflective; import lang::pico::\syntax::Main; -@synopsis{Provides each contribution (IDE feature) as a callback element of the set of LanguageServices.} -set[LanguageService] picoLanguageContributor() = { +@synopsis{A language server is simply a set of ((LanguageService))s.} +set[LanguageService] picoLanguageServer() = { parsing(parser(#start[Program])), documentSymbol(picoDocumentSymbolService), codeLens(picoCodeLenseService), @@ -44,7 +44,7 @@ set[LanguageService] picoLanguageContributor() = { }; @synopsis{This set of contributions runs slower but provides more detail.} -set[LanguageService] picoLanguageContributorSlowSummary() = { +set[LanguageService] picoLanguageServerSlowSummary() = { parsing(parser(#start[Program])), analysis(picoAnalysisService, providesImplementations = false), build(picoBuildService) @@ -175,7 +175,7 @@ void main() { "Pico", {"pico", "pico-new"}, "demo::lang::pico::NewLanguageServer", - "picoLanguageContributor" + "picoLanguageServer" ) ); registerLanguage( @@ -184,7 +184,7 @@ void main() { "Pico", {"pico", "pico-new"}, "demo::lang::pico::NewLanguageServer", - "picoLanguageContributorSlowSummary" + "picoLanguageServerSlowSummary" ) ); } From 21a080fb52d85c6a26a2a772d4d06a51b6e4ef6a Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Mon, 14 Oct 2024 18:59:33 +0200 Subject: [PATCH 23/57] more documentation --- rascal-lsp/src/main/rascal/util/LanguageServer.rsc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 0a99d5af0..e2bd5134e 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -49,10 +49,18 @@ import Message; @description{ The ((registerLanguage)) function takes this as its parameter to generate and run a fresh language protocol server. + +* `pcfg` sets up search paths for Rascal modules and libraries required to run the language server +* `name` is the name of the language +* `extensions` are the file extensions that trigger this language server +* `mainModule` is the Rascal module to load to run the language server +* `mainFunction` is a function of type `set[LanguageService] ()` that produces the implementation of the language server +as a independent set of ((LanguageService))s. } @benefits{ * each registered language is run in its own Rascal run-time environment. * reloading a language is always done in a fresh environment. +* instances of ((Language)) can be easily serialized and communicated in interactive language engineering environments. } @pitfalls{ * even though ((registerLanguage)) is called in a given run-time environment, From dfb0bc346012ad238861167072907baf24a3a8c3 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Mon, 14 Oct 2024 21:33:49 +0200 Subject: [PATCH 24/57] added field names for services back in du to bug in interpreter with nameless fields --- .../src/main/rascal/util/LanguageServer.rsc | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index e2bd5134e..f90c4ba90 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -45,17 +45,19 @@ import IO; import ParseTree; import Message; -@synopsis{Definition of a language server by its meta-data} +@synopsis{Definition of a language server by its meta-data.} @description{ The ((registerLanguage)) function takes this as its parameter to generate and run -a fresh language protocol server. +a fresh language protocol server. Every language server is run in its own Rascal execution +environment. The ((Language)) data-type defines the parameters of this run-time, such +that ((registerLanguage)) can boot and initialize new instances. * `pcfg` sets up search paths for Rascal modules and libraries required to run the language server * `name` is the name of the language -* `extensions` are the file extensions that trigger this language server -* `mainModule` is the Rascal module to load to run the language server +* `extensions` are the file extensions that bind this server to editors of files with these extensions. +* `mainModule` is the Rascal module to load to start the language server * `mainFunction` is a function of type `set[LanguageService] ()` that produces the implementation of the language server -as a independent set of ((LanguageService))s. +as a set of collaborating ((LanguageService))s. } @benefits{ * each registered language is run in its own Rascal run-time environment. @@ -232,28 +234,28 @@ typical programming language concepts. Since these are all just `rel[loc, loc]` * `providesDocumentation` is deprecated. Use `providesHovers` instead. } data LanguageService - = parsing(Tree (str _input, loc _origin)) - | analysis(Summary (loc _origin, Tree _input) + = parsing(Tree (str _input, loc _origin) parsingService) + | analysis(Summary (loc _origin, Tree _input) analysisService , bool providesDocumentation = true , bool providesHovers = providesDocumentation , bool providesDefinitions = true , bool providesReferences = true , bool providesImplementations = true) - | build(Summary (loc _origin, Tree _input) + | build(Summary (loc _origin, Tree _input) buildService , bool providesDocumentation = true , bool providesHovers = providesDocumentation , bool providesDefinitions = true , bool providesReferences = true , bool providesImplementations = true) - | documentSymbol(list[DocumentSymbol] (Tree _input)) - | codeLens (lrel[loc src, Command lens] (Tree _input)) - | inlayHint (list[InlayHint] (Tree _input)) - | execution (value (Command _command)) - | hover (set[str] (Focus _focus)) - | definition (set[loc] (Focus _focus)) - | references (set[loc] (Focus _focus)) - | implementation(set[loc] (Focus _focus)) - | codeAction (list[CodeAction] (Focus _focus)) + | documentSymbol(list[DocumentSymbol] (Tree _input) documentSymbolService) + | codeLens (lrel[loc src, Command lens] (Tree _input) codeLensService) + | inlayHint (list[InlayHint] (Tree _input) inlayHintService) + | execution (value (Command _command) executionService) + | hover (set[str] (Focus _focus) hoverService) + | definition (set[loc] (Focus _focus) definitionService) + | references (set[loc] (Focus _focus) referencesService) + | implementation(set[loc] (Focus _focus) implementationService) + | codeAction (list[CodeAction] (Focus _focus) codeActionService) ; @deprecated{Backward compatible with `parsing`} From 5c37e7a0035d69224e288e65892308c0b54b9689 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Mon, 14 Oct 2024 22:09:08 +0200 Subject: [PATCH 25/57] renamed outline to DocumentSymbols for Rascal as well --- .../rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java | 4 ++-- .../lang/rascal/lsp/{Outline.rsc => DocumentSymbols.rsc} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename rascal-lsp/src/main/rascal/lang/rascal/lsp/{Outline.rsc => DocumentSymbols.rsc} (97%) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java index 2ace1ba1d..31688f0f9 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java @@ -97,7 +97,7 @@ public RascalLanguageServices(RascalTextDocumentService docService, BaseWorkspac var monitor = new RascalLSPMonitor(client, logger); - outlineEvaluator = makeFutureEvaluator(exec, docService, workspaceService, client, "Rascal outline", monitor, null, false, "lang::rascal::lsp::Outline"); + outlineEvaluator = makeFutureEvaluator(exec, docService, workspaceService, client, "Rascal outline", monitor, null, false, "lang::rascal::lsp::DocumentSymbols"); semanticEvaluator = makeFutureEvaluator(exec, docService, workspaceService, client, "Rascal semantics", monitor, null, true, "lang::rascalcore::check::Summary", "lang::rascal::lsp::refactor::Rename"); compilerEvaluator = makeFutureEvaluator(exec, docService, workspaceService, client, "Rascal compiler", monitor, null, true, "lang::rascalcore::check::Checker"); } @@ -188,7 +188,7 @@ public InterruptibleFuture getOutline(IConstructor module) { }); } - return runEvaluator("Rascal outline", outlineEvaluator, eval -> (IList) eval.call("outlineRascalModule", module), + return runEvaluator("Rascal Document Symbols", outlineEvaluator, eval -> (IList) eval.call("documentRascalSymbols", module), VF.list(), exec, false, client); } diff --git a/rascal-lsp/src/main/rascal/lang/rascal/lsp/Outline.rsc b/rascal-lsp/src/main/rascal/lang/rascal/lsp/DocumentSymbols.rsc similarity index 97% rename from rascal-lsp/src/main/rascal/lang/rascal/lsp/Outline.rsc rename to rascal-lsp/src/main/rascal/lang/rascal/lsp/DocumentSymbols.rsc index d7c6a91c4..55f8a63f9 100644 --- a/rascal-lsp/src/main/rascal/lang/rascal/lsp/Outline.rsc +++ b/rascal-lsp/src/main/rascal/lang/rascal/lsp/DocumentSymbols.rsc @@ -25,14 +25,14 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. } @bootstrapParser -module lang::rascal::lsp::Outline +module lang::rascal::lsp::DocumentSymbols import String; import ParseTree; import lang::rascal::\syntax::Rascal; import util::LanguageServer; -list[DocumentSymbol] outlineRascalModule(start[Module] \mod) { +list[DocumentSymbol] documentRascalSymbols(start[Module] \mod) { m= \mod.top; children = []; From 1c317c6e0d8e1846464b6ff9479cb06377d1bdfb Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Tue, 15 Oct 2024 09:32:19 +0200 Subject: [PATCH 26/57] added backward compatibility wrapper for the Summary.documentation field --- .../vscode/lsp/parametric/model/ParametricSummary.java | 10 ++++++++++ .../vscode/lsp/parametric/model/RascalADTs.java | 1 + 2 files changed, 11 insertions(+) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java index 54b004ebb..26b8371cc 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java @@ -267,6 +267,16 @@ public class FullScheduledSummary extends MessagesOnlyScheduledSummary { public FullScheduledSummary(InterruptibleFuture calculation) { super(calculation); + + // for temporary backward compatibility between SummaryFields.DOCUMENTATION and SummaryFields.DEPRECATED_DOCUMENTATION + calculation = calculation.thenApply(summary -> { + var kws = summary.asWithKeywordParameters(); + if (kws.hasParameter(SummaryFields.DEPRECATED_DOCUMENTATION) && !kws.hasParameter(SummaryFields.DOCUMENTATION)) { + return kws.setParameter(SummaryFields.DOCUMENTATION, kws.getParameter(SummaryFields.DEPRECATED_DOCUMENTATION)); + } + return summary; + }); + this.documentation = config.providesDocumentation ? mapCalculation(SummaryFields.DOCUMENTATION, calculation, SummaryFields.DOCUMENTATION, ParametricSummaryFactory::mapValueToString) : null; this.definitions = config.providesDefinitions ? diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java index 89f8284ee..fd6a1e6e1 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java @@ -59,6 +59,7 @@ private Summarizers() {} public static class SummaryFields { private SummaryFields() {} + public static final String DEPRECATED_DOCUMENTATION = "documentation"; public static final String DOCUMENTATION = "hovers"; public static final String DEFINITIONS = "definitions"; public static final String REFERENCES = "references"; From ef7a3fff1924bf3df834ddb86b18cad3e16871d8 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Tue, 15 Oct 2024 09:41:49 +0200 Subject: [PATCH 27/57] fixed new broken links in docs --- rascal-lsp/src/main/rascal/util/LanguageServer.rsc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index f90c4ba90..917d27ae5 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -184,7 +184,7 @@ hover documentation, definition with uses, references to declarations, implement * Warning: ((util::LanguageServer::build))s are _not_ triggered when a file changes on disk outside of VS Code; instead, this results in a change event (not a save event), which triggers the ((analyzer)). * If `providesDocumentation` is false, then the ((hover)) service may be activated. Same for `providesDefinitions` and `providesDocumentation` )) -* the following contributions are _on-demand_ (pull) versions of information also provided by the ((analysis)) and ((build)) summaries. +* the following contributions are _on-demand_ (pull) versions of information also provided by the ((analysis)) and ((util::LanguageServer::build)) summaries. * you can provide these more lightweight on-demand services _instead of_ the ((Summary)) versions. * these functions are run synchronously after a user interaction. The run-time of each service corresponds directly to the UX response time. * a ((hover)) service is a fast and location specific version of the `documentation` relation in a ((Summary)). @@ -192,7 +192,7 @@ hover documentation, definition with uses, references to declarations, implement * a ((references)) service is a fast and location specific version of the `references` relation in a ((Summary)). * an ((implementation)) service is a fast and location specific version of the `implementations` relation in a ((Summary)). * The ((documentSymbol)) service maps a source file to a pretty hierarchy for visualization in the "outline" view and "symbol search" features. -* The ((codeLense)) service discovers places to add "lenses" (little views embedded in the editor on a separate line) and connects commands to execute to each lense +* The ((codeLens)) service discovers places to add "lenses" (little views embedded in the editor on a separate line) and connects commands to execute to each lense * The ((inlayHint)) service discovers plances to add "inlays" (little views embedded in the editor on the same line). Unlike ((lenses)) inlays do not offer command execution. * The ((execution)) service executes the commands registered by ((lenses)) and ((inlayHinter))s. * The ((actions)) service discovers places in the editor to add "code actions" (little hints in the margin next to where the action is relevant) and connects ((CodeAction))s to execute when the users selects the action from a menu. @@ -211,7 +211,7 @@ lookup services. Each of those four services require the same information that i your own ((CodeAction))s and ((Commands)) * create an ((execution)) service to give semantics to each command. This includes creating ((DocumentEdit))s but also ((IDEServices)) can be used to have interesting effects in the IDE. - * ((CodeAction))s can also be attached to error, warning and into ((Message))s as a result of ((parsing)), ((analysis)) or ((build)). + * ((CodeAction))s can also be attached to error, warning and into ((Message))s as a result of ((parsing)), ((analysis)) or ((util::LanguageServer::build)). Such actions will lead to "quick-fix" UX options in the editor. } @benefits{ @@ -226,7 +226,7 @@ and (de)serialization and scheduling is taken care of. @pitfalls{ * If one of the services does not type-check in Rascal, or throws an exception at ((registerLanguage)) time, the extension fails completely. Typically the editor produces a parse error on the first line of the code. The failure is printed in the log window of the IDE. -* Users have expectations with the concepts of ((references)), ((definitions)), ((implementation)) which are based on +* Users have expectations with the concepts of ((references)), ((definition)), ((implementation)) which are based on typical programming language concepts. Since these are all just `rel[loc, loc]` it can be easy to confound them. * ((references)) point from declarations sites to use sites * ((definition)) points the other way around, from a use to the declaration, but only if a value is associated there explicitly or implicitly. From 5ecaff1e693a170be71ca2359cc59f125d27d8ba Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Tue, 15 Oct 2024 15:04:37 +0200 Subject: [PATCH 28/57] improved links in docs --- .../src/main/rascal/util/LanguageServer.rsc | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 917d27ae5..e7d542d12 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -258,43 +258,43 @@ data LanguageService | codeAction (list[CodeAction] (Focus _focus) codeActionService) ; -@deprecated{Backward compatible with `parsing`} -@synopsis{Construct a `parsing` LanguageService} +@deprecated{Backward compatible with ((parsing)).} +@synopsis{Construct a `parsing` ((LanguageService))} LanguageService parser(Parser parser) = parsing(parser); -@deprecated{Backward compatible with `codeLense`} -@synopsis{Construct a `codeLense` LanguageService} +@deprecated{Backward compatible with ((codeLens))} +@synopsis{Construct a ((codeLens)) ((LanguageService))} @description{ Not only translates to the old name of the LanguageService, it also maps the list to an arbitrarily ordered set as it was before. } @benefits{ * If you need your lenses in a stable order in the editor, -use the `codeLense` constructor instead to provide a function that +use the ((codeLens)) constructor instead to provide a function that uses an ordered list. } LanguageService lenses(LensDetector detector) = codeLens(lrel[loc src, Command lens] (Tree input) { return [*detector(input)]; }); -@deprecated{Backward compatible with `action`} -@synopsis{Construct a `lense` LanguageService} +@deprecated{Backward compatible with ((codeAction))} +@synopsis{Construct a ((codeAction)) ((LanguageService))} LanguageService actions(CodeActionContributor contributor) = codeAction(contributor); -@deprecated{Backward compatible with `build`} -@synopsis{Construct a `build` LanguageService} +@deprecated{Backward compatible with ((util::LanguageServer::build))} +@synopsis{Construct a ((util::LanguageServer::build)) ((LanguageService))} LanguageService builder(Summarizer summarizer) = build(summarizer); -@deprecated{Backward compatible with `documentSymbol`} -@synopsis{Construct a `build` LanguageService} +@deprecated{Backward compatible with ((documentSymbol))} +@synopsis{Construct a ((documentSymbol)) ((LanguageService))} LanguageService outliner(Outliner outliner) = documentSymbol(outliner); -@deprecated{Backward compatible with `inlays`} -@synopsis{Construct a `inlays` LanguageService} +@deprecated{Backward compatible with ((inlayHint))} +@synopsis{Construct a ((inlayHint)) ((LanguageService))} LanguageService inlayHinter(InlayHinter hinter) = inlayHint(hinter); -@deprecated{Backward compatible with `execution`} -@synopsis{Construct a `execution` LanguageService} +@deprecated{Backward compatible with ((execution))} +@synopsis{Construct a ((execution)) ((LanguageService))} LanguageService executor(CommandExecutor executor) = execution(executor); @deprecated{ From dded43848c14cbc529b54591e81fd95f1433a805 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Tue, 15 Oct 2024 15:16:34 +0200 Subject: [PATCH 29/57] minor fix --- rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc index 0533dcff9..1ac8bfdf6 100644 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc @@ -57,7 +57,6 @@ list[DocumentSymbol] picoOutliner(start[Program] input) *[symbol("", \variable(), var.src) | /IdType var := input] ])]; - @synopsis{The analyzer maps pico syntax trees to error messages and references} Summary picoAnalyzer(loc l, start[Program] input) = picoSummarizer(l, input, analyze()); @@ -107,7 +106,7 @@ Summary picoSummarizer(loc l, start[Program] input, PicoSummarizerMode mode) { @synopsis{Looks up the declaration for any variable use using the / deep match} set[loc] lookupDef(loc _, start[Program] input, Tree cursor) = - { d.src | /IdType d := input, cursor := d.id}; + {d.src | /IdType d := input, cursor := d.id}; @synopsis{If a variable is not defined, we list a fix of fixes to replace it with a defined variable instead.} list[CodeAction] prepareNotDefinedFixes(loc src, rel[str, loc] defs) From 7c3b87ac0cb2b241c5eaab77aef57800d457ed15 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Tue, 15 Oct 2024 15:20:33 +0200 Subject: [PATCH 30/57] improved documentation for compatibility layer --- .../src/main/rascal/util/LanguageServer.rsc | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index e7d542d12..0d9106b89 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -300,7 +300,7 @@ LanguageService executor(CommandExecutor executor) = execution(executor); @deprecated{ This is a backward compatibility layer for the pre-existing ((Documenter)) alias. -To replace an old-style ((Documenter)) with a new style ((FocusDocumenter)) follow +To replace an old-style ((Documenter)) with a new style ((hover)) service follow this scheme: ```rascal @@ -308,11 +308,11 @@ set[loc] oldDocumenter(loc document, Tree selection, Tree fullTree) { ... } // by this scheme: -set[loc] newDocumenter([Tree selection, *Tree _spine, Tree fullTree]) { +set[loc] newHoverService([Tree selection, *Tree _spine, Tree fullTree]) { loc document = selection@\loc.top; ... } -default set[loc] newDocumenter(list[Tree] _focus) = {}; +default set[loc] newHoverService(list[Tree] _focus) = {}; ``` } LanguageService documenter(Documenter d) { @@ -327,11 +327,10 @@ LanguageService documenter(Documenter d) { return hover(focusAcceptor); } - @deprecated{ This is a backward compatibility layer for the pre-existing ((Definer)) alias. -To replace an old-style ((Definer)) with a new style ((FocusDefiner)) follow +To replace an old-style ((Definer)) with a new style ((definition)) service follow this scheme: ```rascal @@ -339,11 +338,11 @@ set[loc] oldDefiner(loc document, Tree selection, Tree fullTree) { ... } // by this scheme: -set[loc] newDefiner([Tree selection, *Tree _spine, Tree fullTree]) { +set[loc] newDefinitionService([Tree selection, *Tree _spine, Tree fullTree]) { loc document = selection@\loc.top; ... } -default set[loc] newDefiner(list[Tree] _focus) = {}; +default set[loc] newDefinitionService(list[Tree] _focus) = {}; ``` } LanguageService definer(Definer d) { @@ -363,7 +362,7 @@ LanguageService definer(Definer d) { @deprecated{ This is a backward compatibility layer for the pre-existing ((Referrer)) alias. -To replace an old-style ((Referrer)) with a new style ((FocusReferrer)) follow +To replace an old-style ((Referrer)) with a new style ((references)) service follow this scheme. ```rascal @@ -371,11 +370,11 @@ set[loc] oldReferrer(loc document, Tree selection, Tree fullTree) { ... } // by this scheme: -set[loc] newReferrer([Tree selection, *Tree _spine, Tree fullTree]) { +set[loc] newReferencesService([Tree selection, *Tree _spine, Tree fullTree]) { loc document = selection@\loc.top; ... } -default set[loc] newReferrer(list[Tree] _focus) = {}; +default set[loc] newReferencesService(list[Tree] _focus) = {}; ``` } LanguageService referrer(Referrer d) { @@ -394,7 +393,7 @@ LanguageService referrer(Referrer d) { @deprecated{ This is a backward compatibility layer for the pre-existing ((Implementer)) alias. -To replace an old-style ((Implementer)) with a new style ((FocusImplementer)) follow +To replace an old-style ((Implementer)) with a new style ((implementation)) service follow this scheme: ```rascal @@ -402,10 +401,12 @@ set[loc] oldImplementer(loc document, Tree selection, Tree fullTree) { ... } // by this scheme: -set[loc] newImplementer([Tree selection, *Tree _spine, Tree fullTree]) { +set[loc] newImplementationService([Tree selection, *Tree _spine, Tree fullTree]) { loc document = selection@\loc.top; ... } +default set[loc] newImplementationService(list[Tree] _focus) = {}; + ``` } LanguageService implementer(Implementer d) { From ffb9e4f0ede0864b6f2db53da0cbe7a90fb43593 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Tue, 15 Oct 2024 15:35:21 +0200 Subject: [PATCH 31/57] fixed another typo --- .../org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java index fd6a1e6e1..5d714ea49 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java @@ -37,7 +37,7 @@ private LanguageContributions () {} public static final String ANALYZER = "analysis"; public static final String BUILDER = "build"; public static final String OUTLINER = "documentSymbol"; - public static final String LENS_DETECTOR = "codeLense"; + public static final String LENS_DETECTOR = "codeLens"; public static final String INLAY_HINTER = "inlayHint"; public static final String COMMAND_EXECUTOR = "execution"; public static final String DOCUMENTER = "hover"; From 09ae6d76da21243d779ea0a792b58ef9280cffff Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Tue, 15 Oct 2024 15:53:18 +0200 Subject: [PATCH 32/57] docs --- .../demo/lang/pico/NewLanguageServer.rsc | 15 +++++++++++++++ .../src/main/rascal/util/LanguageServer.rsc | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc index 4215e3566..3496adbf4 100644 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc @@ -24,6 +24,7 @@ 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{Demonstrates the latest API for defining and registering IDE features for Programming Languages and Domain Specific Languages.} module demo::lang::pico::NewLanguageServer import util::LanguageServer; @@ -33,6 +34,11 @@ import util::Reflective; import lang::pico::\syntax::Main; @synopsis{A language server is simply a set of ((LanguageService))s.} +@description{ +Each ((LanguageService)) for pico is implemented as a function. +Here we group all services such that the LSP server can link them +with the ((Language)) definition later. +} set[LanguageService] picoLanguageServer() = { parsing(parser(#start[Program])), documentSymbol(picoDocumentSymbolService), @@ -44,6 +50,11 @@ set[LanguageService] picoLanguageServer() = { }; @synopsis{This set of contributions runs slower but provides more detail.} +@description{ +((LanguageService))s can be registered asynchronously and incrementally, +such that quicky loaded features can be made available while slower to load +tools come in later. +} set[LanguageService] picoLanguageServerSlowSummary() = { parsing(parser(#start[Program])), analysis(picoAnalysisService, providesImplementations = false), @@ -51,6 +62,10 @@ set[LanguageService] picoLanguageServerSlowSummary() = { }; @synopsis{The documentSymbol service maps pico syntax trees to lists of DocumentSymbols.} +@description{ +Here we list the symbols we want in the outline view, and which can be searched using +symbol search in the editor. +} list[DocumentSymbol] picoDocumentSymbolService(start[Program] input) = [symbol("", DocumentSymbolKind::\file(), input.src, children=[ *[symbol("", \variable(), var.src) | /IdType var := input] diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 0d9106b89..869491254 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -724,3 +724,22 @@ void unregisterLanguage(str name, set[str] extensions, str mainModule = "", str void unregisterLanguage(str name, str extension, str mainModule = "", str mainFunction = "") { unregisterLanguage(name, {extension}, mainModule = mainModule, mainFunction = mainFunction); } + +@javaClass{org.rascalmpl.vscode.lsp.parametric.RascalInterface} +@synopsis{Produce a ((Focus)) for a given tree and cursor position} +@description{ +This function exists to be able to unit test ((LanguageService))s that +accept a ((Focus)) parameter, indepently of using ((registerLanguage)). + +* `line` is a 1-based indication of what the current line is +* `column` is a 0-based indication of what the current column is. +} +@benefits{ +* test services without spinning up an LSP server or having to run UI tests. +Each UI interaction is tested generically for you already. +} +@pitfalls{ +* LSP indexing is different, but those differences are resolved in the implementation of the protocol. On the Rascal side, we see the above. +Differences are width of the character encoding for non-ASCII characters, and lines are 0-based, etc. +} +java Focus computeFocusList(Tree input, int line, int column); From b22c8544c602fc91c6ca3eb7cd89530028123a73 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Tue, 15 Oct 2024 15:53:39 +0200 Subject: [PATCH 33/57] added computeFocusList for testing purposes --- .../lsp/parametric/ParametricTextDocumentService.java | 2 +- .../rascalmpl/vscode/lsp/parametric/RascalInterface.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java index ba5f53e55..a4691fa6e 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java @@ -637,7 +637,7 @@ public CompletableFuture>> codeAction(CodeActio private CompletableFuture computeCodeActions(final ILanguageContributions contribs, final int startLine, final int startColumn, ITree tree) { IList focus = TreeSearch.computeFocusList(tree, startLine, startColumn); - + if (!focus.isEmpty()) { return contribs.codeActions(focus).get(); } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/RascalInterface.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/RascalInterface.java index 99849f449..7192ca845 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/RascalInterface.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/RascalInterface.java @@ -27,8 +27,11 @@ package org.rascalmpl.vscode.lsp.parametric; import org.rascalmpl.ideservices.IDEServices; +import org.rascalmpl.values.parsetrees.ITree; +import org.rascalmpl.vscode.lsp.util.locations.impl.TreeSearch; import io.usethesource.vallang.IConstructor; +import io.usethesource.vallang.IList; import io.usethesource.vallang.ISourceLocation; /** @@ -53,4 +56,8 @@ public void unregisterLanguage(IConstructor lang) { public ISourceLocation resolveProjectLocation(ISourceLocation project) { return services.resolveProjectLocation(project); } + + public IList computeFocusList(ITree input, int line, int column) { + return TreeSearch.computeFocusList(input, line, column); + } } From e80b8f11a32bac044e2cb1a12b1ea2997b2065c7 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Tue, 15 Oct 2024 16:14:53 +0200 Subject: [PATCH 34/57] fixed interface of computeFocusList --- .../org/rascalmpl/vscode/lsp/parametric/RascalInterface.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/RascalInterface.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/RascalInterface.java index 7192ca845..afaf6569b 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/RascalInterface.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/RascalInterface.java @@ -31,6 +31,7 @@ import org.rascalmpl.vscode.lsp.util.locations.impl.TreeSearch; import io.usethesource.vallang.IConstructor; +import io.usethesource.vallang.IInteger; import io.usethesource.vallang.IList; import io.usethesource.vallang.ISourceLocation; @@ -57,7 +58,7 @@ public ISourceLocation resolveProjectLocation(ISourceLocation project) { return services.resolveProjectLocation(project); } - public IList computeFocusList(ITree input, int line, int column) { - return TreeSearch.computeFocusList(input, line, column); + public IList computeFocusList(IConstructor input, IInteger line, IInteger column) { + return TreeSearch.computeFocusList((ITree) input, line.intValue(), column.intValue()); } } From c4a4204cd85d17f55c85e4c29d6c4a6e06729b3e Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Wed, 16 Oct 2024 09:40:04 +0200 Subject: [PATCH 35/57] log string improved --- .../vscode/lsp/parametric/ParametricTextDocumentService.java | 2 +- .../rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java index a4691fa6e..4edea7dcf 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java @@ -571,7 +571,7 @@ public CompletableFuture semanticTokensRange(SemanticTokensRange @Override public CompletableFuture>>documentSymbol(DocumentSymbolParams params) { - logger.debug("Outline/documentSymbols: {}", params.getTextDocument()); + logger.debug("Outline/documentSymbol: {}", params.getTextDocument()); final TextDocumentState file = getFile(params.getTextDocument()); ILanguageContributions contrib = contributions(params.getTextDocument()); diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java index 5e41f55ad..c10163f5b 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java @@ -263,7 +263,7 @@ public CompletableFuture, List>> documentSymbol(DocumentSymbolParams params) { - logger.debug("Outline/documentSymbols: {}", params.getTextDocument()); + logger.debug("Outline/documentSymbol: {}", params.getTextDocument()); TextDocumentState file = getFile(params.getTextDocument()); return file.getCurrentTreeAsync() .thenApply(Versioned::get) From f386f58b0256feb1c9d451d009bbdb43fbd4a9c1 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Thu, 17 Oct 2024 09:45:28 +0200 Subject: [PATCH 36/57] Rename methods in `ILanguageContributions` to be consistent with LSP --- .../parametric/ILanguageContributions.java | 58 ++++----- .../InterpretedLanguageContributions.java | 46 +++---- .../LanguageContributionsMultiplexer.java | 116 +++++++++--------- .../ParametricTextDocumentService.java | 12 +- .../parametric/ParserOnlyContribution.java | 46 +++---- .../parametric/model/ParametricFileFacts.java | 4 +- .../parametric/model/ParametricSummary.java | 10 +- 7 files changed, 146 insertions(+), 146 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java index d3df7a242..f65efbe9a 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java @@ -46,49 +46,50 @@ public interface ILanguageContributions { public String getName(); - public CompletableFuture parseSourceFile(ISourceLocation loc, String input); - public InterruptibleFuture outline(ITree input); - public InterruptibleFuture analyze(ISourceLocation loc, ITree input); - public InterruptibleFuture build(ISourceLocation loc, ITree input); - public InterruptibleFuture lenses(ITree input); - public InterruptibleFuture<@Nullable IValue> executeCommand(String command); + public CompletableFuture runParsingService(ISourceLocation loc, String input); + public InterruptibleFuture runAnalysisService(ISourceLocation loc, ITree input); + public InterruptibleFuture runBuildService(ISourceLocation loc, ITree input); + public InterruptibleFuture runDocumentSymbolService(ITree input); + public InterruptibleFuture runCodeLensService(ITree input); + public InterruptibleFuture runInlayHintService(@Nullable ITree input); + public InterruptibleFuture<@Nullable IValue> runExecutionService(String command); + public InterruptibleFuture runHoverService(IList focus); + public InterruptibleFuture runDefinitionService(IList focus); + public InterruptibleFuture runReferencesService(IList focus); + public InterruptibleFuture runImplementationService(IList focus); + public InterruptibleFuture runCodeActionService(IList focus); + public CompletableFuture parseCodeActions(String command); - public InterruptibleFuture inlayHint(@Nullable ITree input); - public InterruptibleFuture documentation(IList focus); - public InterruptibleFuture definitions(IList focus); - public InterruptibleFuture references(IList focus); - public InterruptibleFuture implementations(IList focus); - public InterruptibleFuture codeActions(IList focus); - - public CompletableFuture hasAnalyzer(); - public CompletableFuture hasBuilder(); - public CompletableFuture hasOutliner(); - public CompletableFuture hasLensDetector(); - public CompletableFuture hasInlayHinter(); - public CompletableFuture hasCommandExecutor(); - public CompletableFuture hasDocumenter(); - public CompletableFuture hasDefiner(); - public CompletableFuture hasReferrer(); - public CompletableFuture hasImplementer(); - public CompletableFuture hasCodeActionsContributor(); + + public CompletableFuture hasAnalysisService(); + public CompletableFuture hasBuildService(); + public CompletableFuture hasDocumentSymbolService(); + public CompletableFuture hasCodeLensDetector(); + public CompletableFuture hasInlayHintService(); + public CompletableFuture hasExecutionService(); + public CompletableFuture hasHoverService(); + public CompletableFuture hasDefinitionService(); + public CompletableFuture hasReferencesService(); + public CompletableFuture hasImplementationService(); + public CompletableFuture hasCodeActionService(); public CompletableFuture getAnalyzerSummaryConfig(); public CompletableFuture getBuilderSummaryConfig(); public CompletableFuture getOndemandSummaryConfig(); public static class SummaryConfig { - public final boolean providesDocumentation; + public final boolean providesHovers; public final boolean providesDefinitions; public final boolean providesReferences; public final boolean providesImplementations; public SummaryConfig( - boolean providesDocumentation, + boolean providesHovers, boolean providesDefinitions, boolean providesReferences, boolean providesImplementations) { - this.providesDocumentation = providesDocumentation; + this.providesHovers = providesHovers; this.providesDefinitions = providesDefinitions; this.providesReferences = providesReferences; this.providesImplementations = providesImplementations; @@ -98,14 +99,13 @@ public SummaryConfig( public static SummaryConfig or(SummaryConfig a, SummaryConfig b) { return new SummaryConfig( - a.providesDocumentation || b.providesDocumentation, + a.providesHovers || b.providesHovers, a.providesDefinitions || b.providesDefinitions, a.providesReferences || b.providesReferences, a.providesImplementations || b.providesImplementations); } } - @FunctionalInterface // Type alias to conveniently pass methods `analyze`and `build` as parameters public static interface ScheduledCalculator extends BiFunction> {} diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java index 034c91034..07f001a84 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java @@ -257,67 +257,67 @@ public String getName() { } @Override - public CompletableFuture parseSourceFile(ISourceLocation loc, String input) { + public CompletableFuture runParsingService(ISourceLocation loc, String input) { debug(LanguageContributions.PARSER, loc, input); return parser.thenApplyAsync(p -> p.call(VF.string(input), loc), exec); } @Override - public InterruptibleFuture outline(ITree input) { + public InterruptibleFuture runDocumentSymbolService(ITree input) { debug(LanguageContributions.OUTLINER, TreeAdapter.getLocation(input)); return execFunction(LanguageContributions.OUTLINER, outliner, VF.list(), input); } @Override - public InterruptibleFuture analyze(ISourceLocation src, ITree input) { + public InterruptibleFuture runAnalysisService(ISourceLocation src, ITree input) { debug(LanguageContributions.ANALYZER, src); return execFunction(LanguageContributions.ANALYZER, analyzer, EmptySummary.newInstance(src), src, input); } @Override - public InterruptibleFuture build(ISourceLocation src, ITree input) { + public InterruptibleFuture runBuildService(ISourceLocation src, ITree input) { debug(LanguageContributions.BUILDER, src); return execFunction(LanguageContributions.BUILDER, builder, EmptySummary.newInstance(src), src, input); } @Override - public InterruptibleFuture lenses(ITree input) { + public InterruptibleFuture runCodeLensService(ITree input) { debug(LanguageContributions.LENS_DETECTOR, TreeAdapter.getLocation(input)); return execFunction(LanguageContributions.LENS_DETECTOR, lenses, VF.list(), input); } @Override - public InterruptibleFuture inlayHint(@Nullable ITree input) { + public InterruptibleFuture runInlayHintService(@Nullable ITree input) { debug(LanguageContributions.INLAY_HINTER, input != null ? TreeAdapter.getLocation(input) : null); return execFunction(LanguageContributions.INLAY_HINTER, inlayHinter, VF.list(), input); } @Override - public InterruptibleFuture documentation(IList focus) { + public InterruptibleFuture runHoverService(IList focus) { debug(LanguageContributions.DOCUMENTER, focus.length()); return execFunction(LanguageContributions.DOCUMENTER, documenter, VF.set(), focus); } @Override - public InterruptibleFuture definitions(IList focus) { + public InterruptibleFuture runDefinitionService(IList focus) { debug(LanguageContributions.DEFINER, focus.length()); return execFunction(LanguageContributions.DEFINER, definer, VF.set(), focus); } @Override - public InterruptibleFuture implementations(IList focus) { + public InterruptibleFuture runImplementationService(IList focus) { debug(LanguageContributions.IMPLEMENTER, focus.length()); return execFunction(LanguageContributions.IMPLEMENTER, implementer, VF.set(), focus); } @Override - public InterruptibleFuture references(IList focus) { + public InterruptibleFuture runReferencesService(IList focus) { debug(LanguageContributions.REFERRER, focus.length()); return execFunction(LanguageContributions.REFERRER, referrer, VF.set(), focus); } @Override - public InterruptibleFuture codeActions(IList focus) { + public InterruptibleFuture runCodeActionService(IList focus) { debug(LanguageContributions.CODE_ACTION_CONTRIBUTOR, focus.length()); return execFunction(LanguageContributions.CODE_ACTION_CONTRIBUTOR, codeActionContributor, VF.list(), focus); } @@ -331,57 +331,57 @@ private void debug(String name, Object param1, Object param2) { } @Override - public CompletableFuture hasDefiner() { + public CompletableFuture hasDefinitionService() { return hasDefiner; } @Override - public CompletableFuture hasReferrer() { + public CompletableFuture hasReferencesService() { return hasReferrer; } @Override - public CompletableFuture hasImplementer() { + public CompletableFuture hasImplementationService() { return hasImplementer; } @Override - public CompletableFuture hasDocumenter() { + public CompletableFuture hasHoverService() { return hasDocumenter; } @Override - public CompletableFuture hasCommandExecutor() { + public CompletableFuture hasExecutionService() { return hasCommandExecutor; } @Override - public CompletableFuture hasInlayHinter() { + public CompletableFuture hasInlayHintService() { return hasInlayHinter; } @Override - public CompletableFuture hasLensDetector() { + public CompletableFuture hasCodeLensDetector() { return hasLensDetector; } @Override - public CompletableFuture hasOutliner() { + public CompletableFuture hasDocumentSymbolService() { return hasOutliner; } @Override - public CompletableFuture hasCodeActionsContributor() { + public CompletableFuture hasCodeActionService() { return hasCodeActionContributor; } @Override - public CompletableFuture hasAnalyzer() { + public CompletableFuture hasAnalysisService() { return hasAnalyzer; } @Override - public CompletableFuture hasBuilder() { + public CompletableFuture hasBuildService() { return hasBuilder; } @@ -401,7 +401,7 @@ public CompletableFuture getOndemandSummaryConfig() { } @Override - public InterruptibleFuture<@Nullable IValue> executeCommand(String command) { + public InterruptibleFuture<@Nullable IValue> runExecutionService(String command) { logger.debug("executeCommand({}...) (full command value in TRACE level)", () -> command.substring(0, Math.min(10, command.length()))); logger.trace("Full command: {}", command); diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java index 1dc864736..ebb357776 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java @@ -135,29 +135,29 @@ private synchronized void calculateRouting() { // we calculate the "route" once, and then just chain onto the completed // future parser = firstOrFail(); - outliner = findFirstOrDefault(ILanguageContributions::hasOutliner); - analyzer = findFirstOrDefault(ILanguageContributions::hasAnalyzer); - builder = findFirstOrDefault(ILanguageContributions::hasBuilder); - lensDetector = findFirstOrDefault(ILanguageContributions::hasLensDetector); - commandExecutor = findFirstOrDefault(ILanguageContributions::hasCommandExecutor); - inlayHinter = findFirstOrDefault(ILanguageContributions::hasInlayHinter); - definer = findFirstOrDefault(ILanguageContributions::hasDefiner); - documenter = findFirstOrDefault(ILanguageContributions::hasDocumenter); - referrer = findFirstOrDefault(ILanguageContributions::hasReferrer); - implementer = findFirstOrDefault(ILanguageContributions::hasImplementer); - codeActionContributor = findFirstOrDefault(ILanguageContributions::hasCodeActionsContributor); - - hasDocumenter = anyTrue(ILanguageContributions::hasDocumenter); - hasDefiner = anyTrue(ILanguageContributions::hasDefiner); - hasReferrer = anyTrue(ILanguageContributions::hasReferrer); - hasImplementer = anyTrue(ILanguageContributions::hasImplementer); - - hasOutliner = anyTrue(ILanguageContributions::hasOutliner); - hasAnalyzer = anyTrue(ILanguageContributions::hasAnalyzer); - hasBuilder = anyTrue(ILanguageContributions::hasBuilder); - hasLensDetector = anyTrue(ILanguageContributions::hasLensDetector); - hasCommandExecutor = anyTrue(ILanguageContributions::hasCommandExecutor); - hasInlayHinter = anyTrue(ILanguageContributions::hasInlayHinter); + outliner = findFirstOrDefault(ILanguageContributions::hasDocumentSymbolService); + analyzer = findFirstOrDefault(ILanguageContributions::hasAnalysisService); + builder = findFirstOrDefault(ILanguageContributions::hasBuildService); + lensDetector = findFirstOrDefault(ILanguageContributions::hasCodeLensDetector); + commandExecutor = findFirstOrDefault(ILanguageContributions::hasExecutionService); + inlayHinter = findFirstOrDefault(ILanguageContributions::hasInlayHintService); + definer = findFirstOrDefault(ILanguageContributions::hasDefinitionService); + documenter = findFirstOrDefault(ILanguageContributions::hasHoverService); + referrer = findFirstOrDefault(ILanguageContributions::hasReferencesService); + implementer = findFirstOrDefault(ILanguageContributions::hasImplementationService); + codeActionContributor = findFirstOrDefault(ILanguageContributions::hasCodeActionService); + + hasDocumenter = anyTrue(ILanguageContributions::hasHoverService); + hasDefiner = anyTrue(ILanguageContributions::hasDefinitionService); + hasReferrer = anyTrue(ILanguageContributions::hasReferencesService); + hasImplementer = anyTrue(ILanguageContributions::hasImplementationService); + + hasOutliner = anyTrue(ILanguageContributions::hasDocumentSymbolService); + hasAnalyzer = anyTrue(ILanguageContributions::hasAnalysisService); + hasBuilder = anyTrue(ILanguageContributions::hasBuildService); + hasLensDetector = anyTrue(ILanguageContributions::hasCodeLensDetector); + hasCommandExecutor = anyTrue(ILanguageContributions::hasExecutionService); + hasInlayHinter = anyTrue(ILanguageContributions::hasInlayHintService); analyzerSummaryConfig = anyTrue(ILanguageContributions::getAnalyzerSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); builderSummaryConfig = anyTrue(ILanguageContributions::getBuilderSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); @@ -218,12 +218,12 @@ public String getName() { } @Override - public CompletableFuture parseSourceFile(ISourceLocation loc, String input) { + public CompletableFuture runParsingService(ISourceLocation loc, String input) { var p = parser; if (p == null) { return failedInitialization(); } - return p.parseSourceFile(loc, input); + return p.runParsingService(loc, input); } @@ -232,28 +232,28 @@ private InterruptibleFuture flatten(CompletableFuture outline(ITree input) { - return flatten(outliner, c -> c.outline(input)); + public InterruptibleFuture runDocumentSymbolService(ITree input) { + return flatten(outliner, c -> c.runDocumentSymbolService(input)); } @Override - public InterruptibleFuture analyze(ISourceLocation loc, ITree input) { - return flatten(analyzer, c -> c.analyze(loc, input)); + public InterruptibleFuture runAnalysisService(ISourceLocation loc, ITree input) { + return flatten(analyzer, c -> c.runAnalysisService(loc, input)); } @Override - public InterruptibleFuture build(ISourceLocation loc, ITree input) { - return flatten(builder, c -> c.build(loc, input)); + public InterruptibleFuture runBuildService(ISourceLocation loc, ITree input) { + return flatten(builder, c -> c.runBuildService(loc, input)); } @Override - public InterruptibleFuture lenses(ITree input) { - return flatten(lensDetector, c -> c.lenses(input)); + public InterruptibleFuture runCodeLensService(ITree input) { + return flatten(lensDetector, c -> c.runCodeLensService(input)); } @Override - public InterruptibleFuture<@Nullable IValue> executeCommand(String command) { - return flatten(commandExecutor, c -> c.executeCommand(command)); + public InterruptibleFuture<@Nullable IValue> runExecutionService(String command) { + return flatten(commandExecutor, c -> c.runExecutionService(command)); } @Override @@ -262,87 +262,87 @@ public CompletableFuture parseCodeActions(String command) { } @Override - public InterruptibleFuture inlayHint(@Nullable ITree input) { - return flatten(inlayHinter, c -> c.inlayHint(input)); + public InterruptibleFuture runInlayHintService(@Nullable ITree input) { + return flatten(inlayHinter, c -> c.runInlayHintService(input)); } @Override - public InterruptibleFuture documentation(IList focus) { - return flatten(documenter, c -> c.documentation(focus)); + public InterruptibleFuture runHoverService(IList focus) { + return flatten(documenter, c -> c.runHoverService(focus)); } @Override - public InterruptibleFuture definitions(IList focus) { - return flatten(definer, c -> c.definitions(focus)); + public InterruptibleFuture runDefinitionService(IList focus) { + return flatten(definer, c -> c.runDefinitionService(focus)); } @Override - public InterruptibleFuture references(IList focus) { - return flatten(referrer, c -> c.references(focus)); + public InterruptibleFuture runReferencesService(IList focus) { + return flatten(referrer, c -> c.runReferencesService(focus)); } @Override - public InterruptibleFuture implementations(IList focus) { - return flatten(implementer, c -> c.implementations(focus)); + public InterruptibleFuture runImplementationService(IList focus) { + return flatten(implementer, c -> c.runImplementationService(focus)); } @Override - public InterruptibleFuture codeActions(IList focus) { - return flatten(codeActionContributor, c -> c.codeActions(focus)); + public InterruptibleFuture runCodeActionService(IList focus) { + return flatten(codeActionContributor, c -> c.runCodeActionService(focus)); } @Override - public CompletableFuture hasCodeActionsContributor() { + public CompletableFuture hasCodeActionService() { return hasCodeActionContributor; } @Override - public CompletableFuture hasDocumenter() { + public CompletableFuture hasHoverService() { return hasDocumenter; } @Override - public CompletableFuture hasDefiner() { + public CompletableFuture hasDefinitionService() { return hasDefiner; } @Override - public CompletableFuture hasReferrer() { + public CompletableFuture hasReferencesService() { return hasReferrer; } @Override - public CompletableFuture hasImplementer() { + public CompletableFuture hasImplementationService() { return hasImplementer; } @Override - public CompletableFuture hasOutliner() { + public CompletableFuture hasDocumentSymbolService() { return hasOutliner; } @Override - public CompletableFuture hasAnalyzer() { + public CompletableFuture hasAnalysisService() { return hasAnalyzer; } @Override - public CompletableFuture hasBuilder() { + public CompletableFuture hasBuildService() { return hasBuilder; } @Override - public CompletableFuture hasLensDetector() { + public CompletableFuture hasCodeLensDetector() { return hasLensDetector; } @Override - public CompletableFuture hasCommandExecutor() { + public CompletableFuture hasExecutionService() { return hasCommandExecutor; } @Override - public CompletableFuture hasInlayHinter() { + public CompletableFuture hasInlayHintService() { return hasInlayHinter; } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java index 4edea7dcf..3837cd8bc 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java @@ -328,7 +328,7 @@ public CompletableFuture> codeLens(CodeLensParams param return recoverExceptions(file.getCurrentTreeAsync() .thenApply(Versioned::get) - .thenApply(contrib::lenses) + .thenApply(contrib::runCodeLensService) .thenCompose(InterruptibleFuture::get) .thenApply(s -> s.stream() .map(e -> locCommandTupleToCodeLense(contrib.getName(), e)) @@ -344,7 +344,7 @@ public CompletableFuture> inlayHint(InlayHintParams params) { return recoverExceptions( recoverExceptions(file.getCurrentTreeAsync(), file::getMostRecentTree) .thenApply(Versioned::get) - .thenApply(contrib::inlayHint) + .thenApply(contrib::runInlayHintService) .thenCompose(InterruptibleFuture::get) .thenApply(s -> s.stream() .map(this::rowToInlayHint) @@ -520,7 +520,7 @@ private ParametricFileFacts facts(String doc) { private TextDocumentState open(TextDocumentItem doc) { return files.computeIfAbsent(Locations.toLoc(doc), - l -> new TextDocumentState(contributions(doc)::parseSourceFile, l, doc.getVersion(), doc.getText()) + l -> new TextDocumentState(contributions(doc)::runParsingService, l, doc.getVersion(), doc.getText()) ); } @@ -577,7 +577,7 @@ public CompletableFuture semanticTokensRange(SemanticTokensRange ILanguageContributions contrib = contributions(params.getTextDocument()); return recoverExceptions(file.getCurrentTreeAsync() .thenApply(Versioned::get) - .thenApply(contrib::outline) + .thenApply(contrib::runDocumentSymbolService) .thenCompose(InterruptibleFuture::get) .thenApply(c -> Outline.buildOutline(c, columns.get(file.getLocation()))) , Collections::emptyList); @@ -639,7 +639,7 @@ private CompletableFuture computeCodeActions(final ILanguageContributions IList focus = TreeSearch.computeFocusList(tree, startLine, startColumn); if (!focus.isEmpty()) { - return contribs.codeActions(focus).get(); + return contribs.runCodeActionService(focus).get(); } else { logger.log(Level.DEBUG, "no tree focus found at {}:{}", startLine, startColumn); @@ -778,7 +778,7 @@ public CompletableFuture executeCommand(String languageName, String comm ILanguageContributions contribs = contributions.get(languageName); if (contribs != null) { - return contribs.executeCommand(command).get(); + return contribs.runExecutionService(command).get(); } else { logger.warn("ignoring command execution (no contributor configured for this language): {}, {} ", languageName, command); diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java index 91a68d57a..555317e67 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java @@ -75,7 +75,7 @@ public String getName() { } @Override - public CompletableFuture parseSourceFile(ISourceLocation loc, String input) { + public CompletableFuture runParsingService(ISourceLocation loc, String input) { if (loadingParserError != null || parser == null) { return CompletableFuture.failedFuture(new RuntimeException("Parser function did not load", loadingParserError)); } @@ -114,27 +114,27 @@ private static IConstructor makeReifiedType(ParserSpecification spec, IRascalVal } @Override - public InterruptibleFuture outline(ITree input) { + public InterruptibleFuture runDocumentSymbolService(ITree input) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture analyze(ISourceLocation loc, ITree input) { + public InterruptibleFuture runAnalysisService(ISourceLocation loc, ITree input) { return InterruptibleFuture.completedFuture(EmptySummary.newInstance(loc)); } @Override - public InterruptibleFuture build(ISourceLocation loc, ITree input) { + public InterruptibleFuture runBuildService(ISourceLocation loc, ITree input) { return InterruptibleFuture.completedFuture(EmptySummary.newInstance(loc)); } @Override - public InterruptibleFuture lenses(ITree input) { + public InterruptibleFuture runCodeLensService(ITree input) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture<@Nullable IValue> executeCommand(String command) { + public InterruptibleFuture<@Nullable IValue> runExecutionService(String command) { return InterruptibleFuture.completedFuture(VF.bool(false)); } @@ -144,87 +144,87 @@ public CompletableFuture parseCodeActions(String commands) { } @Override - public InterruptibleFuture inlayHint(@Nullable ITree input) { + public InterruptibleFuture runInlayHintService(@Nullable ITree input) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture documentation(IList focus) { + public InterruptibleFuture runHoverService(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public InterruptibleFuture definitions(IList focus) { + public InterruptibleFuture runDefinitionService(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public InterruptibleFuture references(IList focus) { + public InterruptibleFuture runReferencesService(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public InterruptibleFuture codeActions(IList focus) { + public InterruptibleFuture runCodeActionService(IList focus) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture implementations(IList focus) { + public InterruptibleFuture runImplementationService(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public CompletableFuture hasDocumenter() { + public CompletableFuture hasHoverService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasDefiner() { + public CompletableFuture hasDefinitionService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasReferrer() { + public CompletableFuture hasReferencesService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasImplementer() { + public CompletableFuture hasImplementationService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasOutliner() { + public CompletableFuture hasDocumentSymbolService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasAnalyzer() { + public CompletableFuture hasAnalysisService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasBuilder() { + public CompletableFuture hasBuildService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasCodeActionsContributor() { + public CompletableFuture hasCodeActionService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasLensDetector() { + public CompletableFuture hasCodeLensDetector() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasCommandExecutor() { + public CompletableFuture hasExecutionService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasInlayHinter() { + public CompletableFuture hasInlayHintService() { return CompletableFuture.completedFuture(false); } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java index be1ab0eaf..e1adc0bdf 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java @@ -114,9 +114,9 @@ private FileFact getFile(ISourceLocation l) { public void reloadContributions() { analyzerSummaryFactory = contrib.getAnalyzerSummaryConfig().thenApply(config -> - new ScheduledSummaryFactory(config, exec, columns, contrib::analyze)); + new ScheduledSummaryFactory(config, exec, columns, contrib::runAnalysisService)); builderSummaryFactory = contrib.getBuilderSummaryConfig().thenApply(config -> - new ScheduledSummaryFactory(config, exec, columns, contrib::build)); + new ScheduledSummaryFactory(config, exec, columns, contrib::runBuildService)); ondemandSummaryFactory = contrib.getOndemandSummaryConfig().thenApply(config -> new OndemandSummaryFactory(config, exec, columns, contrib)); } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java index 26b8371cc..20d286c51 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java @@ -277,7 +277,7 @@ public FullScheduledSummary(InterruptibleFuture calculation) { return summary; }); - this.documentation = config.providesDocumentation ? + this.documentation = config.providesHovers ? mapCalculation(SummaryFields.DOCUMENTATION, calculation, SummaryFields.DOCUMENTATION, ParametricSummaryFactory::mapValueToString) : null; this.definitions = config.providesDefinitions ? mapCalculation(SummaryFields.DEFINITIONS, calculation, SummaryFields.DEFINITIONS, locationMapper(columns)) : null; @@ -435,22 +435,22 @@ public OndemandSummary(ISourceLocation file, Versioned tree, Position cur @Override @SuppressWarnings("deprecation") // For `MarkedString` public @Nullable InterruptibleFuture>> getDocumentation(Position cursor) { - return get(config.providesDocumentation, cursor, contrib::documentation, ParametricSummaryFactory::mapValueToString, SummaryFields.DOCUMENTATION); + return get(config.providesHovers, cursor, contrib::runHoverService, ParametricSummaryFactory::mapValueToString, SummaryFields.DOCUMENTATION); } @Override public @Nullable InterruptibleFuture> getDefinitions(Position cursor) { - return get(config.providesDefinitions, cursor, contrib::definitions, locationMapper(columns), SummaryFields.DEFINITIONS); + return get(config.providesDefinitions, cursor, contrib::runDefinitionService, locationMapper(columns), SummaryFields.DEFINITIONS); } @Override public @Nullable InterruptibleFuture> getReferences(Position cursor) { - return get(config.providesReferences, cursor, contrib::references, locationMapper(columns), SummaryFields.REFERENCES); + return get(config.providesReferences, cursor, contrib::runReferencesService, locationMapper(columns), SummaryFields.REFERENCES); } @Override public @Nullable InterruptibleFuture> getImplementations(Position cursor) { - return get(config.providesImplementations, cursor, contrib::implementations, locationMapper(columns), SummaryFields.IMPLEMENTATIONS); + return get(config.providesImplementations, cursor, contrib::runImplementationService, locationMapper(columns), SummaryFields.IMPLEMENTATIONS); } @Override From 7e3968e9b8658df61fb8b7860dbe0dfdb287f04f Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Thu, 17 Oct 2024 09:47:04 +0200 Subject: [PATCH 37/57] Revert "Rename methods in `ILanguageContributions` to be consistent with LSP" This reverts commit f386f58b0256feb1c9d451d009bbdb43fbd4a9c1. --- .../parametric/ILanguageContributions.java | 58 ++++----- .../InterpretedLanguageContributions.java | 46 +++---- .../LanguageContributionsMultiplexer.java | 116 +++++++++--------- .../ParametricTextDocumentService.java | 12 +- .../parametric/ParserOnlyContribution.java | 46 +++---- .../parametric/model/ParametricFileFacts.java | 4 +- .../parametric/model/ParametricSummary.java | 10 +- 7 files changed, 146 insertions(+), 146 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java index f65efbe9a..d3df7a242 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java @@ -46,50 +46,49 @@ public interface ILanguageContributions { public String getName(); - public CompletableFuture runParsingService(ISourceLocation loc, String input); - public InterruptibleFuture runAnalysisService(ISourceLocation loc, ITree input); - public InterruptibleFuture runBuildService(ISourceLocation loc, ITree input); - public InterruptibleFuture runDocumentSymbolService(ITree input); - public InterruptibleFuture runCodeLensService(ITree input); - public InterruptibleFuture runInlayHintService(@Nullable ITree input); - public InterruptibleFuture<@Nullable IValue> runExecutionService(String command); - public InterruptibleFuture runHoverService(IList focus); - public InterruptibleFuture runDefinitionService(IList focus); - public InterruptibleFuture runReferencesService(IList focus); - public InterruptibleFuture runImplementationService(IList focus); - public InterruptibleFuture runCodeActionService(IList focus); - + public CompletableFuture parseSourceFile(ISourceLocation loc, String input); + public InterruptibleFuture outline(ITree input); + public InterruptibleFuture analyze(ISourceLocation loc, ITree input); + public InterruptibleFuture build(ISourceLocation loc, ITree input); + public InterruptibleFuture lenses(ITree input); + public InterruptibleFuture<@Nullable IValue> executeCommand(String command); public CompletableFuture parseCodeActions(String command); - - public CompletableFuture hasAnalysisService(); - public CompletableFuture hasBuildService(); - public CompletableFuture hasDocumentSymbolService(); - public CompletableFuture hasCodeLensDetector(); - public CompletableFuture hasInlayHintService(); - public CompletableFuture hasExecutionService(); - public CompletableFuture hasHoverService(); - public CompletableFuture hasDefinitionService(); - public CompletableFuture hasReferencesService(); - public CompletableFuture hasImplementationService(); - public CompletableFuture hasCodeActionService(); + public InterruptibleFuture inlayHint(@Nullable ITree input); + public InterruptibleFuture documentation(IList focus); + public InterruptibleFuture definitions(IList focus); + public InterruptibleFuture references(IList focus); + public InterruptibleFuture implementations(IList focus); + public InterruptibleFuture codeActions(IList focus); + + public CompletableFuture hasAnalyzer(); + public CompletableFuture hasBuilder(); + public CompletableFuture hasOutliner(); + public CompletableFuture hasLensDetector(); + public CompletableFuture hasInlayHinter(); + public CompletableFuture hasCommandExecutor(); + public CompletableFuture hasDocumenter(); + public CompletableFuture hasDefiner(); + public CompletableFuture hasReferrer(); + public CompletableFuture hasImplementer(); + public CompletableFuture hasCodeActionsContributor(); public CompletableFuture getAnalyzerSummaryConfig(); public CompletableFuture getBuilderSummaryConfig(); public CompletableFuture getOndemandSummaryConfig(); public static class SummaryConfig { - public final boolean providesHovers; + public final boolean providesDocumentation; public final boolean providesDefinitions; public final boolean providesReferences; public final boolean providesImplementations; public SummaryConfig( - boolean providesHovers, + boolean providesDocumentation, boolean providesDefinitions, boolean providesReferences, boolean providesImplementations) { - this.providesHovers = providesHovers; + this.providesDocumentation = providesDocumentation; this.providesDefinitions = providesDefinitions; this.providesReferences = providesReferences; this.providesImplementations = providesImplementations; @@ -99,13 +98,14 @@ public SummaryConfig( public static SummaryConfig or(SummaryConfig a, SummaryConfig b) { return new SummaryConfig( - a.providesHovers || b.providesHovers, + a.providesDocumentation || b.providesDocumentation, a.providesDefinitions || b.providesDefinitions, a.providesReferences || b.providesReferences, a.providesImplementations || b.providesImplementations); } } + @FunctionalInterface // Type alias to conveniently pass methods `analyze`and `build` as parameters public static interface ScheduledCalculator extends BiFunction> {} diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java index 07f001a84..034c91034 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java @@ -257,67 +257,67 @@ public String getName() { } @Override - public CompletableFuture runParsingService(ISourceLocation loc, String input) { + public CompletableFuture parseSourceFile(ISourceLocation loc, String input) { debug(LanguageContributions.PARSER, loc, input); return parser.thenApplyAsync(p -> p.call(VF.string(input), loc), exec); } @Override - public InterruptibleFuture runDocumentSymbolService(ITree input) { + public InterruptibleFuture outline(ITree input) { debug(LanguageContributions.OUTLINER, TreeAdapter.getLocation(input)); return execFunction(LanguageContributions.OUTLINER, outliner, VF.list(), input); } @Override - public InterruptibleFuture runAnalysisService(ISourceLocation src, ITree input) { + public InterruptibleFuture analyze(ISourceLocation src, ITree input) { debug(LanguageContributions.ANALYZER, src); return execFunction(LanguageContributions.ANALYZER, analyzer, EmptySummary.newInstance(src), src, input); } @Override - public InterruptibleFuture runBuildService(ISourceLocation src, ITree input) { + public InterruptibleFuture build(ISourceLocation src, ITree input) { debug(LanguageContributions.BUILDER, src); return execFunction(LanguageContributions.BUILDER, builder, EmptySummary.newInstance(src), src, input); } @Override - public InterruptibleFuture runCodeLensService(ITree input) { + public InterruptibleFuture lenses(ITree input) { debug(LanguageContributions.LENS_DETECTOR, TreeAdapter.getLocation(input)); return execFunction(LanguageContributions.LENS_DETECTOR, lenses, VF.list(), input); } @Override - public InterruptibleFuture runInlayHintService(@Nullable ITree input) { + public InterruptibleFuture inlayHint(@Nullable ITree input) { debug(LanguageContributions.INLAY_HINTER, input != null ? TreeAdapter.getLocation(input) : null); return execFunction(LanguageContributions.INLAY_HINTER, inlayHinter, VF.list(), input); } @Override - public InterruptibleFuture runHoverService(IList focus) { + public InterruptibleFuture documentation(IList focus) { debug(LanguageContributions.DOCUMENTER, focus.length()); return execFunction(LanguageContributions.DOCUMENTER, documenter, VF.set(), focus); } @Override - public InterruptibleFuture runDefinitionService(IList focus) { + public InterruptibleFuture definitions(IList focus) { debug(LanguageContributions.DEFINER, focus.length()); return execFunction(LanguageContributions.DEFINER, definer, VF.set(), focus); } @Override - public InterruptibleFuture runImplementationService(IList focus) { + public InterruptibleFuture implementations(IList focus) { debug(LanguageContributions.IMPLEMENTER, focus.length()); return execFunction(LanguageContributions.IMPLEMENTER, implementer, VF.set(), focus); } @Override - public InterruptibleFuture runReferencesService(IList focus) { + public InterruptibleFuture references(IList focus) { debug(LanguageContributions.REFERRER, focus.length()); return execFunction(LanguageContributions.REFERRER, referrer, VF.set(), focus); } @Override - public InterruptibleFuture runCodeActionService(IList focus) { + public InterruptibleFuture codeActions(IList focus) { debug(LanguageContributions.CODE_ACTION_CONTRIBUTOR, focus.length()); return execFunction(LanguageContributions.CODE_ACTION_CONTRIBUTOR, codeActionContributor, VF.list(), focus); } @@ -331,57 +331,57 @@ private void debug(String name, Object param1, Object param2) { } @Override - public CompletableFuture hasDefinitionService() { + public CompletableFuture hasDefiner() { return hasDefiner; } @Override - public CompletableFuture hasReferencesService() { + public CompletableFuture hasReferrer() { return hasReferrer; } @Override - public CompletableFuture hasImplementationService() { + public CompletableFuture hasImplementer() { return hasImplementer; } @Override - public CompletableFuture hasHoverService() { + public CompletableFuture hasDocumenter() { return hasDocumenter; } @Override - public CompletableFuture hasExecutionService() { + public CompletableFuture hasCommandExecutor() { return hasCommandExecutor; } @Override - public CompletableFuture hasInlayHintService() { + public CompletableFuture hasInlayHinter() { return hasInlayHinter; } @Override - public CompletableFuture hasCodeLensDetector() { + public CompletableFuture hasLensDetector() { return hasLensDetector; } @Override - public CompletableFuture hasDocumentSymbolService() { + public CompletableFuture hasOutliner() { return hasOutliner; } @Override - public CompletableFuture hasCodeActionService() { + public CompletableFuture hasCodeActionsContributor() { return hasCodeActionContributor; } @Override - public CompletableFuture hasAnalysisService() { + public CompletableFuture hasAnalyzer() { return hasAnalyzer; } @Override - public CompletableFuture hasBuildService() { + public CompletableFuture hasBuilder() { return hasBuilder; } @@ -401,7 +401,7 @@ public CompletableFuture getOndemandSummaryConfig() { } @Override - public InterruptibleFuture<@Nullable IValue> runExecutionService(String command) { + 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); diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java index ebb357776..1dc864736 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java @@ -135,29 +135,29 @@ private synchronized void calculateRouting() { // we calculate the "route" once, and then just chain onto the completed // future parser = firstOrFail(); - outliner = findFirstOrDefault(ILanguageContributions::hasDocumentSymbolService); - analyzer = findFirstOrDefault(ILanguageContributions::hasAnalysisService); - builder = findFirstOrDefault(ILanguageContributions::hasBuildService); - lensDetector = findFirstOrDefault(ILanguageContributions::hasCodeLensDetector); - commandExecutor = findFirstOrDefault(ILanguageContributions::hasExecutionService); - inlayHinter = findFirstOrDefault(ILanguageContributions::hasInlayHintService); - definer = findFirstOrDefault(ILanguageContributions::hasDefinitionService); - documenter = findFirstOrDefault(ILanguageContributions::hasHoverService); - referrer = findFirstOrDefault(ILanguageContributions::hasReferencesService); - implementer = findFirstOrDefault(ILanguageContributions::hasImplementationService); - codeActionContributor = findFirstOrDefault(ILanguageContributions::hasCodeActionService); - - hasDocumenter = anyTrue(ILanguageContributions::hasHoverService); - hasDefiner = anyTrue(ILanguageContributions::hasDefinitionService); - hasReferrer = anyTrue(ILanguageContributions::hasReferencesService); - hasImplementer = anyTrue(ILanguageContributions::hasImplementationService); - - hasOutliner = anyTrue(ILanguageContributions::hasDocumentSymbolService); - hasAnalyzer = anyTrue(ILanguageContributions::hasAnalysisService); - hasBuilder = anyTrue(ILanguageContributions::hasBuildService); - hasLensDetector = anyTrue(ILanguageContributions::hasCodeLensDetector); - hasCommandExecutor = anyTrue(ILanguageContributions::hasExecutionService); - hasInlayHinter = anyTrue(ILanguageContributions::hasInlayHintService); + outliner = findFirstOrDefault(ILanguageContributions::hasOutliner); + analyzer = findFirstOrDefault(ILanguageContributions::hasAnalyzer); + builder = findFirstOrDefault(ILanguageContributions::hasBuilder); + lensDetector = findFirstOrDefault(ILanguageContributions::hasLensDetector); + commandExecutor = findFirstOrDefault(ILanguageContributions::hasCommandExecutor); + inlayHinter = findFirstOrDefault(ILanguageContributions::hasInlayHinter); + definer = findFirstOrDefault(ILanguageContributions::hasDefiner); + documenter = findFirstOrDefault(ILanguageContributions::hasDocumenter); + referrer = findFirstOrDefault(ILanguageContributions::hasReferrer); + implementer = findFirstOrDefault(ILanguageContributions::hasImplementer); + codeActionContributor = findFirstOrDefault(ILanguageContributions::hasCodeActionsContributor); + + hasDocumenter = anyTrue(ILanguageContributions::hasDocumenter); + hasDefiner = anyTrue(ILanguageContributions::hasDefiner); + hasReferrer = anyTrue(ILanguageContributions::hasReferrer); + hasImplementer = anyTrue(ILanguageContributions::hasImplementer); + + hasOutliner = anyTrue(ILanguageContributions::hasOutliner); + hasAnalyzer = anyTrue(ILanguageContributions::hasAnalyzer); + hasBuilder = anyTrue(ILanguageContributions::hasBuilder); + hasLensDetector = anyTrue(ILanguageContributions::hasLensDetector); + hasCommandExecutor = anyTrue(ILanguageContributions::hasCommandExecutor); + hasInlayHinter = anyTrue(ILanguageContributions::hasInlayHinter); analyzerSummaryConfig = anyTrue(ILanguageContributions::getAnalyzerSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); builderSummaryConfig = anyTrue(ILanguageContributions::getBuilderSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); @@ -218,12 +218,12 @@ public String getName() { } @Override - public CompletableFuture runParsingService(ISourceLocation loc, String input) { + public CompletableFuture parseSourceFile(ISourceLocation loc, String input) { var p = parser; if (p == null) { return failedInitialization(); } - return p.runParsingService(loc, input); + return p.parseSourceFile(loc, input); } @@ -232,28 +232,28 @@ private InterruptibleFuture flatten(CompletableFuture runDocumentSymbolService(ITree input) { - return flatten(outliner, c -> c.runDocumentSymbolService(input)); + public InterruptibleFuture outline(ITree input) { + return flatten(outliner, c -> c.outline(input)); } @Override - public InterruptibleFuture runAnalysisService(ISourceLocation loc, ITree input) { - return flatten(analyzer, c -> c.runAnalysisService(loc, input)); + public InterruptibleFuture analyze(ISourceLocation loc, ITree input) { + return flatten(analyzer, c -> c.analyze(loc, input)); } @Override - public InterruptibleFuture runBuildService(ISourceLocation loc, ITree input) { - return flatten(builder, c -> c.runBuildService(loc, input)); + public InterruptibleFuture build(ISourceLocation loc, ITree input) { + return flatten(builder, c -> c.build(loc, input)); } @Override - public InterruptibleFuture runCodeLensService(ITree input) { - return flatten(lensDetector, c -> c.runCodeLensService(input)); + public InterruptibleFuture lenses(ITree input) { + return flatten(lensDetector, c -> c.lenses(input)); } @Override - public InterruptibleFuture<@Nullable IValue> runExecutionService(String command) { - return flatten(commandExecutor, c -> c.runExecutionService(command)); + public InterruptibleFuture<@Nullable IValue> executeCommand(String command) { + return flatten(commandExecutor, c -> c.executeCommand(command)); } @Override @@ -262,87 +262,87 @@ public CompletableFuture parseCodeActions(String command) { } @Override - public InterruptibleFuture runInlayHintService(@Nullable ITree input) { - return flatten(inlayHinter, c -> c.runInlayHintService(input)); + public InterruptibleFuture inlayHint(@Nullable ITree input) { + return flatten(inlayHinter, c -> c.inlayHint(input)); } @Override - public InterruptibleFuture runHoverService(IList focus) { - return flatten(documenter, c -> c.runHoverService(focus)); + public InterruptibleFuture documentation(IList focus) { + return flatten(documenter, c -> c.documentation(focus)); } @Override - public InterruptibleFuture runDefinitionService(IList focus) { - return flatten(definer, c -> c.runDefinitionService(focus)); + public InterruptibleFuture definitions(IList focus) { + return flatten(definer, c -> c.definitions(focus)); } @Override - public InterruptibleFuture runReferencesService(IList focus) { - return flatten(referrer, c -> c.runReferencesService(focus)); + public InterruptibleFuture references(IList focus) { + return flatten(referrer, c -> c.references(focus)); } @Override - public InterruptibleFuture runImplementationService(IList focus) { - return flatten(implementer, c -> c.runImplementationService(focus)); + public InterruptibleFuture implementations(IList focus) { + return flatten(implementer, c -> c.implementations(focus)); } @Override - public InterruptibleFuture runCodeActionService(IList focus) { - return flatten(codeActionContributor, c -> c.runCodeActionService(focus)); + public InterruptibleFuture codeActions(IList focus) { + return flatten(codeActionContributor, c -> c.codeActions(focus)); } @Override - public CompletableFuture hasCodeActionService() { + public CompletableFuture hasCodeActionsContributor() { return hasCodeActionContributor; } @Override - public CompletableFuture hasHoverService() { + public CompletableFuture hasDocumenter() { return hasDocumenter; } @Override - public CompletableFuture hasDefinitionService() { + public CompletableFuture hasDefiner() { return hasDefiner; } @Override - public CompletableFuture hasReferencesService() { + public CompletableFuture hasReferrer() { return hasReferrer; } @Override - public CompletableFuture hasImplementationService() { + public CompletableFuture hasImplementer() { return hasImplementer; } @Override - public CompletableFuture hasDocumentSymbolService() { + public CompletableFuture hasOutliner() { return hasOutliner; } @Override - public CompletableFuture hasAnalysisService() { + public CompletableFuture hasAnalyzer() { return hasAnalyzer; } @Override - public CompletableFuture hasBuildService() { + public CompletableFuture hasBuilder() { return hasBuilder; } @Override - public CompletableFuture hasCodeLensDetector() { + public CompletableFuture hasLensDetector() { return hasLensDetector; } @Override - public CompletableFuture hasExecutionService() { + public CompletableFuture hasCommandExecutor() { return hasCommandExecutor; } @Override - public CompletableFuture hasInlayHintService() { + public CompletableFuture hasInlayHinter() { return hasInlayHinter; } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java index 3837cd8bc..4edea7dcf 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java @@ -328,7 +328,7 @@ public CompletableFuture> codeLens(CodeLensParams param return recoverExceptions(file.getCurrentTreeAsync() .thenApply(Versioned::get) - .thenApply(contrib::runCodeLensService) + .thenApply(contrib::lenses) .thenCompose(InterruptibleFuture::get) .thenApply(s -> s.stream() .map(e -> locCommandTupleToCodeLense(contrib.getName(), e)) @@ -344,7 +344,7 @@ public CompletableFuture> inlayHint(InlayHintParams params) { return recoverExceptions( recoverExceptions(file.getCurrentTreeAsync(), file::getMostRecentTree) .thenApply(Versioned::get) - .thenApply(contrib::runInlayHintService) + .thenApply(contrib::inlayHint) .thenCompose(InterruptibleFuture::get) .thenApply(s -> s.stream() .map(this::rowToInlayHint) @@ -520,7 +520,7 @@ private ParametricFileFacts facts(String doc) { private TextDocumentState open(TextDocumentItem doc) { return files.computeIfAbsent(Locations.toLoc(doc), - l -> new TextDocumentState(contributions(doc)::runParsingService, l, doc.getVersion(), doc.getText()) + l -> new TextDocumentState(contributions(doc)::parseSourceFile, l, doc.getVersion(), doc.getText()) ); } @@ -577,7 +577,7 @@ public CompletableFuture semanticTokensRange(SemanticTokensRange ILanguageContributions contrib = contributions(params.getTextDocument()); return recoverExceptions(file.getCurrentTreeAsync() .thenApply(Versioned::get) - .thenApply(contrib::runDocumentSymbolService) + .thenApply(contrib::outline) .thenCompose(InterruptibleFuture::get) .thenApply(c -> Outline.buildOutline(c, columns.get(file.getLocation()))) , Collections::emptyList); @@ -639,7 +639,7 @@ private CompletableFuture computeCodeActions(final ILanguageContributions IList focus = TreeSearch.computeFocusList(tree, startLine, startColumn); if (!focus.isEmpty()) { - return contribs.runCodeActionService(focus).get(); + return contribs.codeActions(focus).get(); } else { logger.log(Level.DEBUG, "no tree focus found at {}:{}", startLine, startColumn); @@ -778,7 +778,7 @@ public CompletableFuture executeCommand(String languageName, String comm ILanguageContributions contribs = contributions.get(languageName); if (contribs != null) { - return contribs.runExecutionService(command).get(); + return contribs.executeCommand(command).get(); } else { logger.warn("ignoring command execution (no contributor configured for this language): {}, {} ", languageName, command); diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java index 555317e67..91a68d57a 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java @@ -75,7 +75,7 @@ public String getName() { } @Override - public CompletableFuture runParsingService(ISourceLocation loc, String input) { + public CompletableFuture parseSourceFile(ISourceLocation loc, String input) { if (loadingParserError != null || parser == null) { return CompletableFuture.failedFuture(new RuntimeException("Parser function did not load", loadingParserError)); } @@ -114,27 +114,27 @@ private static IConstructor makeReifiedType(ParserSpecification spec, IRascalVal } @Override - public InterruptibleFuture runDocumentSymbolService(ITree input) { + public InterruptibleFuture outline(ITree input) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture runAnalysisService(ISourceLocation loc, ITree input) { + public InterruptibleFuture analyze(ISourceLocation loc, ITree input) { return InterruptibleFuture.completedFuture(EmptySummary.newInstance(loc)); } @Override - public InterruptibleFuture runBuildService(ISourceLocation loc, ITree input) { + public InterruptibleFuture build(ISourceLocation loc, ITree input) { return InterruptibleFuture.completedFuture(EmptySummary.newInstance(loc)); } @Override - public InterruptibleFuture runCodeLensService(ITree input) { + public InterruptibleFuture lenses(ITree input) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture<@Nullable IValue> runExecutionService(String command) { + public InterruptibleFuture<@Nullable IValue> executeCommand(String command) { return InterruptibleFuture.completedFuture(VF.bool(false)); } @@ -144,87 +144,87 @@ public CompletableFuture parseCodeActions(String commands) { } @Override - public InterruptibleFuture runInlayHintService(@Nullable ITree input) { + public InterruptibleFuture inlayHint(@Nullable ITree input) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture runHoverService(IList focus) { + public InterruptibleFuture documentation(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public InterruptibleFuture runDefinitionService(IList focus) { + public InterruptibleFuture definitions(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public InterruptibleFuture runReferencesService(IList focus) { + public InterruptibleFuture references(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public InterruptibleFuture runCodeActionService(IList focus) { + public InterruptibleFuture codeActions(IList focus) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture runImplementationService(IList focus) { + public InterruptibleFuture implementations(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public CompletableFuture hasHoverService() { + public CompletableFuture hasDocumenter() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasDefinitionService() { + public CompletableFuture hasDefiner() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasReferencesService() { + public CompletableFuture hasReferrer() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasImplementationService() { + public CompletableFuture hasImplementer() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasDocumentSymbolService() { + public CompletableFuture hasOutliner() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasAnalysisService() { + public CompletableFuture hasAnalyzer() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasBuildService() { + public CompletableFuture hasBuilder() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasCodeActionService() { + public CompletableFuture hasCodeActionsContributor() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasCodeLensDetector() { + public CompletableFuture hasLensDetector() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasExecutionService() { + public CompletableFuture hasCommandExecutor() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasInlayHintService() { + public CompletableFuture hasInlayHinter() { return CompletableFuture.completedFuture(false); } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java index e1adc0bdf..be1ab0eaf 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java @@ -114,9 +114,9 @@ private FileFact getFile(ISourceLocation l) { public void reloadContributions() { analyzerSummaryFactory = contrib.getAnalyzerSummaryConfig().thenApply(config -> - new ScheduledSummaryFactory(config, exec, columns, contrib::runAnalysisService)); + new ScheduledSummaryFactory(config, exec, columns, contrib::analyze)); builderSummaryFactory = contrib.getBuilderSummaryConfig().thenApply(config -> - new ScheduledSummaryFactory(config, exec, columns, contrib::runBuildService)); + new ScheduledSummaryFactory(config, exec, columns, contrib::build)); ondemandSummaryFactory = contrib.getOndemandSummaryConfig().thenApply(config -> new OndemandSummaryFactory(config, exec, columns, contrib)); } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java index 20d286c51..26b8371cc 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java @@ -277,7 +277,7 @@ public FullScheduledSummary(InterruptibleFuture calculation) { return summary; }); - this.documentation = config.providesHovers ? + this.documentation = config.providesDocumentation ? mapCalculation(SummaryFields.DOCUMENTATION, calculation, SummaryFields.DOCUMENTATION, ParametricSummaryFactory::mapValueToString) : null; this.definitions = config.providesDefinitions ? mapCalculation(SummaryFields.DEFINITIONS, calculation, SummaryFields.DEFINITIONS, locationMapper(columns)) : null; @@ -435,22 +435,22 @@ public OndemandSummary(ISourceLocation file, Versioned tree, Position cur @Override @SuppressWarnings("deprecation") // For `MarkedString` public @Nullable InterruptibleFuture>> getDocumentation(Position cursor) { - return get(config.providesHovers, cursor, contrib::runHoverService, ParametricSummaryFactory::mapValueToString, SummaryFields.DOCUMENTATION); + return get(config.providesDocumentation, cursor, contrib::documentation, ParametricSummaryFactory::mapValueToString, SummaryFields.DOCUMENTATION); } @Override public @Nullable InterruptibleFuture> getDefinitions(Position cursor) { - return get(config.providesDefinitions, cursor, contrib::runDefinitionService, locationMapper(columns), SummaryFields.DEFINITIONS); + return get(config.providesDefinitions, cursor, contrib::definitions, locationMapper(columns), SummaryFields.DEFINITIONS); } @Override public @Nullable InterruptibleFuture> getReferences(Position cursor) { - return get(config.providesReferences, cursor, contrib::runReferencesService, locationMapper(columns), SummaryFields.REFERENCES); + return get(config.providesReferences, cursor, contrib::references, locationMapper(columns), SummaryFields.REFERENCES); } @Override public @Nullable InterruptibleFuture> getImplementations(Position cursor) { - return get(config.providesImplementations, cursor, contrib::runImplementationService, locationMapper(columns), SummaryFields.IMPLEMENTATIONS); + return get(config.providesImplementations, cursor, contrib::implementations, locationMapper(columns), SummaryFields.IMPLEMENTATIONS); } @Override From 617731da52d6b9adc8c994aa8174b5bbccfa8c28 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Thu, 17 Oct 2024 09:45:28 +0200 Subject: [PATCH 38/57] Rename methods in `ILanguageContributions` to be consistent with LSP --- .../parametric/ILanguageContributions.java | 58 ++++----- .../InterpretedLanguageContributions.java | 46 +++---- .../LanguageContributionsMultiplexer.java | 116 +++++++++--------- .../ParametricTextDocumentService.java | 12 +- .../parametric/ParserOnlyContribution.java | 46 +++---- .../parametric/model/ParametricFileFacts.java | 4 +- .../parametric/model/ParametricSummary.java | 10 +- 7 files changed, 146 insertions(+), 146 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java index d3df7a242..f65efbe9a 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java @@ -46,49 +46,50 @@ public interface ILanguageContributions { public String getName(); - public CompletableFuture parseSourceFile(ISourceLocation loc, String input); - public InterruptibleFuture outline(ITree input); - public InterruptibleFuture analyze(ISourceLocation loc, ITree input); - public InterruptibleFuture build(ISourceLocation loc, ITree input); - public InterruptibleFuture lenses(ITree input); - public InterruptibleFuture<@Nullable IValue> executeCommand(String command); + public CompletableFuture runParsingService(ISourceLocation loc, String input); + public InterruptibleFuture runAnalysisService(ISourceLocation loc, ITree input); + public InterruptibleFuture runBuildService(ISourceLocation loc, ITree input); + public InterruptibleFuture runDocumentSymbolService(ITree input); + public InterruptibleFuture runCodeLensService(ITree input); + public InterruptibleFuture runInlayHintService(@Nullable ITree input); + public InterruptibleFuture<@Nullable IValue> runExecutionService(String command); + public InterruptibleFuture runHoverService(IList focus); + public InterruptibleFuture runDefinitionService(IList focus); + public InterruptibleFuture runReferencesService(IList focus); + public InterruptibleFuture runImplementationService(IList focus); + public InterruptibleFuture runCodeActionService(IList focus); + public CompletableFuture parseCodeActions(String command); - public InterruptibleFuture inlayHint(@Nullable ITree input); - public InterruptibleFuture documentation(IList focus); - public InterruptibleFuture definitions(IList focus); - public InterruptibleFuture references(IList focus); - public InterruptibleFuture implementations(IList focus); - public InterruptibleFuture codeActions(IList focus); - - public CompletableFuture hasAnalyzer(); - public CompletableFuture hasBuilder(); - public CompletableFuture hasOutliner(); - public CompletableFuture hasLensDetector(); - public CompletableFuture hasInlayHinter(); - public CompletableFuture hasCommandExecutor(); - public CompletableFuture hasDocumenter(); - public CompletableFuture hasDefiner(); - public CompletableFuture hasReferrer(); - public CompletableFuture hasImplementer(); - public CompletableFuture hasCodeActionsContributor(); + + public CompletableFuture hasAnalysisService(); + public CompletableFuture hasBuildService(); + public CompletableFuture hasDocumentSymbolService(); + public CompletableFuture hasCodeLensDetector(); + public CompletableFuture hasInlayHintService(); + public CompletableFuture hasExecutionService(); + public CompletableFuture hasHoverService(); + public CompletableFuture hasDefinitionService(); + public CompletableFuture hasReferencesService(); + public CompletableFuture hasImplementationService(); + public CompletableFuture hasCodeActionService(); public CompletableFuture getAnalyzerSummaryConfig(); public CompletableFuture getBuilderSummaryConfig(); public CompletableFuture getOndemandSummaryConfig(); public static class SummaryConfig { - public final boolean providesDocumentation; + public final boolean providesHovers; public final boolean providesDefinitions; public final boolean providesReferences; public final boolean providesImplementations; public SummaryConfig( - boolean providesDocumentation, + boolean providesHovers, boolean providesDefinitions, boolean providesReferences, boolean providesImplementations) { - this.providesDocumentation = providesDocumentation; + this.providesHovers = providesHovers; this.providesDefinitions = providesDefinitions; this.providesReferences = providesReferences; this.providesImplementations = providesImplementations; @@ -98,14 +99,13 @@ public SummaryConfig( public static SummaryConfig or(SummaryConfig a, SummaryConfig b) { return new SummaryConfig( - a.providesDocumentation || b.providesDocumentation, + a.providesHovers || b.providesHovers, a.providesDefinitions || b.providesDefinitions, a.providesReferences || b.providesReferences, a.providesImplementations || b.providesImplementations); } } - @FunctionalInterface // Type alias to conveniently pass methods `analyze`and `build` as parameters public static interface ScheduledCalculator extends BiFunction> {} diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java index 034c91034..07f001a84 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java @@ -257,67 +257,67 @@ public String getName() { } @Override - public CompletableFuture parseSourceFile(ISourceLocation loc, String input) { + public CompletableFuture runParsingService(ISourceLocation loc, String input) { debug(LanguageContributions.PARSER, loc, input); return parser.thenApplyAsync(p -> p.call(VF.string(input), loc), exec); } @Override - public InterruptibleFuture outline(ITree input) { + public InterruptibleFuture runDocumentSymbolService(ITree input) { debug(LanguageContributions.OUTLINER, TreeAdapter.getLocation(input)); return execFunction(LanguageContributions.OUTLINER, outliner, VF.list(), input); } @Override - public InterruptibleFuture analyze(ISourceLocation src, ITree input) { + public InterruptibleFuture runAnalysisService(ISourceLocation src, ITree input) { debug(LanguageContributions.ANALYZER, src); return execFunction(LanguageContributions.ANALYZER, analyzer, EmptySummary.newInstance(src), src, input); } @Override - public InterruptibleFuture build(ISourceLocation src, ITree input) { + public InterruptibleFuture runBuildService(ISourceLocation src, ITree input) { debug(LanguageContributions.BUILDER, src); return execFunction(LanguageContributions.BUILDER, builder, EmptySummary.newInstance(src), src, input); } @Override - public InterruptibleFuture lenses(ITree input) { + public InterruptibleFuture runCodeLensService(ITree input) { debug(LanguageContributions.LENS_DETECTOR, TreeAdapter.getLocation(input)); return execFunction(LanguageContributions.LENS_DETECTOR, lenses, VF.list(), input); } @Override - public InterruptibleFuture inlayHint(@Nullable ITree input) { + public InterruptibleFuture runInlayHintService(@Nullable ITree input) { debug(LanguageContributions.INLAY_HINTER, input != null ? TreeAdapter.getLocation(input) : null); return execFunction(LanguageContributions.INLAY_HINTER, inlayHinter, VF.list(), input); } @Override - public InterruptibleFuture documentation(IList focus) { + public InterruptibleFuture runHoverService(IList focus) { debug(LanguageContributions.DOCUMENTER, focus.length()); return execFunction(LanguageContributions.DOCUMENTER, documenter, VF.set(), focus); } @Override - public InterruptibleFuture definitions(IList focus) { + public InterruptibleFuture runDefinitionService(IList focus) { debug(LanguageContributions.DEFINER, focus.length()); return execFunction(LanguageContributions.DEFINER, definer, VF.set(), focus); } @Override - public InterruptibleFuture implementations(IList focus) { + public InterruptibleFuture runImplementationService(IList focus) { debug(LanguageContributions.IMPLEMENTER, focus.length()); return execFunction(LanguageContributions.IMPLEMENTER, implementer, VF.set(), focus); } @Override - public InterruptibleFuture references(IList focus) { + public InterruptibleFuture runReferencesService(IList focus) { debug(LanguageContributions.REFERRER, focus.length()); return execFunction(LanguageContributions.REFERRER, referrer, VF.set(), focus); } @Override - public InterruptibleFuture codeActions(IList focus) { + public InterruptibleFuture runCodeActionService(IList focus) { debug(LanguageContributions.CODE_ACTION_CONTRIBUTOR, focus.length()); return execFunction(LanguageContributions.CODE_ACTION_CONTRIBUTOR, codeActionContributor, VF.list(), focus); } @@ -331,57 +331,57 @@ private void debug(String name, Object param1, Object param2) { } @Override - public CompletableFuture hasDefiner() { + public CompletableFuture hasDefinitionService() { return hasDefiner; } @Override - public CompletableFuture hasReferrer() { + public CompletableFuture hasReferencesService() { return hasReferrer; } @Override - public CompletableFuture hasImplementer() { + public CompletableFuture hasImplementationService() { return hasImplementer; } @Override - public CompletableFuture hasDocumenter() { + public CompletableFuture hasHoverService() { return hasDocumenter; } @Override - public CompletableFuture hasCommandExecutor() { + public CompletableFuture hasExecutionService() { return hasCommandExecutor; } @Override - public CompletableFuture hasInlayHinter() { + public CompletableFuture hasInlayHintService() { return hasInlayHinter; } @Override - public CompletableFuture hasLensDetector() { + public CompletableFuture hasCodeLensDetector() { return hasLensDetector; } @Override - public CompletableFuture hasOutliner() { + public CompletableFuture hasDocumentSymbolService() { return hasOutliner; } @Override - public CompletableFuture hasCodeActionsContributor() { + public CompletableFuture hasCodeActionService() { return hasCodeActionContributor; } @Override - public CompletableFuture hasAnalyzer() { + public CompletableFuture hasAnalysisService() { return hasAnalyzer; } @Override - public CompletableFuture hasBuilder() { + public CompletableFuture hasBuildService() { return hasBuilder; } @@ -401,7 +401,7 @@ public CompletableFuture getOndemandSummaryConfig() { } @Override - public InterruptibleFuture<@Nullable IValue> executeCommand(String command) { + public InterruptibleFuture<@Nullable IValue> runExecutionService(String command) { logger.debug("executeCommand({}...) (full command value in TRACE level)", () -> command.substring(0, Math.min(10, command.length()))); logger.trace("Full command: {}", command); diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java index 1dc864736..ebb357776 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java @@ -135,29 +135,29 @@ private synchronized void calculateRouting() { // we calculate the "route" once, and then just chain onto the completed // future parser = firstOrFail(); - outliner = findFirstOrDefault(ILanguageContributions::hasOutliner); - analyzer = findFirstOrDefault(ILanguageContributions::hasAnalyzer); - builder = findFirstOrDefault(ILanguageContributions::hasBuilder); - lensDetector = findFirstOrDefault(ILanguageContributions::hasLensDetector); - commandExecutor = findFirstOrDefault(ILanguageContributions::hasCommandExecutor); - inlayHinter = findFirstOrDefault(ILanguageContributions::hasInlayHinter); - definer = findFirstOrDefault(ILanguageContributions::hasDefiner); - documenter = findFirstOrDefault(ILanguageContributions::hasDocumenter); - referrer = findFirstOrDefault(ILanguageContributions::hasReferrer); - implementer = findFirstOrDefault(ILanguageContributions::hasImplementer); - codeActionContributor = findFirstOrDefault(ILanguageContributions::hasCodeActionsContributor); - - hasDocumenter = anyTrue(ILanguageContributions::hasDocumenter); - hasDefiner = anyTrue(ILanguageContributions::hasDefiner); - hasReferrer = anyTrue(ILanguageContributions::hasReferrer); - hasImplementer = anyTrue(ILanguageContributions::hasImplementer); - - hasOutliner = anyTrue(ILanguageContributions::hasOutliner); - hasAnalyzer = anyTrue(ILanguageContributions::hasAnalyzer); - hasBuilder = anyTrue(ILanguageContributions::hasBuilder); - hasLensDetector = anyTrue(ILanguageContributions::hasLensDetector); - hasCommandExecutor = anyTrue(ILanguageContributions::hasCommandExecutor); - hasInlayHinter = anyTrue(ILanguageContributions::hasInlayHinter); + outliner = findFirstOrDefault(ILanguageContributions::hasDocumentSymbolService); + analyzer = findFirstOrDefault(ILanguageContributions::hasAnalysisService); + builder = findFirstOrDefault(ILanguageContributions::hasBuildService); + lensDetector = findFirstOrDefault(ILanguageContributions::hasCodeLensDetector); + commandExecutor = findFirstOrDefault(ILanguageContributions::hasExecutionService); + inlayHinter = findFirstOrDefault(ILanguageContributions::hasInlayHintService); + definer = findFirstOrDefault(ILanguageContributions::hasDefinitionService); + documenter = findFirstOrDefault(ILanguageContributions::hasHoverService); + referrer = findFirstOrDefault(ILanguageContributions::hasReferencesService); + implementer = findFirstOrDefault(ILanguageContributions::hasImplementationService); + codeActionContributor = findFirstOrDefault(ILanguageContributions::hasCodeActionService); + + hasDocumenter = anyTrue(ILanguageContributions::hasHoverService); + hasDefiner = anyTrue(ILanguageContributions::hasDefinitionService); + hasReferrer = anyTrue(ILanguageContributions::hasReferencesService); + hasImplementer = anyTrue(ILanguageContributions::hasImplementationService); + + hasOutliner = anyTrue(ILanguageContributions::hasDocumentSymbolService); + hasAnalyzer = anyTrue(ILanguageContributions::hasAnalysisService); + hasBuilder = anyTrue(ILanguageContributions::hasBuildService); + hasLensDetector = anyTrue(ILanguageContributions::hasCodeLensDetector); + hasCommandExecutor = anyTrue(ILanguageContributions::hasExecutionService); + hasInlayHinter = anyTrue(ILanguageContributions::hasInlayHintService); analyzerSummaryConfig = anyTrue(ILanguageContributions::getAnalyzerSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); builderSummaryConfig = anyTrue(ILanguageContributions::getBuilderSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); @@ -218,12 +218,12 @@ public String getName() { } @Override - public CompletableFuture parseSourceFile(ISourceLocation loc, String input) { + public CompletableFuture runParsingService(ISourceLocation loc, String input) { var p = parser; if (p == null) { return failedInitialization(); } - return p.parseSourceFile(loc, input); + return p.runParsingService(loc, input); } @@ -232,28 +232,28 @@ private InterruptibleFuture flatten(CompletableFuture outline(ITree input) { - return flatten(outliner, c -> c.outline(input)); + public InterruptibleFuture runDocumentSymbolService(ITree input) { + return flatten(outliner, c -> c.runDocumentSymbolService(input)); } @Override - public InterruptibleFuture analyze(ISourceLocation loc, ITree input) { - return flatten(analyzer, c -> c.analyze(loc, input)); + public InterruptibleFuture runAnalysisService(ISourceLocation loc, ITree input) { + return flatten(analyzer, c -> c.runAnalysisService(loc, input)); } @Override - public InterruptibleFuture build(ISourceLocation loc, ITree input) { - return flatten(builder, c -> c.build(loc, input)); + public InterruptibleFuture runBuildService(ISourceLocation loc, ITree input) { + return flatten(builder, c -> c.runBuildService(loc, input)); } @Override - public InterruptibleFuture lenses(ITree input) { - return flatten(lensDetector, c -> c.lenses(input)); + public InterruptibleFuture runCodeLensService(ITree input) { + return flatten(lensDetector, c -> c.runCodeLensService(input)); } @Override - public InterruptibleFuture<@Nullable IValue> executeCommand(String command) { - return flatten(commandExecutor, c -> c.executeCommand(command)); + public InterruptibleFuture<@Nullable IValue> runExecutionService(String command) { + return flatten(commandExecutor, c -> c.runExecutionService(command)); } @Override @@ -262,87 +262,87 @@ public CompletableFuture parseCodeActions(String command) { } @Override - public InterruptibleFuture inlayHint(@Nullable ITree input) { - return flatten(inlayHinter, c -> c.inlayHint(input)); + public InterruptibleFuture runInlayHintService(@Nullable ITree input) { + return flatten(inlayHinter, c -> c.runInlayHintService(input)); } @Override - public InterruptibleFuture documentation(IList focus) { - return flatten(documenter, c -> c.documentation(focus)); + public InterruptibleFuture runHoverService(IList focus) { + return flatten(documenter, c -> c.runHoverService(focus)); } @Override - public InterruptibleFuture definitions(IList focus) { - return flatten(definer, c -> c.definitions(focus)); + public InterruptibleFuture runDefinitionService(IList focus) { + return flatten(definer, c -> c.runDefinitionService(focus)); } @Override - public InterruptibleFuture references(IList focus) { - return flatten(referrer, c -> c.references(focus)); + public InterruptibleFuture runReferencesService(IList focus) { + return flatten(referrer, c -> c.runReferencesService(focus)); } @Override - public InterruptibleFuture implementations(IList focus) { - return flatten(implementer, c -> c.implementations(focus)); + public InterruptibleFuture runImplementationService(IList focus) { + return flatten(implementer, c -> c.runImplementationService(focus)); } @Override - public InterruptibleFuture codeActions(IList focus) { - return flatten(codeActionContributor, c -> c.codeActions(focus)); + public InterruptibleFuture runCodeActionService(IList focus) { + return flatten(codeActionContributor, c -> c.runCodeActionService(focus)); } @Override - public CompletableFuture hasCodeActionsContributor() { + public CompletableFuture hasCodeActionService() { return hasCodeActionContributor; } @Override - public CompletableFuture hasDocumenter() { + public CompletableFuture hasHoverService() { return hasDocumenter; } @Override - public CompletableFuture hasDefiner() { + public CompletableFuture hasDefinitionService() { return hasDefiner; } @Override - public CompletableFuture hasReferrer() { + public CompletableFuture hasReferencesService() { return hasReferrer; } @Override - public CompletableFuture hasImplementer() { + public CompletableFuture hasImplementationService() { return hasImplementer; } @Override - public CompletableFuture hasOutliner() { + public CompletableFuture hasDocumentSymbolService() { return hasOutliner; } @Override - public CompletableFuture hasAnalyzer() { + public CompletableFuture hasAnalysisService() { return hasAnalyzer; } @Override - public CompletableFuture hasBuilder() { + public CompletableFuture hasBuildService() { return hasBuilder; } @Override - public CompletableFuture hasLensDetector() { + public CompletableFuture hasCodeLensDetector() { return hasLensDetector; } @Override - public CompletableFuture hasCommandExecutor() { + public CompletableFuture hasExecutionService() { return hasCommandExecutor; } @Override - public CompletableFuture hasInlayHinter() { + public CompletableFuture hasInlayHintService() { return hasInlayHinter; } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java index 4edea7dcf..3837cd8bc 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java @@ -328,7 +328,7 @@ public CompletableFuture> codeLens(CodeLensParams param return recoverExceptions(file.getCurrentTreeAsync() .thenApply(Versioned::get) - .thenApply(contrib::lenses) + .thenApply(contrib::runCodeLensService) .thenCompose(InterruptibleFuture::get) .thenApply(s -> s.stream() .map(e -> locCommandTupleToCodeLense(contrib.getName(), e)) @@ -344,7 +344,7 @@ public CompletableFuture> inlayHint(InlayHintParams params) { return recoverExceptions( recoverExceptions(file.getCurrentTreeAsync(), file::getMostRecentTree) .thenApply(Versioned::get) - .thenApply(contrib::inlayHint) + .thenApply(contrib::runInlayHintService) .thenCompose(InterruptibleFuture::get) .thenApply(s -> s.stream() .map(this::rowToInlayHint) @@ -520,7 +520,7 @@ private ParametricFileFacts facts(String doc) { private TextDocumentState open(TextDocumentItem doc) { return files.computeIfAbsent(Locations.toLoc(doc), - l -> new TextDocumentState(contributions(doc)::parseSourceFile, l, doc.getVersion(), doc.getText()) + l -> new TextDocumentState(contributions(doc)::runParsingService, l, doc.getVersion(), doc.getText()) ); } @@ -577,7 +577,7 @@ public CompletableFuture semanticTokensRange(SemanticTokensRange ILanguageContributions contrib = contributions(params.getTextDocument()); return recoverExceptions(file.getCurrentTreeAsync() .thenApply(Versioned::get) - .thenApply(contrib::outline) + .thenApply(contrib::runDocumentSymbolService) .thenCompose(InterruptibleFuture::get) .thenApply(c -> Outline.buildOutline(c, columns.get(file.getLocation()))) , Collections::emptyList); @@ -639,7 +639,7 @@ private CompletableFuture computeCodeActions(final ILanguageContributions IList focus = TreeSearch.computeFocusList(tree, startLine, startColumn); if (!focus.isEmpty()) { - return contribs.codeActions(focus).get(); + return contribs.runCodeActionService(focus).get(); } else { logger.log(Level.DEBUG, "no tree focus found at {}:{}", startLine, startColumn); @@ -778,7 +778,7 @@ public CompletableFuture executeCommand(String languageName, String comm ILanguageContributions contribs = contributions.get(languageName); if (contribs != null) { - return contribs.executeCommand(command).get(); + return contribs.runExecutionService(command).get(); } else { logger.warn("ignoring command execution (no contributor configured for this language): {}, {} ", languageName, command); diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java index 91a68d57a..555317e67 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java @@ -75,7 +75,7 @@ public String getName() { } @Override - public CompletableFuture parseSourceFile(ISourceLocation loc, String input) { + public CompletableFuture runParsingService(ISourceLocation loc, String input) { if (loadingParserError != null || parser == null) { return CompletableFuture.failedFuture(new RuntimeException("Parser function did not load", loadingParserError)); } @@ -114,27 +114,27 @@ private static IConstructor makeReifiedType(ParserSpecification spec, IRascalVal } @Override - public InterruptibleFuture outline(ITree input) { + public InterruptibleFuture runDocumentSymbolService(ITree input) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture analyze(ISourceLocation loc, ITree input) { + public InterruptibleFuture runAnalysisService(ISourceLocation loc, ITree input) { return InterruptibleFuture.completedFuture(EmptySummary.newInstance(loc)); } @Override - public InterruptibleFuture build(ISourceLocation loc, ITree input) { + public InterruptibleFuture runBuildService(ISourceLocation loc, ITree input) { return InterruptibleFuture.completedFuture(EmptySummary.newInstance(loc)); } @Override - public InterruptibleFuture lenses(ITree input) { + public InterruptibleFuture runCodeLensService(ITree input) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture<@Nullable IValue> executeCommand(String command) { + public InterruptibleFuture<@Nullable IValue> runExecutionService(String command) { return InterruptibleFuture.completedFuture(VF.bool(false)); } @@ -144,87 +144,87 @@ public CompletableFuture parseCodeActions(String commands) { } @Override - public InterruptibleFuture inlayHint(@Nullable ITree input) { + public InterruptibleFuture runInlayHintService(@Nullable ITree input) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture documentation(IList focus) { + public InterruptibleFuture runHoverService(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public InterruptibleFuture definitions(IList focus) { + public InterruptibleFuture runDefinitionService(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public InterruptibleFuture references(IList focus) { + public InterruptibleFuture runReferencesService(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public InterruptibleFuture codeActions(IList focus) { + public InterruptibleFuture runCodeActionService(IList focus) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture implementations(IList focus) { + public InterruptibleFuture runImplementationService(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public CompletableFuture hasDocumenter() { + public CompletableFuture hasHoverService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasDefiner() { + public CompletableFuture hasDefinitionService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasReferrer() { + public CompletableFuture hasReferencesService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasImplementer() { + public CompletableFuture hasImplementationService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasOutliner() { + public CompletableFuture hasDocumentSymbolService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasAnalyzer() { + public CompletableFuture hasAnalysisService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasBuilder() { + public CompletableFuture hasBuildService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasCodeActionsContributor() { + public CompletableFuture hasCodeActionService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasLensDetector() { + public CompletableFuture hasCodeLensDetector() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasCommandExecutor() { + public CompletableFuture hasExecutionService() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasInlayHinter() { + public CompletableFuture hasInlayHintService() { return CompletableFuture.completedFuture(false); } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java index be1ab0eaf..e1adc0bdf 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java @@ -114,9 +114,9 @@ private FileFact getFile(ISourceLocation l) { public void reloadContributions() { analyzerSummaryFactory = contrib.getAnalyzerSummaryConfig().thenApply(config -> - new ScheduledSummaryFactory(config, exec, columns, contrib::analyze)); + new ScheduledSummaryFactory(config, exec, columns, contrib::runAnalysisService)); builderSummaryFactory = contrib.getBuilderSummaryConfig().thenApply(config -> - new ScheduledSummaryFactory(config, exec, columns, contrib::build)); + new ScheduledSummaryFactory(config, exec, columns, contrib::runBuildService)); ondemandSummaryFactory = contrib.getOndemandSummaryConfig().thenApply(config -> new OndemandSummaryFactory(config, exec, columns, contrib)); } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java index 26b8371cc..20d286c51 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java @@ -277,7 +277,7 @@ public FullScheduledSummary(InterruptibleFuture calculation) { return summary; }); - this.documentation = config.providesDocumentation ? + this.documentation = config.providesHovers ? mapCalculation(SummaryFields.DOCUMENTATION, calculation, SummaryFields.DOCUMENTATION, ParametricSummaryFactory::mapValueToString) : null; this.definitions = config.providesDefinitions ? mapCalculation(SummaryFields.DEFINITIONS, calculation, SummaryFields.DEFINITIONS, locationMapper(columns)) : null; @@ -435,22 +435,22 @@ public OndemandSummary(ISourceLocation file, Versioned tree, Position cur @Override @SuppressWarnings("deprecation") // For `MarkedString` public @Nullable InterruptibleFuture>> getDocumentation(Position cursor) { - return get(config.providesDocumentation, cursor, contrib::documentation, ParametricSummaryFactory::mapValueToString, SummaryFields.DOCUMENTATION); + return get(config.providesHovers, cursor, contrib::runHoverService, ParametricSummaryFactory::mapValueToString, SummaryFields.DOCUMENTATION); } @Override public @Nullable InterruptibleFuture> getDefinitions(Position cursor) { - return get(config.providesDefinitions, cursor, contrib::definitions, locationMapper(columns), SummaryFields.DEFINITIONS); + return get(config.providesDefinitions, cursor, contrib::runDefinitionService, locationMapper(columns), SummaryFields.DEFINITIONS); } @Override public @Nullable InterruptibleFuture> getReferences(Position cursor) { - return get(config.providesReferences, cursor, contrib::references, locationMapper(columns), SummaryFields.REFERENCES); + return get(config.providesReferences, cursor, contrib::runReferencesService, locationMapper(columns), SummaryFields.REFERENCES); } @Override public @Nullable InterruptibleFuture> getImplementations(Position cursor) { - return get(config.providesImplementations, cursor, contrib::implementations, locationMapper(columns), SummaryFields.IMPLEMENTATIONS); + return get(config.providesImplementations, cursor, contrib::runImplementationService, locationMapper(columns), SummaryFields.IMPLEMENTATIONS); } @Override From 90eaac84ee07554bda8763ee1d16bc8178664b00 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Thu, 17 Oct 2024 10:43:32 +0200 Subject: [PATCH 39/57] Rename methods in `LanguageContributionsMultiplexer` to be consistent with LSP --- .../LanguageContributionsMultiplexer.java | 149 +++++++++--------- 1 file changed, 74 insertions(+), 75 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java index ebb357776..d865de2cb 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java @@ -51,31 +51,32 @@ private static final CompletableFuture failedInitialization() { return CompletableFuture.failedFuture(new RuntimeException("No contributions registered")); } - private volatile @MonotonicNonNull ILanguageContributions parser = null; - private volatile CompletableFuture outliner = failedInitialization(); - private volatile CompletableFuture analyzer = failedInitialization(); - private volatile CompletableFuture builder = failedInitialization(); - private volatile CompletableFuture lensDetector = failedInitialization(); - private volatile CompletableFuture commandExecutor = failedInitialization(); - private volatile CompletableFuture inlayHinter = failedInitialization(); - private volatile CompletableFuture definer = failedInitialization(); - private volatile CompletableFuture documenter = failedInitialization(); - private volatile CompletableFuture referrer = failedInitialization(); - private volatile CompletableFuture implementer = failedInitialization(); - private volatile CompletableFuture codeActionContributor = failedInitialization(); - - private volatile CompletableFuture hasDocumenter = failedInitialization(); - private volatile CompletableFuture hasDefiner = failedInitialization(); - private volatile CompletableFuture hasReferrer = failedInitialization(); - private volatile CompletableFuture hasImplementer = failedInitialization(); - - private volatile CompletableFuture hasOutliner = failedInitialization(); - private volatile CompletableFuture hasAnalyzer = failedInitialization(); - private volatile CompletableFuture hasBuilder = failedInitialization(); - private volatile CompletableFuture hasLensDetector = failedInitialization(); - private volatile CompletableFuture hasCommandExecutor = failedInitialization(); - private volatile CompletableFuture hasInlayHinter = failedInitialization(); - private volatile CompletableFuture hasCodeActionContributor = failedInitialization(); + private volatile @MonotonicNonNull ILanguageContributions parsingService = null; + + private volatile CompletableFuture getAnalysisService = failedInitialization(); + private volatile CompletableFuture getBuildService = failedInitialization(); + private volatile CompletableFuture getDocumentSymbolService = failedInitialization(); + private volatile CompletableFuture getCodeLensService = failedInitialization(); + private volatile CompletableFuture getInlayHintService = failedInitialization(); + private volatile CompletableFuture getExecutionService = failedInitialization(); + private volatile CompletableFuture getHoverService = failedInitialization(); + private volatile CompletableFuture getDefinitionService = failedInitialization(); + private volatile CompletableFuture getReferencesService = failedInitialization(); + private volatile CompletableFuture getImplementationService = failedInitialization(); + private volatile CompletableFuture getCodeActionService = failedInitialization(); + + + private volatile CompletableFuture hasAnalysisService = failedInitialization(); + private volatile CompletableFuture hasBuildService = failedInitialization(); + private volatile CompletableFuture hasDocumentSymbolService = failedInitialization(); + private volatile CompletableFuture hasCodeLensService = failedInitialization(); + private volatile CompletableFuture hasInlayHintService = failedInitialization(); + private volatile CompletableFuture hasExecutionService = failedInitialization(); + private volatile CompletableFuture hasHoverService = failedInitialization(); + private volatile CompletableFuture hasDefinitionService = failedInitialization(); + private volatile CompletableFuture hasReferencesService = failedInitialization(); + private volatile CompletableFuture hasImplementationService = failedInitialization(); + private volatile CompletableFuture hasCodeActionService = failedInitialization(); private volatile CompletableFuture analyzerSummaryConfig; private volatile CompletableFuture builderSummaryConfig; @@ -134,30 +135,30 @@ private synchronized void calculateRouting() { // this is to avoid doing this lookup every time we get a request // we calculate the "route" once, and then just chain onto the completed // future - parser = firstOrFail(); - outliner = findFirstOrDefault(ILanguageContributions::hasDocumentSymbolService); - analyzer = findFirstOrDefault(ILanguageContributions::hasAnalysisService); - builder = findFirstOrDefault(ILanguageContributions::hasBuildService); - lensDetector = findFirstOrDefault(ILanguageContributions::hasCodeLensDetector); - commandExecutor = findFirstOrDefault(ILanguageContributions::hasExecutionService); - inlayHinter = findFirstOrDefault(ILanguageContributions::hasInlayHintService); - definer = findFirstOrDefault(ILanguageContributions::hasDefinitionService); - documenter = findFirstOrDefault(ILanguageContributions::hasHoverService); - referrer = findFirstOrDefault(ILanguageContributions::hasReferencesService); - implementer = findFirstOrDefault(ILanguageContributions::hasImplementationService); - codeActionContributor = findFirstOrDefault(ILanguageContributions::hasCodeActionService); - - hasDocumenter = anyTrue(ILanguageContributions::hasHoverService); - hasDefiner = anyTrue(ILanguageContributions::hasDefinitionService); - hasReferrer = anyTrue(ILanguageContributions::hasReferencesService); - hasImplementer = anyTrue(ILanguageContributions::hasImplementationService); - - hasOutliner = anyTrue(ILanguageContributions::hasDocumentSymbolService); - hasAnalyzer = anyTrue(ILanguageContributions::hasAnalysisService); - hasBuilder = anyTrue(ILanguageContributions::hasBuildService); - hasLensDetector = anyTrue(ILanguageContributions::hasCodeLensDetector); - hasCommandExecutor = anyTrue(ILanguageContributions::hasExecutionService); - hasInlayHinter = anyTrue(ILanguageContributions::hasInlayHintService); + parsingService = firstOrFail(); + getAnalysisService = findFirstOrDefault(ILanguageContributions::hasAnalysisService); + getBuildService = findFirstOrDefault(ILanguageContributions::hasBuildService); + getDocumentSymbolService = findFirstOrDefault(ILanguageContributions::hasDocumentSymbolService); + getCodeLensService = findFirstOrDefault(ILanguageContributions::hasCodeLensDetector); + getInlayHintService = findFirstOrDefault(ILanguageContributions::hasInlayHintService); + getExecutionService = findFirstOrDefault(ILanguageContributions::hasExecutionService); + getHoverService = findFirstOrDefault(ILanguageContributions::hasHoverService); + getDefinitionService = findFirstOrDefault(ILanguageContributions::hasDefinitionService); + getReferencesService = findFirstOrDefault(ILanguageContributions::hasReferencesService); + getImplementationService = findFirstOrDefault(ILanguageContributions::hasImplementationService); + getCodeActionService = findFirstOrDefault(ILanguageContributions::hasCodeActionService); + + + hasAnalysisService = anyTrue(ILanguageContributions::hasAnalysisService); + hasBuildService = anyTrue(ILanguageContributions::hasBuildService); + hasDocumentSymbolService = anyTrue(ILanguageContributions::hasDocumentSymbolService); + hasCodeLensService = anyTrue(ILanguageContributions::hasCodeLensDetector); + hasInlayHintService = anyTrue(ILanguageContributions::hasInlayHintService); + hasExecutionService = anyTrue(ILanguageContributions::hasExecutionService); + hasHoverService = anyTrue(ILanguageContributions::hasHoverService); + hasDefinitionService = anyTrue(ILanguageContributions::hasDefinitionService); + hasReferencesService = anyTrue(ILanguageContributions::hasReferencesService); + hasImplementationService = anyTrue(ILanguageContributions::hasImplementationService); analyzerSummaryConfig = anyTrue(ILanguageContributions::getAnalyzerSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); builderSummaryConfig = anyTrue(ILanguageContributions::getBuilderSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); @@ -172,8 +173,6 @@ private ILanguageContributions firstOrFail() { return it.next().contrib; } - - private CompletableFuture findFirstOrDefault(Function> filter) { return CompletableFuture.supplyAsync(() -> { for (var c : contributions) { @@ -219,7 +218,7 @@ public String getName() { @Override public CompletableFuture runParsingService(ISourceLocation loc, String input) { - var p = parser; + var p = parsingService; if (p == null) { return failedInitialization(); } @@ -233,117 +232,117 @@ private InterruptibleFuture flatten(CompletableFuture runDocumentSymbolService(ITree input) { - return flatten(outliner, c -> c.runDocumentSymbolService(input)); + return flatten(getDocumentSymbolService, c -> c.runDocumentSymbolService(input)); } @Override public InterruptibleFuture runAnalysisService(ISourceLocation loc, ITree input) { - return flatten(analyzer, c -> c.runAnalysisService(loc, input)); + return flatten(getAnalysisService, c -> c.runAnalysisService(loc, input)); } @Override public InterruptibleFuture runBuildService(ISourceLocation loc, ITree input) { - return flatten(builder, c -> c.runBuildService(loc, input)); + return flatten(getBuildService, c -> c.runBuildService(loc, input)); } @Override public InterruptibleFuture runCodeLensService(ITree input) { - return flatten(lensDetector, c -> c.runCodeLensService(input)); + return flatten(getCodeLensService, c -> c.runCodeLensService(input)); } @Override public InterruptibleFuture<@Nullable IValue> runExecutionService(String command) { - return flatten(commandExecutor, c -> c.runExecutionService(command)); + return flatten(getExecutionService, c -> c.runExecutionService(command)); } @Override public CompletableFuture parseCodeActions(String command) { - return commandExecutor.thenApply(c -> c.parseCodeActions(command)).thenCompose(Function.identity()); + return getExecutionService.thenApply(c -> c.parseCodeActions(command)).thenCompose(Function.identity()); } @Override public InterruptibleFuture runInlayHintService(@Nullable ITree input) { - return flatten(inlayHinter, c -> c.runInlayHintService(input)); + return flatten(getInlayHintService, c -> c.runInlayHintService(input)); } @Override public InterruptibleFuture runHoverService(IList focus) { - return flatten(documenter, c -> c.runHoverService(focus)); + return flatten(getHoverService, c -> c.runHoverService(focus)); } @Override public InterruptibleFuture runDefinitionService(IList focus) { - return flatten(definer, c -> c.runDefinitionService(focus)); + return flatten(getDefinitionService, c -> c.runDefinitionService(focus)); } @Override public InterruptibleFuture runReferencesService(IList focus) { - return flatten(referrer, c -> c.runReferencesService(focus)); + return flatten(getReferencesService, c -> c.runReferencesService(focus)); } @Override public InterruptibleFuture runImplementationService(IList focus) { - return flatten(implementer, c -> c.runImplementationService(focus)); + return flatten(getImplementationService, c -> c.runImplementationService(focus)); } @Override public InterruptibleFuture runCodeActionService(IList focus) { - return flatten(codeActionContributor, c -> c.runCodeActionService(focus)); + return flatten(getCodeActionService, c -> c.runCodeActionService(focus)); } @Override public CompletableFuture hasCodeActionService() { - return hasCodeActionContributor; + return hasCodeActionService; } @Override public CompletableFuture hasHoverService() { - return hasDocumenter; + return hasHoverService; } @Override public CompletableFuture hasDefinitionService() { - return hasDefiner; + return hasDefinitionService; } @Override public CompletableFuture hasReferencesService() { - return hasReferrer; + return hasReferencesService; } @Override public CompletableFuture hasImplementationService() { - return hasImplementer; + return hasImplementationService; } @Override public CompletableFuture hasDocumentSymbolService() { - return hasOutliner; + return hasDocumentSymbolService; } @Override public CompletableFuture hasAnalysisService() { - return hasAnalyzer; + return hasAnalysisService; } @Override public CompletableFuture hasBuildService() { - return hasBuilder; + return hasBuildService; } @Override public CompletableFuture hasCodeLensDetector() { - return hasLensDetector; + return hasCodeLensService; } @Override public CompletableFuture hasExecutionService() { - return hasCommandExecutor; + return hasExecutionService; } @Override public CompletableFuture hasInlayHintService() { - return hasInlayHinter; + return hasInlayHintService; } @Override From 231157d2a604b220a63feb40bff0c9b5f97741ae Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Thu, 17 Oct 2024 11:08:46 +0200 Subject: [PATCH 40/57] Rename methods in `InterpretedLanguageContributions` to be consistent with LSP --- .../InterpretedLanguageContributions.java | 141 +++++++++--------- 1 file changed, 71 insertions(+), 70 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java index 07f001a84..da1b665a9 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java @@ -74,30 +74,31 @@ public class InterpretedLanguageContributions implements ILanguageContributions private final CompletableFuture eval; private final CompletableFuture store; - private final CompletableFuture parser; - private final CompletableFuture<@Nullable IFunction> outliner; - private final CompletableFuture<@Nullable IFunction> analyzer; - private final CompletableFuture<@Nullable IFunction> builder; - private final CompletableFuture<@Nullable IFunction> lenses; - private final CompletableFuture<@Nullable IFunction> commandExecutor; - private final CompletableFuture<@Nullable IFunction> inlayHinter; - private final CompletableFuture<@Nullable IFunction> documenter; - 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 hasOutliner; - private final CompletableFuture hasAnalyzer; - private final CompletableFuture hasBuilder; - private final CompletableFuture hasLensDetector; - private final CompletableFuture hasCommandExecutor; - private final CompletableFuture hasInlayHinter; - private final CompletableFuture hasDocumenter; - private final CompletableFuture hasDefiner; - private final CompletableFuture hasReferrer; - private final CompletableFuture hasImplementer; - private final CompletableFuture hasCodeActionContributor; + + private final CompletableFuture parsingService; + private final CompletableFuture<@Nullable IFunction> analysisService; + private final CompletableFuture<@Nullable IFunction> buildService; + private final CompletableFuture<@Nullable IFunction> documentSymbolService; + private final CompletableFuture<@Nullable IFunction> codeLensService; + private final CompletableFuture<@Nullable IFunction> inlayHintService; + private final CompletableFuture<@Nullable IFunction> executionService; + private final CompletableFuture<@Nullable IFunction> hoverService; + private final CompletableFuture<@Nullable IFunction> definitionService; + private final CompletableFuture<@Nullable IFunction> referencesService; + private final CompletableFuture<@Nullable IFunction> implementationService; + private final CompletableFuture<@Nullable IFunction> codeActionService; + + private final CompletableFuture hasAnalysisService; + private final CompletableFuture hasBuildService; + private final CompletableFuture hasDocumentSymbolService; + private final CompletableFuture hasCodeLensService; + private final CompletableFuture hasInlayHintService; + private final CompletableFuture hasExecutionService; + private final CompletableFuture hasHoverService; + private final CompletableFuture hasDefinitionService; + private final CompletableFuture hasReferencesService; + private final CompletableFuture hasImplementationService; + private final CompletableFuture hasCodeActionService; private final CompletableFuture analyzerSummaryConfig; private final CompletableFuture builderSummaryConfig; @@ -122,31 +123,31 @@ public InterpretedLanguageContributions(LanguageParameter lang, IBaseTextDocumen ValueFactoryFactory.getValueFactory().set(), exec, true, client).get(); this.store = eval.thenApply(e -> ((ModuleEnvironment)e.getModule(mainModule)).getStore()); - this.parser = getFunctionFor(contributions, LanguageContributions.PARSER); - this.outliner = getFunctionFor(contributions, LanguageContributions.OUTLINER); - this.analyzer = getFunctionFor(contributions, LanguageContributions.ANALYZER); - this.builder = getFunctionFor(contributions, LanguageContributions.BUILDER); - this.lenses = getFunctionFor(contributions, LanguageContributions.LENS_DETECTOR); - this.commandExecutor = getFunctionFor(contributions, LanguageContributions.COMMAND_EXECUTOR); - this.inlayHinter = getFunctionFor(contributions, LanguageContributions.INLAY_HINTER); - this.documenter = getFunctionFor(contributions, LanguageContributions.DOCUMENTER); - 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); + this.parsingService = getFunctionFor(contributions, LanguageContributions.PARSER); + this.analysisService = getFunctionFor(contributions, LanguageContributions.ANALYZER); + this.buildService = getFunctionFor(contributions, LanguageContributions.BUILDER); + this.documentSymbolService = getFunctionFor(contributions, LanguageContributions.OUTLINER); + this.codeLensService = getFunctionFor(contributions, LanguageContributions.LENS_DETECTOR); + this.inlayHintService = getFunctionFor(contributions, LanguageContributions.INLAY_HINTER); + this.executionService = getFunctionFor(contributions, LanguageContributions.COMMAND_EXECUTOR); + this.hoverService = getFunctionFor(contributions, LanguageContributions.DOCUMENTER); + this.definitionService = getFunctionFor(contributions, LanguageContributions.DEFINER); + this.referencesService = getFunctionFor(contributions, LanguageContributions.REFERRER); + this.implementationService = getFunctionFor(contributions, LanguageContributions.IMPLEMENTER); + this.codeActionService = getFunctionFor(contributions, LanguageContributions.CODE_ACTION_CONTRIBUTOR); // assign boolean properties once instead of wasting futures all the time - this.hasOutliner = nonNull(this.outliner); - this.hasAnalyzer = nonNull(this.analyzer); - this.hasBuilder = nonNull(this.builder); - this.hasLensDetector = nonNull(this.lenses); - this.hasCommandExecutor = nonNull(this.commandExecutor); - this.hasInlayHinter = nonNull(this.inlayHinter); - this.hasDocumenter = nonNull(this.documenter); - this.hasDefiner = nonNull(this.definer); - this.hasReferrer = nonNull(this.referrer); - this.hasImplementer = nonNull(this.implementer); - this.hasCodeActionContributor = nonNull(this.codeActionContributor); + this.hasAnalysisService = nonNull(this.analysisService); + this.hasBuildService = nonNull(this.buildService); + this.hasDocumentSymbolService = nonNull(this.documentSymbolService); + this.hasCodeLensService = nonNull(this.codeLensService); + this.hasInlayHintService = nonNull(this.inlayHintService); + this.hasExecutionService = nonNull(this.executionService); + this.hasHoverService = nonNull(this.hoverService); + this.hasDefinitionService = nonNull(this.definitionService); + this.hasReferencesService = nonNull(this.referencesService); + this.hasImplementationService = nonNull(this.implementationService); + this.hasCodeActionService = nonNull(this.codeActionService); this.analyzerSummaryConfig = scheduledSummaryConfig(contributions, LanguageContributions.ANALYZER); this.builderSummaryConfig = scheduledSummaryConfig(contributions, LanguageContributions.BUILDER); @@ -259,67 +260,67 @@ public String getName() { @Override public CompletableFuture runParsingService(ISourceLocation loc, String input) { debug(LanguageContributions.PARSER, loc, input); - return parser.thenApplyAsync(p -> p.call(VF.string(input), loc), exec); + return parsingService.thenApplyAsync(p -> p.call(VF.string(input), loc), exec); } @Override public InterruptibleFuture runDocumentSymbolService(ITree input) { debug(LanguageContributions.OUTLINER, TreeAdapter.getLocation(input)); - return execFunction(LanguageContributions.OUTLINER, outliner, VF.list(), input); + return execFunction(LanguageContributions.OUTLINER, documentSymbolService, VF.list(), input); } @Override public InterruptibleFuture runAnalysisService(ISourceLocation src, ITree input) { debug(LanguageContributions.ANALYZER, src); - return execFunction(LanguageContributions.ANALYZER, analyzer, EmptySummary.newInstance(src), src, input); + return execFunction(LanguageContributions.ANALYZER, analysisService, EmptySummary.newInstance(src), src, input); } @Override public InterruptibleFuture runBuildService(ISourceLocation src, ITree input) { debug(LanguageContributions.BUILDER, src); - return execFunction(LanguageContributions.BUILDER, builder, EmptySummary.newInstance(src), src, input); + return execFunction(LanguageContributions.BUILDER, buildService, EmptySummary.newInstance(src), src, input); } @Override public InterruptibleFuture runCodeLensService(ITree input) { debug(LanguageContributions.LENS_DETECTOR, TreeAdapter.getLocation(input)); - return execFunction(LanguageContributions.LENS_DETECTOR, lenses, VF.list(), input); + return execFunction(LanguageContributions.LENS_DETECTOR, codeLensService, VF.list(), input); } @Override public InterruptibleFuture runInlayHintService(@Nullable ITree input) { debug(LanguageContributions.INLAY_HINTER, input != null ? TreeAdapter.getLocation(input) : null); - return execFunction(LanguageContributions.INLAY_HINTER, inlayHinter, VF.list(), input); + return execFunction(LanguageContributions.INLAY_HINTER, inlayHintService, VF.list(), input); } @Override public InterruptibleFuture runHoverService(IList focus) { debug(LanguageContributions.DOCUMENTER, focus.length()); - return execFunction(LanguageContributions.DOCUMENTER, documenter, VF.set(), focus); + return execFunction(LanguageContributions.DOCUMENTER, hoverService, VF.set(), focus); } @Override public InterruptibleFuture runDefinitionService(IList focus) { debug(LanguageContributions.DEFINER, focus.length()); - return execFunction(LanguageContributions.DEFINER, definer, VF.set(), focus); + return execFunction(LanguageContributions.DEFINER, definitionService, VF.set(), focus); } @Override public InterruptibleFuture runImplementationService(IList focus) { debug(LanguageContributions.IMPLEMENTER, focus.length()); - return execFunction(LanguageContributions.IMPLEMENTER, implementer, VF.set(), focus); + return execFunction(LanguageContributions.IMPLEMENTER, implementationService, VF.set(), focus); } @Override public InterruptibleFuture runReferencesService(IList focus) { debug(LanguageContributions.REFERRER, focus.length()); - return execFunction(LanguageContributions.REFERRER, referrer, VF.set(), focus); + return execFunction(LanguageContributions.REFERRER, referencesService, VF.set(), focus); } @Override public InterruptibleFuture runCodeActionService(IList focus) { debug(LanguageContributions.CODE_ACTION_CONTRIBUTOR, focus.length()); - return execFunction(LanguageContributions.CODE_ACTION_CONTRIBUTOR, codeActionContributor, VF.list(), focus); + return execFunction(LanguageContributions.CODE_ACTION_CONTRIBUTOR, codeActionService, VF.list(), focus); } private void debug(String name, Object param) { @@ -332,57 +333,57 @@ private void debug(String name, Object param1, Object param2) { @Override public CompletableFuture hasDefinitionService() { - return hasDefiner; + return hasDefinitionService; } @Override public CompletableFuture hasReferencesService() { - return hasReferrer; + return hasReferencesService; } @Override public CompletableFuture hasImplementationService() { - return hasImplementer; + return hasImplementationService; } @Override public CompletableFuture hasHoverService() { - return hasDocumenter; + return hasHoverService; } @Override public CompletableFuture hasExecutionService() { - return hasCommandExecutor; + return hasExecutionService; } @Override public CompletableFuture hasInlayHintService() { - return hasInlayHinter; + return hasInlayHintService; } @Override public CompletableFuture hasCodeLensDetector() { - return hasLensDetector; + return hasCodeLensService; } @Override public CompletableFuture hasDocumentSymbolService() { - return hasOutliner; + return hasDocumentSymbolService; } @Override public CompletableFuture hasCodeActionService() { - return hasCodeActionContributor; + return hasCodeActionService; } @Override public CompletableFuture hasAnalysisService() { - return hasAnalyzer; + return hasAnalysisService; } @Override public CompletableFuture hasBuildService() { - return hasBuilder; + return hasBuildService; } @Override @@ -406,7 +407,7 @@ public CompletableFuture getOndemandSummaryConfig() { logger.trace("Full command: {}", command); return InterruptibleFuture.flatten(parseCommand(command).thenCombine( - commandExecutor, + executionService, (cons, func) -> { if (func == null) { From 3aeef96edbe1f5bf49500b29ea2000059a3ad10c Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Mon, 21 Oct 2024 14:52:15 +0200 Subject: [PATCH 41/57] Fix flaky UI test --- .../src/test/vscode-suite/dsl.test.ts | 18 +++++++++++++++--- .../src/test/vscode-suite/utils.ts | 6 +++++- runUItests.sh | 5 ++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/rascal-vscode-extension/src/test/vscode-suite/dsl.test.ts b/rascal-vscode-extension/src/test/vscode-suite/dsl.test.ts index 287331323..976452b4a 100644 --- a/rascal-vscode-extension/src/test/vscode-suite/dsl.test.ts +++ b/rascal-vscode-extension/src/test/vscode-suite/dsl.test.ts @@ -47,13 +47,14 @@ describe('DSL', function () { const repl = new RascalREPL(bench, driver); await repl.start(); await repl.execute("import demo::lang::pico::LanguageServer;"); - repl.execute("main();"); // we don't wait, be cause we might miss pico loading window + const replExecuteMain = repl.execute("main();"); // we don't wait yet, because we might miss pico loading window const ide = new IDEOperations(browser); const isPicoLoading = ide.statusContains("Pico"); await driver.wait(isPicoLoading, Delays.slow, "Pico DSL should start loading"); - await repl.terminate(); - // now wait for the Pico loader to dissapear + // now wait for the Pico loader to disappear await driver.wait(async () => !(await isPicoLoading()), Delays.extremelySlow, "Pico DSL should be finished starting", 100); + await replExecuteMain; + await repl.terminate(); } @@ -70,6 +71,12 @@ describe('DSL', function () { await ide.load(); }); + beforeEach(async function () { + if (this.test?.title) { + await ide.screenshot("DSL-" + this.test?.title); + } + }); + afterEach(async function () { if (this.test?.title) { await ide.screenshot("DSL-" + this.test?.title); @@ -87,6 +94,11 @@ describe('DSL', function () { try { await editor.setTextAtLine(10, "b := ;"); await ide.hasErrorSquiggly(editor, Delays.slow); + } catch (e) { + console.log(`Failed to trigger parse error: ${e}`); + if (e instanceof Error) { + console.log(e.stack); + } } finally { await ide.revertOpenChanges(); } diff --git a/rascal-vscode-extension/src/test/vscode-suite/utils.ts b/rascal-vscode-extension/src/test/vscode-suite/utils.ts index 680991d24..9ec8a51bd 100644 --- a/rascal-vscode-extension/src/test/vscode-suite/utils.ts +++ b/rascal-vscode-extension/src/test/vscode-suite/utils.ts @@ -315,8 +315,12 @@ export class IDEOperations { }; } + private screenshotSeqNumber = 0; + screenshot(name: string): Promise { - return this.browser.takeScreenshot(name.replace(/[/\\?%*:|"<>]/g, '-')); + return this.browser.takeScreenshot( + `${String(this.screenshotSeqNumber++).padStart(4, '0')}-` + // Make sorting screenshots chronologically in VS Code easier + name.replace(/[/\\?%*:|"<>]/g, '-')); } } diff --git a/runUItests.sh b/runUItests.sh index 641c9ef20..7e05214f0 100755 --- a/runUItests.sh +++ b/runUItests.sh @@ -21,4 +21,7 @@ npm run compile-tests # test what was compiled -exec npx extest setup-and-run out/test/vscode-suite/*.test.js --storage $UITESTS +exec npx extest setup-and-run out/test/vscode-suite/*.test.js \ + --code_version 1.82.3 \ + --storage $UITESTS \ + --extensions_dir $UITESTS/extensions_dir \ No newline at end of file From 59e361e8be09882f2f88af30d4fed8e5270be1ae Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Mon, 21 Oct 2024 15:50:14 +0200 Subject: [PATCH 42/57] Rename methods in `RascalADTs` to be consistent with LSP --- .../InterpretedLanguageContributions.java | 100 +++++++++--------- .../parametric/model/ParametricSummary.java | 10 +- .../lsp/parametric/model/RascalADTs.java | 40 +++---- 3 files changed, 76 insertions(+), 74 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java index da1b665a9..7c6c8ec72 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java @@ -122,35 +122,37 @@ public InterpretedLanguageContributions(LanguageParameter lang, IBaseTextDocumen e -> loadContributions(e, lang), ValueFactoryFactory.getValueFactory().set(), exec, true, client).get(); + this.store = eval.thenApply(e -> ((ModuleEnvironment)e.getModule(mainModule)).getStore()); - this.parsingService = getFunctionFor(contributions, LanguageContributions.PARSER); - this.analysisService = getFunctionFor(contributions, LanguageContributions.ANALYZER); - this.buildService = getFunctionFor(contributions, LanguageContributions.BUILDER); - this.documentSymbolService = getFunctionFor(contributions, LanguageContributions.OUTLINER); - this.codeLensService = getFunctionFor(contributions, LanguageContributions.LENS_DETECTOR); - this.inlayHintService = getFunctionFor(contributions, LanguageContributions.INLAY_HINTER); - this.executionService = getFunctionFor(contributions, LanguageContributions.COMMAND_EXECUTOR); - this.hoverService = getFunctionFor(contributions, LanguageContributions.DOCUMENTER); - this.definitionService = getFunctionFor(contributions, LanguageContributions.DEFINER); - this.referencesService = getFunctionFor(contributions, LanguageContributions.REFERRER); - this.implementationService = getFunctionFor(contributions, LanguageContributions.IMPLEMENTER); - this.codeActionService = getFunctionFor(contributions, LanguageContributions.CODE_ACTION_CONTRIBUTOR); + + this.parsingService = getFunctionFor(contributions, LanguageContributions.PARSING); + this.analysisService = getFunctionFor(contributions, LanguageContributions.ANALYSIS); + this.buildService = getFunctionFor(contributions, LanguageContributions.BUILD); + this.documentSymbolService = getFunctionFor(contributions, LanguageContributions.DOCUMENT_SYMBOL); + this.codeLensService = getFunctionFor(contributions, LanguageContributions.CODE_LENS); + this.inlayHintService = getFunctionFor(contributions, LanguageContributions.INLAY_HINT); + this.executionService = getFunctionFor(contributions, LanguageContributions.EXECUTION); + this.hoverService = getFunctionFor(contributions, LanguageContributions.HOVER); + this.definitionService = getFunctionFor(contributions, LanguageContributions.DEFINITION); + this.referencesService = getFunctionFor(contributions, LanguageContributions.REFERENCES); + this.implementationService = getFunctionFor(contributions, LanguageContributions.IMPLEMENTATION); + this.codeActionService = getFunctionFor(contributions, LanguageContributions.CODE_ACTION); // assign boolean properties once instead of wasting futures all the time - this.hasAnalysisService = nonNull(this.analysisService); - this.hasBuildService = nonNull(this.buildService); + this.hasAnalysisService = nonNull(this.analysisService); + this.hasBuildService = nonNull(this.buildService); this.hasDocumentSymbolService = nonNull(this.documentSymbolService); - this.hasCodeLensService = nonNull(this.codeLensService); - this.hasInlayHintService = nonNull(this.inlayHintService); - this.hasExecutionService = nonNull(this.executionService); - this.hasHoverService = nonNull(this.hoverService); - this.hasDefinitionService = nonNull(this.definitionService); - this.hasReferencesService = nonNull(this.referencesService); + this.hasCodeLensService = nonNull(this.codeLensService); + this.hasInlayHintService = nonNull(this.inlayHintService); + this.hasExecutionService = nonNull(this.executionService); + this.hasHoverService = nonNull(this.hoverService); + this.hasDefinitionService = nonNull(this.definitionService); + this.hasReferencesService = nonNull(this.referencesService); this.hasImplementationService = nonNull(this.implementationService); - this.hasCodeActionService = nonNull(this.codeActionService); + this.hasCodeActionService = nonNull(this.codeActionService); - this.analyzerSummaryConfig = scheduledSummaryConfig(contributions, LanguageContributions.ANALYZER); - this.builderSummaryConfig = scheduledSummaryConfig(contributions, LanguageContributions.BUILDER); + this.analyzerSummaryConfig = scheduledSummaryConfig(contributions, LanguageContributions.ANALYSIS); + this.builderSummaryConfig = scheduledSummaryConfig(contributions, LanguageContributions.BUILD); this.ondemandSummaryConfig = ondemandSummaryConfig(contributions); } catch (IOException e1) { @@ -168,7 +170,7 @@ private static CompletableFuture scheduledSummaryConfig(Completab var constructor = getContribution(c, summarizer); if (constructor != null) { return new SummaryConfig( - isTrue(constructor, LanguageContributions.Summarizers.PROVIDES_DOCUMENTATION), + isTrue(constructor, LanguageContributions.Summarizers.PROVIDES_HOVERS), isTrue(constructor, LanguageContributions.Summarizers.PROVIDES_DEFINITIONS), isTrue(constructor, LanguageContributions.Summarizers.PROVIDES_REFERENCES), isTrue(constructor, LanguageContributions.Summarizers.PROVIDES_IMPLEMENTATIONS)); @@ -181,10 +183,10 @@ private static CompletableFuture scheduledSummaryConfig(Completab private static CompletableFuture ondemandSummaryConfig(CompletableFuture contributions) { return contributions.thenApply(c -> new SummaryConfig( - hasContribution(c, LanguageContributions.DOCUMENTER), - hasContribution(c, LanguageContributions.DEFINER), - hasContribution(c, LanguageContributions.REFERRER), - hasContribution(c, LanguageContributions.IMPLEMENTER))); + hasContribution(c, LanguageContributions.HOVER), + hasContribution(c, LanguageContributions.DEFINITION), + hasContribution(c, LanguageContributions.REFERENCES), + hasContribution(c, LanguageContributions.IMPLEMENTATION))); } private static @Nullable IConstructor getContribution(ISet contributions, String name) { @@ -259,68 +261,68 @@ public String getName() { @Override public CompletableFuture runParsingService(ISourceLocation loc, String input) { - debug(LanguageContributions.PARSER, loc, input); + debug(LanguageContributions.PARSING, loc, input); return parsingService.thenApplyAsync(p -> p.call(VF.string(input), loc), exec); } @Override public InterruptibleFuture runDocumentSymbolService(ITree input) { - debug(LanguageContributions.OUTLINER, TreeAdapter.getLocation(input)); - return execFunction(LanguageContributions.OUTLINER, documentSymbolService, VF.list(), input); + debug(LanguageContributions.DOCUMENT_SYMBOL, TreeAdapter.getLocation(input)); + return execFunction(LanguageContributions.DOCUMENT_SYMBOL, documentSymbolService, VF.list(), input); } @Override public InterruptibleFuture runAnalysisService(ISourceLocation src, ITree input) { - debug(LanguageContributions.ANALYZER, src); - return execFunction(LanguageContributions.ANALYZER, analysisService, EmptySummary.newInstance(src), src, input); + debug(LanguageContributions.ANALYSIS, src); + return execFunction(LanguageContributions.ANALYSIS, analysisService, EmptySummary.newInstance(src), src, input); } @Override public InterruptibleFuture runBuildService(ISourceLocation src, ITree input) { - debug(LanguageContributions.BUILDER, src); - return execFunction(LanguageContributions.BUILDER, buildService, EmptySummary.newInstance(src), src, input); + debug(LanguageContributions.BUILD, src); + return execFunction(LanguageContributions.BUILD, buildService, EmptySummary.newInstance(src), src, input); } @Override public InterruptibleFuture runCodeLensService(ITree input) { - debug(LanguageContributions.LENS_DETECTOR, TreeAdapter.getLocation(input)); - return execFunction(LanguageContributions.LENS_DETECTOR, codeLensService, VF.list(), input); + debug(LanguageContributions.CODE_LENS, TreeAdapter.getLocation(input)); + return execFunction(LanguageContributions.CODE_LENS, codeLensService, VF.list(), input); } @Override public InterruptibleFuture runInlayHintService(@Nullable ITree input) { - debug(LanguageContributions.INLAY_HINTER, input != null ? TreeAdapter.getLocation(input) : null); - return execFunction(LanguageContributions.INLAY_HINTER, inlayHintService, VF.list(), input); + debug(LanguageContributions.INLAY_HINT, input != null ? TreeAdapter.getLocation(input) : null); + return execFunction(LanguageContributions.INLAY_HINT, inlayHintService, VF.list(), input); } @Override public InterruptibleFuture runHoverService(IList focus) { - debug(LanguageContributions.DOCUMENTER, focus.length()); - return execFunction(LanguageContributions.DOCUMENTER, hoverService, VF.set(), focus); + debug(LanguageContributions.HOVER, focus.length()); + return execFunction(LanguageContributions.HOVER, hoverService, VF.set(), focus); } @Override public InterruptibleFuture runDefinitionService(IList focus) { - debug(LanguageContributions.DEFINER, focus.length()); - return execFunction(LanguageContributions.DEFINER, definitionService, VF.set(), focus); + debug(LanguageContributions.DEFINITION, focus.length()); + return execFunction(LanguageContributions.DEFINITION, definitionService, VF.set(), focus); } @Override public InterruptibleFuture runImplementationService(IList focus) { - debug(LanguageContributions.IMPLEMENTER, focus.length()); - return execFunction(LanguageContributions.IMPLEMENTER, implementationService, VF.set(), focus); + debug(LanguageContributions.IMPLEMENTATION, focus.length()); + return execFunction(LanguageContributions.IMPLEMENTATION, implementationService, VF.set(), focus); } @Override public InterruptibleFuture runReferencesService(IList focus) { - debug(LanguageContributions.REFERRER, focus.length()); - return execFunction(LanguageContributions.REFERRER, referencesService, VF.set(), focus); + debug(LanguageContributions.REFERENCES, focus.length()); + return execFunction(LanguageContributions.REFERENCES, referencesService, VF.set(), focus); } @Override public InterruptibleFuture runCodeActionService(IList focus) { - debug(LanguageContributions.CODE_ACTION_CONTRIBUTOR, focus.length()); - return execFunction(LanguageContributions.CODE_ACTION_CONTRIBUTOR, codeActionService, VF.list(), focus); + debug(LanguageContributions.CODE_ACTION, focus.length()); + return execFunction(LanguageContributions.CODE_ACTION, codeActionService, VF.list(), focus); } private void debug(String name, Object param) { diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java index 20d286c51..b821093ad 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java @@ -268,17 +268,17 @@ public class FullScheduledSummary extends MessagesOnlyScheduledSummary { public FullScheduledSummary(InterruptibleFuture calculation) { super(calculation); - // for temporary backward compatibility between SummaryFields.DOCUMENTATION and SummaryFields.DEPRECATED_DOCUMENTATION + // for temporary backward compatibility between SummaryFields.HOVERS and SummaryFields.DEPRECATED_DOCUMENTATION calculation = calculation.thenApply(summary -> { var kws = summary.asWithKeywordParameters(); - if (kws.hasParameter(SummaryFields.DEPRECATED_DOCUMENTATION) && !kws.hasParameter(SummaryFields.DOCUMENTATION)) { - return kws.setParameter(SummaryFields.DOCUMENTATION, kws.getParameter(SummaryFields.DEPRECATED_DOCUMENTATION)); + if (kws.hasParameter(SummaryFields.DEPRECATED_DOCUMENTATION) && !kws.hasParameter(SummaryFields.HOVERS)) { + return kws.setParameter(SummaryFields.HOVERS, kws.getParameter(SummaryFields.DEPRECATED_DOCUMENTATION)); } return summary; }); this.documentation = config.providesHovers ? - mapCalculation(SummaryFields.DOCUMENTATION, calculation, SummaryFields.DOCUMENTATION, ParametricSummaryFactory::mapValueToString) : null; + mapCalculation(SummaryFields.HOVERS, calculation, SummaryFields.HOVERS, ParametricSummaryFactory::mapValueToString) : null; this.definitions = config.providesDefinitions ? mapCalculation(SummaryFields.DEFINITIONS, calculation, SummaryFields.DEFINITIONS, locationMapper(columns)) : null; this.references = config.providesReferences ? @@ -435,7 +435,7 @@ public OndemandSummary(ISourceLocation file, Versioned tree, Position cur @Override @SuppressWarnings("deprecation") // For `MarkedString` public @Nullable InterruptibleFuture>> getDocumentation(Position cursor) { - return get(config.providesHovers, cursor, contrib::runHoverService, ParametricSummaryFactory::mapValueToString, SummaryFields.DOCUMENTATION); + return get(config.providesHovers, cursor, contrib::runHoverService, ParametricSummaryFactory::mapValueToString, SummaryFields.HOVERS); } @Override diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java index 5d714ea49..bfa66ddaf 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java @@ -33,26 +33,27 @@ public class RascalADTs { private RascalADTs() {} public static class LanguageContributions { private LanguageContributions () {} - public static final String PARSER = "parsing"; - public static final String ANALYZER = "analysis"; - public static final String BUILDER = "build"; - public static final String OUTLINER = "documentSymbol"; - public static final String LENS_DETECTOR = "codeLens"; - public static final String INLAY_HINTER = "inlayHint"; - public static final String COMMAND_EXECUTOR = "execution"; - public static final String DOCUMENTER = "hover"; - public static final String DEFINER = "definition"; - public static final String REFERRER = "references"; - public static final String IMPLEMENTER = "implementation"; - public static final String CODE_ACTION_CONTRIBUTOR = "codeAction"; + + public static final String PARSING = "parsing"; + public static final String ANALYSIS = "analysis"; + public static final String BUILD = "build"; + public static final String DOCUMENT_SYMBOL = "documentSymbol"; + public static final String CODE_LENS = "codeLens"; + public static final String INLAY_HINT = "inlayHint"; + public static final String EXECUTION = "execution"; + public static final String HOVER = "hover"; + public static final String DEFINITION = "definition"; + public static final String REFERENCES = "references"; + public static final String IMPLEMENTATION = "implementation"; + public static final String CODE_ACTION = "codeAction"; public static class Summarizers { private Summarizers() {} + public static final String PROVIDES_HOVERS = "providesHovers"; + public static final String PROVIDES_DEFINITIONS = "providesDefinitions"; + public static final String PROVIDES_REFERENCES = "providesReferences"; public static final String PROVIDES_IMPLEMENTATIONS = "providesImplementations"; - public static final String PROVIDES_REFERENCES = "providesReferences"; - public static final String PROVIDES_DEFINITIONS = "providesDefinitions"; - public static final String PROVIDES_DOCUMENTATION = "providesDocumentation"; } } @@ -60,11 +61,11 @@ public static class SummaryFields { private SummaryFields() {} public static final String DEPRECATED_DOCUMENTATION = "documentation"; - public static final String DOCUMENTATION = "hovers"; - public static final String DEFINITIONS = "definitions"; - public static final String REFERENCES = "references"; - public static final String IMPLEMENTATIONS = "implementations"; + public static final String HOVERS = "hovers"; + public static final String DEFINITIONS = "definitions"; + public static final String REFERENCES = "references"; + public static final String IMPLEMENTATIONS = "implementations"; } public static class CommandFields { @@ -81,5 +82,4 @@ private CodeActionFields() { } public static final String TITLE = "title"; public static final String KIND = "kind"; } - } From 6b1418b808c04b5378715a5848b53fb848bf6be7 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Mon, 21 Oct 2024 16:07:00 +0200 Subject: [PATCH 43/57] Rename methods in `RascalLanguageServices` to be consistent with LSP --- .../vscode/lsp/rascal/RascalLanguageServices.java | 8 ++++---- .../vscode/lsp/rascal/RascalTextDocumentService.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java index 31688f0f9..eed62f975 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java @@ -79,7 +79,7 @@ public class RascalLanguageServices { private static final Logger logger = LogManager.getLogger(RascalLanguageServices.class); - private final CompletableFuture outlineEvaluator; + private final CompletableFuture documentSymbolEvaluator; private final CompletableFuture semanticEvaluator; private final CompletableFuture compilerEvaluator; @@ -97,7 +97,7 @@ public RascalLanguageServices(RascalTextDocumentService docService, BaseWorkspac var monitor = new RascalLSPMonitor(client, logger); - outlineEvaluator = makeFutureEvaluator(exec, docService, workspaceService, client, "Rascal outline", monitor, null, false, "lang::rascal::lsp::DocumentSymbols"); + documentSymbolEvaluator = makeFutureEvaluator(exec, docService, workspaceService, client, "Rascal document symbols", monitor, null, false, "lang::rascal::lsp::DocumentSymbols"); semanticEvaluator = makeFutureEvaluator(exec, docService, workspaceService, client, "Rascal semantics", monitor, null, true, "lang::rascalcore::check::Summary", "lang::rascal::lsp::refactor::Rename"); compilerEvaluator = makeFutureEvaluator(exec, docService, workspaceService, client, "Rascal compiler", monitor, null, true, "lang::rascalcore::check::Checker"); } @@ -181,14 +181,14 @@ private ISourceLocation getFileLoc(ITree moduleTree) { } - public InterruptibleFuture getOutline(IConstructor module) { + public InterruptibleFuture getDocumentSymbols(IConstructor module) { ISourceLocation loc = getFileLoc((ITree) module); if (loc == null) { return new InterruptibleFuture<>(CompletableFuture.completedFuture(VF.list()), () -> { }); } - return runEvaluator("Rascal Document Symbols", outlineEvaluator, eval -> (IList) eval.call("documentRascalSymbols", module), + return runEvaluator("Rascal Document Symbols", documentSymbolEvaluator, eval -> (IList) eval.call("documentRascalSymbols", module), VF.list(), exec, false, client); } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java index c10163f5b..4d36bc566 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java @@ -268,7 +268,7 @@ public CompletableFuture, List (t == null ? (file.getMostRecentTree().get()) : t)) - .thenCompose(tr -> rascalServices.getOutline(tr).get()) + .thenCompose(tr -> rascalServices.getDocumentSymbols(tr).get()) .thenApply(c -> Outline.buildOutline(c, columns.get(file.getLocation()))) ; } From 7b3e7ac34f8814d02c7ac83c2258b2007b2236f4 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Mon, 21 Oct 2024 16:21:51 +0200 Subject: [PATCH 44/57] Rename methods in `ParametricSummary` to be consistent with LSP --- .../ParametricTextDocumentService.java | 2 +- .../parametric/model/ParametricSummary.java | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java index 3837cd8bc..5a5140412 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java @@ -689,7 +689,7 @@ public CompletableFuture> references(ReferenceParams pa public CompletableFuture hover(HoverParams params) { logger.debug("Hover: {} at {}", params.getTextDocument(), params.getPosition()); return recoverExceptions( - lookup(ParametricSummary::documentation, params.getTextDocument(), params.getPosition()) + lookup(ParametricSummary::hovers, params.getTextDocument(), params.getPosition()) .thenApply(Hover::new) , () -> null); } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java index b821093ad..d2de95508 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java @@ -72,7 +72,7 @@ /** * The purpose of this interface is to provide a general abstraction for - * `Position`-based look-ups of documentation, definitions, references, and + * `Position`-based look-ups of hovers, definitions, references, and * implementations, regardless of which component calculates the requested * information. There are two implementations: * @@ -96,7 +96,7 @@ public interface ParametricSummary { // this happens when no on-demand summarizer exists for the requested // information. @SuppressWarnings("deprecation") // For `MarkedString` - @Nullable InterruptibleFuture>> getDocumentation(Position cursor); + @Nullable InterruptibleFuture>> getHovers(Position cursor); @Nullable InterruptibleFuture> getDefinitions(Position cursor); @Nullable InterruptibleFuture> getReferences(Position cursor); @Nullable InterruptibleFuture> getImplementations(Position cursor); @@ -113,8 +113,8 @@ public static interface SummaryLookup extends BiFunction>> documentation(ParametricSummary summary, Position position) { - return summary.getDocumentation(position); + public static @Nullable InterruptibleFuture>> hovers(ParametricSummary summary, Position position) { + return summary.getHovers(position); } public static @Nullable InterruptibleFuture> definitions(ParametricSummary summary, Position position) { return summary.getDefinitions(position); @@ -139,7 +139,7 @@ public static InterruptibleFuture> getMessages(CompletableFutur class NullSummary implements ParametricSummary { @Override @SuppressWarnings("deprecation") // For `MarkedString` - public @Nullable InterruptibleFuture>> getDocumentation(Position cursor) { + public @Nullable InterruptibleFuture>> getHovers(Position cursor) { return null; } @@ -260,7 +260,7 @@ private InterruptibleFuture>> extractMessages(Interruptibl public class FullScheduledSummary extends MessagesOnlyScheduledSummary { @SuppressWarnings("deprecation") // For `MarkedString` - private final @Nullable InterruptibleFuture>>>> documentation; + private final @Nullable InterruptibleFuture>>>> hovers; private final @Nullable InterruptibleFuture>>> definitions; private final @Nullable InterruptibleFuture>>> references; private final @Nullable InterruptibleFuture>>> implementations; @@ -277,7 +277,7 @@ public FullScheduledSummary(InterruptibleFuture calculation) { return summary; }); - this.documentation = config.providesHovers ? + this.hovers = config.providesHovers ? mapCalculation(SummaryFields.HOVERS, calculation, SummaryFields.HOVERS, ParametricSummaryFactory::mapValueToString) : null; this.definitions = config.providesDefinitions ? mapCalculation(SummaryFields.DEFINITIONS, calculation, SummaryFields.DEFINITIONS, locationMapper(columns)) : null; @@ -289,8 +289,8 @@ public FullScheduledSummary(InterruptibleFuture calculation) { @Override @SuppressWarnings("deprecation") // For `MarkedString` - public @Nullable InterruptibleFuture>> getDocumentation(Position cursor) { - return get(documentation, cursor); + public @Nullable InterruptibleFuture>> getHovers(Position cursor) { + return get(hovers, cursor); } @Override @@ -311,7 +311,7 @@ public FullScheduledSummary(InterruptibleFuture calculation) { @Override public void invalidate() { super.invalidate(); - documentation.interrupt(); + hovers.interrupt(); definitions.interrupt(); references.interrupt(); implementations.interrupt(); @@ -434,7 +434,7 @@ public OndemandSummary(ISourceLocation file, Versioned tree, Position cur @Override @SuppressWarnings("deprecation") // For `MarkedString` - public @Nullable InterruptibleFuture>> getDocumentation(Position cursor) { + public @Nullable InterruptibleFuture>> getHovers(Position cursor) { return get(config.providesHovers, cursor, contrib::runHoverService, ParametricSummaryFactory::mapValueToString, SummaryFields.HOVERS); } From 565b70a77082594cb884b485d019a37df5e36323 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Mon, 21 Oct 2024 16:28:03 +0200 Subject: [PATCH 45/57] Rename methods in `RascalTextDocumentService` to be consistent with LSP --- .../vscode/lsp/rascal/RascalTextDocumentService.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java index 4d36bc566..3210301bb 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java @@ -158,6 +158,7 @@ public void initializeServerCapabilities(ServerCapabilities result) { result.setFoldingRangeProvider(true); result.setRenameProvider(true); } + @Override public void pair(BaseWorkspaceService workspaceService) { this.workspaceService = workspaceService; @@ -176,14 +177,14 @@ public void connect(LanguageClient client) { @Override public void didOpen(DidOpenTextDocumentParams params) { - logger.debug("Open file: {}", params.getTextDocument()); + logger.debug("Open: {}", params.getTextDocument()); TextDocumentState file = open(params.getTextDocument()); handleParsingErrors(file); } @Override public void didChange(DidChangeTextDocumentParams params) { - logger.trace("Change contents: {}", params.getTextDocument()); + logger.trace("Change: {}", params.getTextDocument()); updateContents(params.getTextDocument(), last(params.getContentChanges()).getText()); } @@ -244,10 +245,9 @@ private void handleParsingErrors(TextDocumentState file) { handleParsingErrors(file,file.getCurrentTreeAsync()); } - @Override public CompletableFuture, List>> definition(DefinitionParams params) { - logger.debug("Definition: {} at {}", params.getTextDocument(), params.getPosition()); + logger.debug("textDocument/definition: {} at {}", params.getTextDocument(), params.getPosition()); if (facts != null) { return facts.getSummary(Locations.toLoc(params.getTextDocument())) @@ -263,7 +263,7 @@ public CompletableFuture, List>> documentSymbol(DocumentSymbolParams params) { - logger.debug("Outline/documentSymbol: {}", params.getTextDocument()); + logger.debug("textDocument/documentSymbol: {}", params.getTextDocument()); TextDocumentState file = getFile(params.getTextDocument()); return file.getCurrentTreeAsync() .thenApply(Versioned::get) @@ -429,6 +429,4 @@ public CompletableFuture executeCommand(String extension, String command logger.warn("ignoring execute command in Rascal LSP: {}, {}", extension, command); return CompletableFuture.completedFuture(null); } - - } From 0a54319c905ee8df187b60741d39b9db75208477 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Mon, 21 Oct 2024 16:34:33 +0200 Subject: [PATCH 46/57] Rename methods in `ParametricTextDocumentService` to be consistent with LSP --- .../lsp/parametric/ParametricTextDocumentService.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java index 5a5140412..2014eb1f7 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java @@ -370,7 +370,6 @@ private InlayHint rowToInlayHint(IValue v) { var toolTip = (IString)t.asWithKeywordParameters().getParameter("toolTip"); var atEnd = (IBool)t.asWithKeywordParameters().getParameter("atEnd"); - // translate to lsp var result = new InlayHint(Locations.toPosition(loc, columns, atEnd.getValue()), Either.forLeft(label.trim())); result.setKind(kind.getName().equals("type") ? InlayHintKind.Type : InlayHintKind.Parameter); @@ -678,7 +677,7 @@ public CompletableFuture, List> references(ReferenceParams params) { - logger.debug("Implementation: {} at {}", params.getTextDocument(), params.getPosition()); + logger.debug("References: {} at {}", params.getTextDocument(), params.getPosition()); return recoverExceptions( lookup(ParametricSummary::references, params.getTextDocument(), params.getPosition()) .thenApply(l -> l) // hack to help compiler see type @@ -696,7 +695,7 @@ public CompletableFuture hover(HoverParams params) { @Override public CompletableFuture> foldingRange(FoldingRangeRequestParams params) { - logger.debug("textDocument/foldingRange: {}", params.getTextDocument()); + logger.debug("Folding range: {}", params.getTextDocument()); TextDocumentState file = getFile(params.getTextDocument()); return recoverExceptions(file.getCurrentTreeAsync().thenApply(Versioned::get).thenApplyAsync(FoldingRanges::getFoldingRanges) .whenComplete((r, e) -> @@ -785,5 +784,4 @@ public CompletableFuture executeCommand(String languageName, String comm return CompletableFuture.completedFuture(null); } } - } From 8951698d2d4d4f29b62440da24d30c743c8cb4dd Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Mon, 21 Oct 2024 16:46:02 +0200 Subject: [PATCH 47/57] Rename methods in `Outline` to be consistent with LSP --- .../parametric/ParametricTextDocumentService.java | 2 +- .../lsp/rascal/RascalTextDocumentService.java | 2 +- .../org/rascalmpl/vscode/lsp/util/Outline.java | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java index 2014eb1f7..e2309f5ed 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java @@ -578,7 +578,7 @@ public CompletableFuture semanticTokensRange(SemanticTokensRange .thenApply(Versioned::get) .thenApply(contrib::runDocumentSymbolService) .thenCompose(InterruptibleFuture::get) - .thenApply(c -> Outline.buildOutline(c, columns.get(file.getLocation()))) + .thenApply(documentSymbols -> Outline.toLSP(documentSymbols, columns.get(file.getLocation()))) , Collections::emptyList); } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java index 3210301bb..e66a5523a 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java @@ -269,7 +269,7 @@ public CompletableFuture, List (t == null ? (file.getMostRecentTree().get()) : t)) .thenCompose(tr -> rascalServices.getDocumentSymbols(tr).get()) - .thenApply(c -> Outline.buildOutline(c, columns.get(file.getLocation()))) + .thenApply(documentSymbols -> Outline.toLSP(documentSymbols, columns.get(file.getLocation()))) ; } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/Outline.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/Outline.java index 21aeff439..56b12bb31 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/Outline.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/Outline.java @@ -53,29 +53,29 @@ private static String capitalize(String kindName) { /** * Converts a list of Rascal DocumentSymbols (@see util::IDE) to LSP DocumentSymbols * @param symbols list of Rascal DocumentSymbols - * @param om line/column offset map + * @param om line/column offset map * @return list of LSP DocumentSymbols */ - public static List> buildOutline(IList symbols, LineColumnOffsetMap om) { + public static List> toLSP(IList symbols, LineColumnOffsetMap om) { return symbols.stream() - .map(s -> buildParametricOutline((IConstructor) s, om)) + .map(s -> toLSP((IConstructor) s, om)) .map(Either::forRight) .collect(Collectors.toList()); } /** - * Converts a constructor tree of Rascal type DocumentSymbol from util::IDE to an LSP DocumentSymbol + * Converts a constructor tree of Rascal type DocumentSymbol (@see util::IDE) to an LSP DocumentSymbol * @param symbol IConstructor of Rascal type DocumentSymbol * @param om line/column offset map - * @return a DocumentSymbol + * @return an LSP DocumentSymbol */ - public static DocumentSymbol buildParametricOutline(IConstructor symbol, final LineColumnOffsetMap om) { + public static DocumentSymbol toLSP(IConstructor symbol, final LineColumnOffsetMap om) { IWithKeywordParameters kwp = symbol.asWithKeywordParameters(); List children = kwp.hasParameter("children") ? ((IList) kwp.getParameter("children")) .stream() - .map(c -> buildParametricOutline((IConstructor) c, om)) + .map(c -> toLSP((IConstructor) c, om)) .collect(Collectors.toList()) : Collections.emptyList(); From 33fa928648b752177ea5e5dfbe1ad4b010b1ee9c Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Mon, 21 Oct 2024 17:02:08 +0200 Subject: [PATCH 48/57] Rename method `hasCodeLensDetector` to be consistent with LSP (previously overlooked) --- .../vscode/lsp/parametric/ILanguageContributions.java | 2 +- .../lsp/parametric/InterpretedLanguageContributions.java | 2 +- .../lsp/parametric/LanguageContributionsMultiplexer.java | 6 +++--- .../vscode/lsp/parametric/ParserOnlyContribution.java | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java index f65efbe9a..e9d1c0a6e 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java @@ -64,7 +64,7 @@ public interface ILanguageContributions { public CompletableFuture hasAnalysisService(); public CompletableFuture hasBuildService(); public CompletableFuture hasDocumentSymbolService(); - public CompletableFuture hasCodeLensDetector(); + public CompletableFuture hasCodeLensService(); public CompletableFuture hasInlayHintService(); public CompletableFuture hasExecutionService(); public CompletableFuture hasHoverService(); diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java index 7c6c8ec72..4df75d227 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java @@ -364,7 +364,7 @@ public CompletableFuture hasInlayHintService() { } @Override - public CompletableFuture hasCodeLensDetector() { + public CompletableFuture hasCodeLensService() { return hasCodeLensService; } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java index d865de2cb..b9ffd497c 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java @@ -139,7 +139,7 @@ private synchronized void calculateRouting() { getAnalysisService = findFirstOrDefault(ILanguageContributions::hasAnalysisService); getBuildService = findFirstOrDefault(ILanguageContributions::hasBuildService); getDocumentSymbolService = findFirstOrDefault(ILanguageContributions::hasDocumentSymbolService); - getCodeLensService = findFirstOrDefault(ILanguageContributions::hasCodeLensDetector); + getCodeLensService = findFirstOrDefault(ILanguageContributions::hasCodeLensService); getInlayHintService = findFirstOrDefault(ILanguageContributions::hasInlayHintService); getExecutionService = findFirstOrDefault(ILanguageContributions::hasExecutionService); getHoverService = findFirstOrDefault(ILanguageContributions::hasHoverService); @@ -152,7 +152,7 @@ private synchronized void calculateRouting() { hasAnalysisService = anyTrue(ILanguageContributions::hasAnalysisService); hasBuildService = anyTrue(ILanguageContributions::hasBuildService); hasDocumentSymbolService = anyTrue(ILanguageContributions::hasDocumentSymbolService); - hasCodeLensService = anyTrue(ILanguageContributions::hasCodeLensDetector); + hasCodeLensService = anyTrue(ILanguageContributions::hasCodeLensService); hasInlayHintService = anyTrue(ILanguageContributions::hasInlayHintService); hasExecutionService = anyTrue(ILanguageContributions::hasExecutionService); hasHoverService = anyTrue(ILanguageContributions::hasHoverService); @@ -331,7 +331,7 @@ public CompletableFuture hasBuildService() { } @Override - public CompletableFuture hasCodeLensDetector() { + public CompletableFuture hasCodeLensService() { return hasCodeLensService; } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java index 555317e67..80e597b3d 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java @@ -214,7 +214,7 @@ public CompletableFuture hasCodeActionService() { } @Override - public CompletableFuture hasCodeLensDetector() { + public CompletableFuture hasCodeLensService() { return CompletableFuture.completedFuture(false); } From eae06cf098e620deceeef4f90e3be10db2095257 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Mon, 21 Oct 2024 17:07:31 +0200 Subject: [PATCH 49/57] Improve code layout --- .../LanguageContributionsMultiplexer.java | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java index b9ffd497c..49500fdd0 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java @@ -65,7 +65,6 @@ private static final CompletableFuture failedInitialization() { private volatile CompletableFuture getImplementationService = failedInitialization(); private volatile CompletableFuture getCodeActionService = failedInitialization(); - private volatile CompletableFuture hasAnalysisService = failedInitialization(); private volatile CompletableFuture hasBuildService = failedInitialization(); private volatile CompletableFuture hasDocumentSymbolService = failedInitialization(); @@ -136,32 +135,32 @@ private synchronized void calculateRouting() { // we calculate the "route" once, and then just chain onto the completed // future parsingService = firstOrFail(); - getAnalysisService = findFirstOrDefault(ILanguageContributions::hasAnalysisService); - getBuildService = findFirstOrDefault(ILanguageContributions::hasBuildService); + + getAnalysisService = findFirstOrDefault(ILanguageContributions::hasAnalysisService); + getBuildService = findFirstOrDefault(ILanguageContributions::hasBuildService); getDocumentSymbolService = findFirstOrDefault(ILanguageContributions::hasDocumentSymbolService); - getCodeLensService = findFirstOrDefault(ILanguageContributions::hasCodeLensService); - getInlayHintService = findFirstOrDefault(ILanguageContributions::hasInlayHintService); - getExecutionService = findFirstOrDefault(ILanguageContributions::hasExecutionService); - getHoverService = findFirstOrDefault(ILanguageContributions::hasHoverService); - getDefinitionService = findFirstOrDefault(ILanguageContributions::hasDefinitionService); - getReferencesService = findFirstOrDefault(ILanguageContributions::hasReferencesService); + getCodeLensService = findFirstOrDefault(ILanguageContributions::hasCodeLensService); + getInlayHintService = findFirstOrDefault(ILanguageContributions::hasInlayHintService); + getExecutionService = findFirstOrDefault(ILanguageContributions::hasExecutionService); + getHoverService = findFirstOrDefault(ILanguageContributions::hasHoverService); + getDefinitionService = findFirstOrDefault(ILanguageContributions::hasDefinitionService); + getReferencesService = findFirstOrDefault(ILanguageContributions::hasReferencesService); getImplementationService = findFirstOrDefault(ILanguageContributions::hasImplementationService); - getCodeActionService = findFirstOrDefault(ILanguageContributions::hasCodeActionService); - + getCodeActionService = findFirstOrDefault(ILanguageContributions::hasCodeActionService); - hasAnalysisService = anyTrue(ILanguageContributions::hasAnalysisService); - hasBuildService = anyTrue(ILanguageContributions::hasBuildService); + hasAnalysisService = anyTrue(ILanguageContributions::hasAnalysisService); + hasBuildService = anyTrue(ILanguageContributions::hasBuildService); hasDocumentSymbolService = anyTrue(ILanguageContributions::hasDocumentSymbolService); - hasCodeLensService = anyTrue(ILanguageContributions::hasCodeLensService); - hasInlayHintService = anyTrue(ILanguageContributions::hasInlayHintService); - hasExecutionService = anyTrue(ILanguageContributions::hasExecutionService); - hasHoverService = anyTrue(ILanguageContributions::hasHoverService); - hasDefinitionService = anyTrue(ILanguageContributions::hasDefinitionService); - hasReferencesService = anyTrue(ILanguageContributions::hasReferencesService); + hasCodeLensService = anyTrue(ILanguageContributions::hasCodeLensService); + hasInlayHintService = anyTrue(ILanguageContributions::hasInlayHintService); + hasExecutionService = anyTrue(ILanguageContributions::hasExecutionService); + hasHoverService = anyTrue(ILanguageContributions::hasHoverService); + hasDefinitionService = anyTrue(ILanguageContributions::hasDefinitionService); + hasReferencesService = anyTrue(ILanguageContributions::hasReferencesService); hasImplementationService = anyTrue(ILanguageContributions::hasImplementationService); analyzerSummaryConfig = anyTrue(ILanguageContributions::getAnalyzerSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); - builderSummaryConfig = anyTrue(ILanguageContributions::getBuilderSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); + builderSummaryConfig = anyTrue(ILanguageContributions::getBuilderSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); ondemandSummaryConfig = anyTrue(ILanguageContributions::getOndemandSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); } From c1b9dc502ca3ac7ccb41e0a8bd5d7c8f51c47667 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Tue, 22 Oct 2024 08:20:43 +0200 Subject: [PATCH 50/57] Rename class `Outline` to `DocumentSymbols` --- .../lsp/parametric/LanguageContributionsMultiplexer.java | 1 - .../vscode/lsp/parametric/ParametricTextDocumentService.java | 4 ++-- .../vscode/lsp/rascal/RascalTextDocumentService.java | 4 ++-- .../vscode/lsp/util/{Outline.java => DocumentSymbols.java} | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) rename rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/{Outline.java => DocumentSymbols.java} (98%) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java index 49500fdd0..10194d480 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java @@ -224,7 +224,6 @@ public CompletableFuture runParsingService(ISourceLocation loc, String in return p.runParsingService(loc, input); } - private InterruptibleFuture flatten(CompletableFuture target, Function> call) { return InterruptibleFuture.flatten(target.thenApply(call), ownExecuter); } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java index e2309f5ed..b8fc8b644 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java @@ -114,7 +114,7 @@ import org.rascalmpl.vscode.lsp.util.Diagnostics; import org.rascalmpl.vscode.lsp.util.DocumentChanges; import org.rascalmpl.vscode.lsp.util.FoldingRanges; -import org.rascalmpl.vscode.lsp.util.Outline; +import org.rascalmpl.vscode.lsp.util.DocumentSymbols; import org.rascalmpl.vscode.lsp.util.SemanticTokenizer; import org.rascalmpl.vscode.lsp.util.Versioned; import org.rascalmpl.vscode.lsp.util.concurrent.InterruptibleFuture; @@ -578,7 +578,7 @@ public CompletableFuture semanticTokensRange(SemanticTokensRange .thenApply(Versioned::get) .thenApply(contrib::runDocumentSymbolService) .thenCompose(InterruptibleFuture::get) - .thenApply(documentSymbols -> Outline.toLSP(documentSymbols, columns.get(file.getLocation()))) + .thenApply(documentSymbols -> DocumentSymbols.toLSP(documentSymbols, columns.get(file.getLocation()))) , Collections::emptyList); } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java index e66a5523a..6de9d8b44 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java @@ -98,7 +98,7 @@ import org.rascalmpl.vscode.lsp.util.Diagnostics; import org.rascalmpl.vscode.lsp.util.DocumentChanges; import org.rascalmpl.vscode.lsp.util.FoldingRanges; -import org.rascalmpl.vscode.lsp.util.Outline; +import org.rascalmpl.vscode.lsp.util.DocumentSymbols; import org.rascalmpl.vscode.lsp.util.SemanticTokenizer; import org.rascalmpl.vscode.lsp.util.Versioned; import org.rascalmpl.vscode.lsp.util.locations.ColumnMaps; @@ -269,7 +269,7 @@ public CompletableFuture, List (t == null ? (file.getMostRecentTree().get()) : t)) .thenCompose(tr -> rascalServices.getDocumentSymbols(tr).get()) - .thenApply(documentSymbols -> Outline.toLSP(documentSymbols, columns.get(file.getLocation()))) + .thenApply(documentSymbols -> DocumentSymbols.toLSP(documentSymbols, columns.get(file.getLocation()))) ; } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/Outline.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/DocumentSymbols.java similarity index 98% rename from rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/Outline.java rename to rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/DocumentSymbols.java index 56b12bb31..93ad73f9b 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/Outline.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/DocumentSymbols.java @@ -42,9 +42,9 @@ import io.usethesource.vallang.IString; import io.usethesource.vallang.IWithKeywordParameters; -public class Outline { +public class DocumentSymbols { // hide constructor for static class - private Outline() {} + private DocumentSymbols() {} private static String capitalize(String kindName) { return kindName.substring(0,1).toUpperCase() + kindName.substring(1); From a583630dc9b05a3dd8581a609cda772c453c144a Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Wed, 23 Oct 2024 11:51:02 +0200 Subject: [PATCH 51/57] Made names shorter (without `run..Service` pre/suffix) --- .../parametric/ILanguageContributions.java | 46 ++--- .../InterpretedLanguageContributions.java | 186 ++++++++--------- .../LanguageContributionsMultiplexer.java | 194 +++++++++--------- .../ParametricTextDocumentService.java | 12 +- .../parametric/ParserOnlyContribution.java | 46 ++--- .../parametric/model/ParametricSummary.java | 8 +- 6 files changed, 246 insertions(+), 246 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java index e9d1c0a6e..d73e0fc15 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java @@ -46,32 +46,32 @@ public interface ILanguageContributions { public String getName(); - public CompletableFuture runParsingService(ISourceLocation loc, String input); - public InterruptibleFuture runAnalysisService(ISourceLocation loc, ITree input); - public InterruptibleFuture runBuildService(ISourceLocation loc, ITree input); - public InterruptibleFuture runDocumentSymbolService(ITree input); - public InterruptibleFuture runCodeLensService(ITree input); - public InterruptibleFuture runInlayHintService(@Nullable ITree input); - public InterruptibleFuture<@Nullable IValue> runExecutionService(String command); - public InterruptibleFuture runHoverService(IList focus); - public InterruptibleFuture runDefinitionService(IList focus); - public InterruptibleFuture runReferencesService(IList focus); - public InterruptibleFuture runImplementationService(IList focus); - public InterruptibleFuture runCodeActionService(IList focus); + public CompletableFuture parsing(ISourceLocation loc, String input); + public InterruptibleFuture analysis(ISourceLocation loc, ITree input); + public InterruptibleFuture build(ISourceLocation loc, ITree input); + public InterruptibleFuture documentSymbol(ITree input); + public InterruptibleFuture codeLens(ITree input); + public InterruptibleFuture inlayHint(@Nullable ITree input); + public InterruptibleFuture<@Nullable IValue> execution(String command); + public InterruptibleFuture hover(IList focus); + public InterruptibleFuture definition(IList focus); + public InterruptibleFuture references(IList focus); + public InterruptibleFuture implementation(IList focus); + public InterruptibleFuture codeAction(IList focus); public CompletableFuture parseCodeActions(String command); - public CompletableFuture hasAnalysisService(); - public CompletableFuture hasBuildService(); - public CompletableFuture hasDocumentSymbolService(); - public CompletableFuture hasCodeLensService(); - public CompletableFuture hasInlayHintService(); - public CompletableFuture hasExecutionService(); - public CompletableFuture hasHoverService(); - public CompletableFuture hasDefinitionService(); - public CompletableFuture hasReferencesService(); - public CompletableFuture hasImplementationService(); - public CompletableFuture hasCodeActionService(); + public CompletableFuture hasAnalysis(); + public CompletableFuture hasBuild(); + public CompletableFuture hasDocumentSymbol(); + public CompletableFuture hasCodeLens(); + public CompletableFuture hasInlayHint(); + public CompletableFuture hasExecution(); + public CompletableFuture hasHover(); + public CompletableFuture hasDefinition(); + public CompletableFuture hasReferences(); + public CompletableFuture hasImplementation(); + public CompletableFuture hasCodeAction(); public CompletableFuture getAnalyzerSummaryConfig(); public CompletableFuture getBuilderSummaryConfig(); diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java index 4df75d227..fa78ef1ee 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java @@ -75,30 +75,30 @@ public class InterpretedLanguageContributions implements ILanguageContributions private final CompletableFuture eval; private final CompletableFuture store; - private final CompletableFuture parsingService; - private final CompletableFuture<@Nullable IFunction> analysisService; - private final CompletableFuture<@Nullable IFunction> buildService; - private final CompletableFuture<@Nullable IFunction> documentSymbolService; - private final CompletableFuture<@Nullable IFunction> codeLensService; - private final CompletableFuture<@Nullable IFunction> inlayHintService; - private final CompletableFuture<@Nullable IFunction> executionService; - private final CompletableFuture<@Nullable IFunction> hoverService; - private final CompletableFuture<@Nullable IFunction> definitionService; - private final CompletableFuture<@Nullable IFunction> referencesService; - private final CompletableFuture<@Nullable IFunction> implementationService; - private final CompletableFuture<@Nullable IFunction> codeActionService; - - private final CompletableFuture hasAnalysisService; - private final CompletableFuture hasBuildService; - private final CompletableFuture hasDocumentSymbolService; - private final CompletableFuture hasCodeLensService; - private final CompletableFuture hasInlayHintService; - private final CompletableFuture hasExecutionService; - private final CompletableFuture hasHoverService; - private final CompletableFuture hasDefinitionService; - private final CompletableFuture hasReferencesService; - private final CompletableFuture hasImplementationService; - private final CompletableFuture hasCodeActionService; + private final CompletableFuture parsing; + private final CompletableFuture<@Nullable IFunction> analysis; + private final CompletableFuture<@Nullable IFunction> build; + private final CompletableFuture<@Nullable IFunction> documentSymbol; + private final CompletableFuture<@Nullable IFunction> codeLens; + private final CompletableFuture<@Nullable IFunction> inlayHint; + private final CompletableFuture<@Nullable IFunction> execution; + private final CompletableFuture<@Nullable IFunction> hover; + private final CompletableFuture<@Nullable IFunction> definition; + private final CompletableFuture<@Nullable IFunction> references; + private final CompletableFuture<@Nullable IFunction> implementation; + private final CompletableFuture<@Nullable IFunction> codeAction; + + private final CompletableFuture hasAnalysis; + private final CompletableFuture hasBuild; + private final CompletableFuture hasDocumentSymbol; + private final CompletableFuture hasCodeLens; + private final CompletableFuture hasInlayHint; + private final CompletableFuture hasExecution; + private final CompletableFuture hasHover; + private final CompletableFuture hasDefinition; + private final CompletableFuture hasReferences; + private final CompletableFuture hasImplementation; + private final CompletableFuture hasCodeAction; private final CompletableFuture analyzerSummaryConfig; private final CompletableFuture builderSummaryConfig; @@ -125,31 +125,31 @@ public InterpretedLanguageContributions(LanguageParameter lang, IBaseTextDocumen this.store = eval.thenApply(e -> ((ModuleEnvironment)e.getModule(mainModule)).getStore()); - this.parsingService = getFunctionFor(contributions, LanguageContributions.PARSING); - this.analysisService = getFunctionFor(contributions, LanguageContributions.ANALYSIS); - this.buildService = getFunctionFor(contributions, LanguageContributions.BUILD); - this.documentSymbolService = getFunctionFor(contributions, LanguageContributions.DOCUMENT_SYMBOL); - this.codeLensService = getFunctionFor(contributions, LanguageContributions.CODE_LENS); - this.inlayHintService = getFunctionFor(contributions, LanguageContributions.INLAY_HINT); - this.executionService = getFunctionFor(contributions, LanguageContributions.EXECUTION); - this.hoverService = getFunctionFor(contributions, LanguageContributions.HOVER); - this.definitionService = getFunctionFor(contributions, LanguageContributions.DEFINITION); - this.referencesService = getFunctionFor(contributions, LanguageContributions.REFERENCES); - this.implementationService = getFunctionFor(contributions, LanguageContributions.IMPLEMENTATION); - this.codeActionService = getFunctionFor(contributions, LanguageContributions.CODE_ACTION); + this.parsing = getFunctionFor(contributions, LanguageContributions.PARSING); + this.analysis = getFunctionFor(contributions, LanguageContributions.ANALYSIS); + this.build = getFunctionFor(contributions, LanguageContributions.BUILD); + this.documentSymbol = getFunctionFor(contributions, LanguageContributions.DOCUMENT_SYMBOL); + this.codeLens = getFunctionFor(contributions, LanguageContributions.CODE_LENS); + this.inlayHint = getFunctionFor(contributions, LanguageContributions.INLAY_HINT); + this.execution = getFunctionFor(contributions, LanguageContributions.EXECUTION); + this.hover = getFunctionFor(contributions, LanguageContributions.HOVER); + this.definition = getFunctionFor(contributions, LanguageContributions.DEFINITION); + this.references = getFunctionFor(contributions, LanguageContributions.REFERENCES); + this.implementation = getFunctionFor(contributions, LanguageContributions.IMPLEMENTATION); + this.codeAction = getFunctionFor(contributions, LanguageContributions.CODE_ACTION); // assign boolean properties once instead of wasting futures all the time - this.hasAnalysisService = nonNull(this.analysisService); - this.hasBuildService = nonNull(this.buildService); - this.hasDocumentSymbolService = nonNull(this.documentSymbolService); - this.hasCodeLensService = nonNull(this.codeLensService); - this.hasInlayHintService = nonNull(this.inlayHintService); - this.hasExecutionService = nonNull(this.executionService); - this.hasHoverService = nonNull(this.hoverService); - this.hasDefinitionService = nonNull(this.definitionService); - this.hasReferencesService = nonNull(this.referencesService); - this.hasImplementationService = nonNull(this.implementationService); - this.hasCodeActionService = nonNull(this.codeActionService); + this.hasAnalysis = nonNull(this.analysis); + this.hasBuild = nonNull(this.build); + this.hasDocumentSymbol = nonNull(this.documentSymbol); + this.hasCodeLens = nonNull(this.codeLens); + this.hasInlayHint = nonNull(this.inlayHint); + this.hasExecution = nonNull(this.execution); + this.hasHover = nonNull(this.hover); + this.hasDefinition = nonNull(this.definition); + this.hasReferences = nonNull(this.references); + this.hasImplementation = nonNull(this.implementation); + this.hasCodeAction = nonNull(this.codeAction); this.analyzerSummaryConfig = scheduledSummaryConfig(contributions, LanguageContributions.ANALYSIS); this.builderSummaryConfig = scheduledSummaryConfig(contributions, LanguageContributions.BUILD); @@ -260,69 +260,69 @@ public String getName() { } @Override - public CompletableFuture runParsingService(ISourceLocation loc, String input) { + public CompletableFuture parsing(ISourceLocation loc, String input) { debug(LanguageContributions.PARSING, loc, input); - return parsingService.thenApplyAsync(p -> p.call(VF.string(input), loc), exec); + return parsing.thenApplyAsync(p -> p.call(VF.string(input), loc), exec); } @Override - public InterruptibleFuture runDocumentSymbolService(ITree input) { + public InterruptibleFuture documentSymbol(ITree input) { debug(LanguageContributions.DOCUMENT_SYMBOL, TreeAdapter.getLocation(input)); - return execFunction(LanguageContributions.DOCUMENT_SYMBOL, documentSymbolService, VF.list(), input); + return execFunction(LanguageContributions.DOCUMENT_SYMBOL, documentSymbol, VF.list(), input); } @Override - public InterruptibleFuture runAnalysisService(ISourceLocation src, ITree input) { + public InterruptibleFuture analysis(ISourceLocation src, ITree input) { debug(LanguageContributions.ANALYSIS, src); - return execFunction(LanguageContributions.ANALYSIS, analysisService, EmptySummary.newInstance(src), src, input); + return execFunction(LanguageContributions.ANALYSIS, analysis, EmptySummary.newInstance(src), src, input); } @Override - public InterruptibleFuture runBuildService(ISourceLocation src, ITree input) { + public InterruptibleFuture build(ISourceLocation src, ITree input) { debug(LanguageContributions.BUILD, src); - return execFunction(LanguageContributions.BUILD, buildService, EmptySummary.newInstance(src), src, input); + return execFunction(LanguageContributions.BUILD, build, EmptySummary.newInstance(src), src, input); } @Override - public InterruptibleFuture runCodeLensService(ITree input) { + public InterruptibleFuture codeLens(ITree input) { debug(LanguageContributions.CODE_LENS, TreeAdapter.getLocation(input)); - return execFunction(LanguageContributions.CODE_LENS, codeLensService, VF.list(), input); + return execFunction(LanguageContributions.CODE_LENS, codeLens, VF.list(), input); } @Override - public InterruptibleFuture runInlayHintService(@Nullable ITree input) { + public InterruptibleFuture inlayHint(@Nullable ITree input) { debug(LanguageContributions.INLAY_HINT, input != null ? TreeAdapter.getLocation(input) : null); - return execFunction(LanguageContributions.INLAY_HINT, inlayHintService, VF.list(), input); + return execFunction(LanguageContributions.INLAY_HINT, inlayHint, VF.list(), input); } @Override - public InterruptibleFuture runHoverService(IList focus) { + public InterruptibleFuture hover(IList focus) { debug(LanguageContributions.HOVER, focus.length()); - return execFunction(LanguageContributions.HOVER, hoverService, VF.set(), focus); + return execFunction(LanguageContributions.HOVER, hover, VF.set(), focus); } @Override - public InterruptibleFuture runDefinitionService(IList focus) { + public InterruptibleFuture definition(IList focus) { debug(LanguageContributions.DEFINITION, focus.length()); - return execFunction(LanguageContributions.DEFINITION, definitionService, VF.set(), focus); + return execFunction(LanguageContributions.DEFINITION, definition, VF.set(), focus); } @Override - public InterruptibleFuture runImplementationService(IList focus) { + public InterruptibleFuture implementation(IList focus) { debug(LanguageContributions.IMPLEMENTATION, focus.length()); - return execFunction(LanguageContributions.IMPLEMENTATION, implementationService, VF.set(), focus); + return execFunction(LanguageContributions.IMPLEMENTATION, implementation, VF.set(), focus); } @Override - public InterruptibleFuture runReferencesService(IList focus) { + public InterruptibleFuture references(IList focus) { debug(LanguageContributions.REFERENCES, focus.length()); - return execFunction(LanguageContributions.REFERENCES, referencesService, VF.set(), focus); + return execFunction(LanguageContributions.REFERENCES, references, VF.set(), focus); } @Override - public InterruptibleFuture runCodeActionService(IList focus) { + public InterruptibleFuture codeAction(IList focus) { debug(LanguageContributions.CODE_ACTION, focus.length()); - return execFunction(LanguageContributions.CODE_ACTION, codeActionService, VF.list(), focus); + return execFunction(LanguageContributions.CODE_ACTION, codeAction, VF.list(), focus); } private void debug(String name, Object param) { @@ -334,58 +334,58 @@ private void debug(String name, Object param1, Object param2) { } @Override - public CompletableFuture hasDefinitionService() { - return hasDefinitionService; + public CompletableFuture hasDefinition() { + return hasDefinition; } @Override - public CompletableFuture hasReferencesService() { - return hasReferencesService; + public CompletableFuture hasReferences() { + return hasReferences; } @Override - public CompletableFuture hasImplementationService() { - return hasImplementationService; + public CompletableFuture hasImplementation() { + return hasImplementation; } @Override - public CompletableFuture hasHoverService() { - return hasHoverService; + public CompletableFuture hasHover() { + return hasHover; } @Override - public CompletableFuture hasExecutionService() { - return hasExecutionService; + public CompletableFuture hasExecution() { + return hasExecution; } @Override - public CompletableFuture hasInlayHintService() { - return hasInlayHintService; + public CompletableFuture hasInlayHint() { + return hasInlayHint; } @Override - public CompletableFuture hasCodeLensService() { - return hasCodeLensService; + public CompletableFuture hasCodeLens() { + return hasCodeLens; } @Override - public CompletableFuture hasDocumentSymbolService() { - return hasDocumentSymbolService; + public CompletableFuture hasDocumentSymbol() { + return hasDocumentSymbol; } @Override - public CompletableFuture hasCodeActionService() { - return hasCodeActionService; + public CompletableFuture hasCodeAction() { + return hasCodeAction; } @Override - public CompletableFuture hasAnalysisService() { - return hasAnalysisService; + public CompletableFuture hasAnalysis() { + return hasAnalysis; } @Override - public CompletableFuture hasBuildService() { - return hasBuildService; + public CompletableFuture hasBuild() { + return hasBuild; } @Override @@ -404,12 +404,12 @@ public CompletableFuture getOndemandSummaryConfig() { } @Override - public InterruptibleFuture<@Nullable IValue> runExecutionService(String command) { + public InterruptibleFuture<@Nullable IValue> execution(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( - executionService, + execution, (cons, func) -> { if (func == null) { diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java index 10194d480..a43fb300a 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java @@ -51,31 +51,31 @@ private static final CompletableFuture failedInitialization() { return CompletableFuture.failedFuture(new RuntimeException("No contributions registered")); } - private volatile @MonotonicNonNull ILanguageContributions parsingService = null; - - private volatile CompletableFuture getAnalysisService = failedInitialization(); - private volatile CompletableFuture getBuildService = failedInitialization(); - private volatile CompletableFuture getDocumentSymbolService = failedInitialization(); - private volatile CompletableFuture getCodeLensService = failedInitialization(); - private volatile CompletableFuture getInlayHintService = failedInitialization(); - private volatile CompletableFuture getExecutionService = failedInitialization(); - private volatile CompletableFuture getHoverService = failedInitialization(); - private volatile CompletableFuture getDefinitionService = failedInitialization(); - private volatile CompletableFuture getReferencesService = failedInitialization(); - private volatile CompletableFuture getImplementationService = failedInitialization(); - private volatile CompletableFuture getCodeActionService = failedInitialization(); - - private volatile CompletableFuture hasAnalysisService = failedInitialization(); - private volatile CompletableFuture hasBuildService = failedInitialization(); - private volatile CompletableFuture hasDocumentSymbolService = failedInitialization(); - private volatile CompletableFuture hasCodeLensService = failedInitialization(); - private volatile CompletableFuture hasInlayHintService = failedInitialization(); - private volatile CompletableFuture hasExecutionService = failedInitialization(); - private volatile CompletableFuture hasHoverService = failedInitialization(); - private volatile CompletableFuture hasDefinitionService = failedInitialization(); - private volatile CompletableFuture hasReferencesService = failedInitialization(); - private volatile CompletableFuture hasImplementationService = failedInitialization(); - private volatile CompletableFuture hasCodeActionService = failedInitialization(); + private volatile @MonotonicNonNull ILanguageContributions parsing = null; + + private volatile CompletableFuture analysis = failedInitialization(); + private volatile CompletableFuture build = failedInitialization(); + private volatile CompletableFuture documentSymbol = failedInitialization(); + private volatile CompletableFuture codeLens = failedInitialization(); + private volatile CompletableFuture inlayHint = failedInitialization(); + private volatile CompletableFuture execution = failedInitialization(); + private volatile CompletableFuture hover = failedInitialization(); + private volatile CompletableFuture definition = failedInitialization(); + private volatile CompletableFuture references = failedInitialization(); + private volatile CompletableFuture implementation = failedInitialization(); + private volatile CompletableFuture codeAction = failedInitialization(); + + private volatile CompletableFuture hasAnalysis = failedInitialization(); + private volatile CompletableFuture hasBuild = failedInitialization(); + private volatile CompletableFuture hasDocumentSymbol = failedInitialization(); + private volatile CompletableFuture hasCodeLens = failedInitialization(); + private volatile CompletableFuture hasInlayHint = failedInitialization(); + private volatile CompletableFuture hasExecution = failedInitialization(); + private volatile CompletableFuture hasHover = failedInitialization(); + private volatile CompletableFuture hasDefinition = failedInitialization(); + private volatile CompletableFuture hasReferences = failedInitialization(); + private volatile CompletableFuture hasImplementation = failedInitialization(); + private volatile CompletableFuture hasCodeAction = failedInitialization(); private volatile CompletableFuture analyzerSummaryConfig; private volatile CompletableFuture builderSummaryConfig; @@ -134,30 +134,30 @@ private synchronized void calculateRouting() { // this is to avoid doing this lookup every time we get a request // we calculate the "route" once, and then just chain onto the completed // future - parsingService = firstOrFail(); - - getAnalysisService = findFirstOrDefault(ILanguageContributions::hasAnalysisService); - getBuildService = findFirstOrDefault(ILanguageContributions::hasBuildService); - getDocumentSymbolService = findFirstOrDefault(ILanguageContributions::hasDocumentSymbolService); - getCodeLensService = findFirstOrDefault(ILanguageContributions::hasCodeLensService); - getInlayHintService = findFirstOrDefault(ILanguageContributions::hasInlayHintService); - getExecutionService = findFirstOrDefault(ILanguageContributions::hasExecutionService); - getHoverService = findFirstOrDefault(ILanguageContributions::hasHoverService); - getDefinitionService = findFirstOrDefault(ILanguageContributions::hasDefinitionService); - getReferencesService = findFirstOrDefault(ILanguageContributions::hasReferencesService); - getImplementationService = findFirstOrDefault(ILanguageContributions::hasImplementationService); - getCodeActionService = findFirstOrDefault(ILanguageContributions::hasCodeActionService); - - hasAnalysisService = anyTrue(ILanguageContributions::hasAnalysisService); - hasBuildService = anyTrue(ILanguageContributions::hasBuildService); - hasDocumentSymbolService = anyTrue(ILanguageContributions::hasDocumentSymbolService); - hasCodeLensService = anyTrue(ILanguageContributions::hasCodeLensService); - hasInlayHintService = anyTrue(ILanguageContributions::hasInlayHintService); - hasExecutionService = anyTrue(ILanguageContributions::hasExecutionService); - hasHoverService = anyTrue(ILanguageContributions::hasHoverService); - hasDefinitionService = anyTrue(ILanguageContributions::hasDefinitionService); - hasReferencesService = anyTrue(ILanguageContributions::hasReferencesService); - hasImplementationService = anyTrue(ILanguageContributions::hasImplementationService); + parsing = firstOrFail(); + + analysis = findFirstOrDefault(ILanguageContributions::hasAnalysis); + build = findFirstOrDefault(ILanguageContributions::hasBuild); + documentSymbol = findFirstOrDefault(ILanguageContributions::hasDocumentSymbol); + codeLens = findFirstOrDefault(ILanguageContributions::hasCodeLens); + inlayHint = findFirstOrDefault(ILanguageContributions::hasInlayHint); + execution = findFirstOrDefault(ILanguageContributions::hasExecution); + hover = findFirstOrDefault(ILanguageContributions::hasHover); + definition = findFirstOrDefault(ILanguageContributions::hasDefinition); + references = findFirstOrDefault(ILanguageContributions::hasReferences); + implementation = findFirstOrDefault(ILanguageContributions::hasImplementation); + codeAction = findFirstOrDefault(ILanguageContributions::hasCodeAction); + + hasAnalysis = anyTrue(ILanguageContributions::hasAnalysis); + hasBuild = anyTrue(ILanguageContributions::hasBuild); + hasDocumentSymbol = anyTrue(ILanguageContributions::hasDocumentSymbol); + hasCodeLens = anyTrue(ILanguageContributions::hasCodeLens); + hasInlayHint = anyTrue(ILanguageContributions::hasInlayHint); + hasExecution = anyTrue(ILanguageContributions::hasExecution); + hasHover = anyTrue(ILanguageContributions::hasHover); + hasDefinition = anyTrue(ILanguageContributions::hasDefinition); + hasReferences = anyTrue(ILanguageContributions::hasReferences); + hasImplementation = anyTrue(ILanguageContributions::hasImplementation); analyzerSummaryConfig = anyTrue(ILanguageContributions::getAnalyzerSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); builderSummaryConfig = anyTrue(ILanguageContributions::getBuilderSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); @@ -216,12 +216,12 @@ public String getName() { } @Override - public CompletableFuture runParsingService(ISourceLocation loc, String input) { - var p = parsingService; + public CompletableFuture parsing(ISourceLocation loc, String input) { + var p = parsing; if (p == null) { return failedInitialization(); } - return p.runParsingService(loc, input); + return p.parsing(loc, input); } private InterruptibleFuture flatten(CompletableFuture target, Function> call) { @@ -229,118 +229,118 @@ private InterruptibleFuture flatten(CompletableFuture runDocumentSymbolService(ITree input) { - return flatten(getDocumentSymbolService, c -> c.runDocumentSymbolService(input)); + public InterruptibleFuture documentSymbol(ITree input) { + return flatten(documentSymbol, c -> c.documentSymbol(input)); } @Override - public InterruptibleFuture runAnalysisService(ISourceLocation loc, ITree input) { - return flatten(getAnalysisService, c -> c.runAnalysisService(loc, input)); + public InterruptibleFuture analysis(ISourceLocation loc, ITree input) { + return flatten(analysis, c -> c.analysis(loc, input)); } @Override - public InterruptibleFuture runBuildService(ISourceLocation loc, ITree input) { - return flatten(getBuildService, c -> c.runBuildService(loc, input)); + public InterruptibleFuture build(ISourceLocation loc, ITree input) { + return flatten(build, c -> c.build(loc, input)); } @Override - public InterruptibleFuture runCodeLensService(ITree input) { - return flatten(getCodeLensService, c -> c.runCodeLensService(input)); + public InterruptibleFuture codeLens(ITree input) { + return flatten(codeLens, c -> c.codeLens(input)); } @Override - public InterruptibleFuture<@Nullable IValue> runExecutionService(String command) { - return flatten(getExecutionService, c -> c.runExecutionService(command)); + public InterruptibleFuture<@Nullable IValue> execution(String command) { + return flatten(execution, c -> c.execution(command)); } @Override public CompletableFuture parseCodeActions(String command) { - return getExecutionService.thenApply(c -> c.parseCodeActions(command)).thenCompose(Function.identity()); + return execution.thenApply(c -> c.parseCodeActions(command)).thenCompose(Function.identity()); } @Override - public InterruptibleFuture runInlayHintService(@Nullable ITree input) { - return flatten(getInlayHintService, c -> c.runInlayHintService(input)); + public InterruptibleFuture inlayHint(@Nullable ITree input) { + return flatten(inlayHint, c -> c.inlayHint(input)); } @Override - public InterruptibleFuture runHoverService(IList focus) { - return flatten(getHoverService, c -> c.runHoverService(focus)); + public InterruptibleFuture hover(IList focus) { + return flatten(hover, c -> c.hover(focus)); } @Override - public InterruptibleFuture runDefinitionService(IList focus) { - return flatten(getDefinitionService, c -> c.runDefinitionService(focus)); + public InterruptibleFuture definition(IList focus) { + return flatten(definition, c -> c.definition(focus)); } @Override - public InterruptibleFuture runReferencesService(IList focus) { - return flatten(getReferencesService, c -> c.runReferencesService(focus)); + public InterruptibleFuture references(IList focus) { + return flatten(references, c -> c.references(focus)); } @Override - public InterruptibleFuture runImplementationService(IList focus) { - return flatten(getImplementationService, c -> c.runImplementationService(focus)); + public InterruptibleFuture implementation(IList focus) { + return flatten(implementation, c -> c.implementation(focus)); } @Override - public InterruptibleFuture runCodeActionService(IList focus) { - return flatten(getCodeActionService, c -> c.runCodeActionService(focus)); + public InterruptibleFuture codeAction(IList focus) { + return flatten(codeAction, c -> c.codeAction(focus)); } @Override - public CompletableFuture hasCodeActionService() { - return hasCodeActionService; + public CompletableFuture hasCodeAction() { + return hasCodeAction; } @Override - public CompletableFuture hasHoverService() { - return hasHoverService; + public CompletableFuture hasHover() { + return hasHover; } @Override - public CompletableFuture hasDefinitionService() { - return hasDefinitionService; + public CompletableFuture hasDefinition() { + return hasDefinition; } @Override - public CompletableFuture hasReferencesService() { - return hasReferencesService; + public CompletableFuture hasReferences() { + return hasReferences; } @Override - public CompletableFuture hasImplementationService() { - return hasImplementationService; + public CompletableFuture hasImplementation() { + return hasImplementation; } @Override - public CompletableFuture hasDocumentSymbolService() { - return hasDocumentSymbolService; + public CompletableFuture hasDocumentSymbol() { + return hasDocumentSymbol; } @Override - public CompletableFuture hasAnalysisService() { - return hasAnalysisService; + public CompletableFuture hasAnalysis() { + return hasAnalysis; } @Override - public CompletableFuture hasBuildService() { - return hasBuildService; + public CompletableFuture hasBuild() { + return hasBuild; } @Override - public CompletableFuture hasCodeLensService() { - return hasCodeLensService; + public CompletableFuture hasCodeLens() { + return hasCodeLens; } @Override - public CompletableFuture hasExecutionService() { - return hasExecutionService; + public CompletableFuture hasExecution() { + return hasExecution; } @Override - public CompletableFuture hasInlayHintService() { - return hasInlayHintService; + public CompletableFuture hasInlayHint() { + return hasInlayHint; } @Override diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java index b8fc8b644..83da701f2 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java @@ -328,7 +328,7 @@ public CompletableFuture> codeLens(CodeLensParams param return recoverExceptions(file.getCurrentTreeAsync() .thenApply(Versioned::get) - .thenApply(contrib::runCodeLensService) + .thenApply(contrib::codeLens) .thenCompose(InterruptibleFuture::get) .thenApply(s -> s.stream() .map(e -> locCommandTupleToCodeLense(contrib.getName(), e)) @@ -344,7 +344,7 @@ public CompletableFuture> inlayHint(InlayHintParams params) { return recoverExceptions( recoverExceptions(file.getCurrentTreeAsync(), file::getMostRecentTree) .thenApply(Versioned::get) - .thenApply(contrib::runInlayHintService) + .thenApply(contrib::inlayHint) .thenCompose(InterruptibleFuture::get) .thenApply(s -> s.stream() .map(this::rowToInlayHint) @@ -519,7 +519,7 @@ private ParametricFileFacts facts(String doc) { private TextDocumentState open(TextDocumentItem doc) { return files.computeIfAbsent(Locations.toLoc(doc), - l -> new TextDocumentState(contributions(doc)::runParsingService, l, doc.getVersion(), doc.getText()) + l -> new TextDocumentState(contributions(doc)::parsing, l, doc.getVersion(), doc.getText()) ); } @@ -576,7 +576,7 @@ public CompletableFuture semanticTokensRange(SemanticTokensRange ILanguageContributions contrib = contributions(params.getTextDocument()); return recoverExceptions(file.getCurrentTreeAsync() .thenApply(Versioned::get) - .thenApply(contrib::runDocumentSymbolService) + .thenApply(contrib::documentSymbol) .thenCompose(InterruptibleFuture::get) .thenApply(documentSymbols -> DocumentSymbols.toLSP(documentSymbols, columns.get(file.getLocation()))) , Collections::emptyList); @@ -638,7 +638,7 @@ private CompletableFuture computeCodeActions(final ILanguageContributions IList focus = TreeSearch.computeFocusList(tree, startLine, startColumn); if (!focus.isEmpty()) { - return contribs.runCodeActionService(focus).get(); + return contribs.codeAction(focus).get(); } else { logger.log(Level.DEBUG, "no tree focus found at {}:{}", startLine, startColumn); @@ -777,7 +777,7 @@ public CompletableFuture executeCommand(String languageName, String comm ILanguageContributions contribs = contributions.get(languageName); if (contribs != null) { - return contribs.runExecutionService(command).get(); + return contribs.execution(command).get(); } else { logger.warn("ignoring command execution (no contributor configured for this language): {}, {} ", languageName, command); diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java index 80e597b3d..3ba38ca3a 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java @@ -75,7 +75,7 @@ public String getName() { } @Override - public CompletableFuture runParsingService(ISourceLocation loc, String input) { + public CompletableFuture parsing(ISourceLocation loc, String input) { if (loadingParserError != null || parser == null) { return CompletableFuture.failedFuture(new RuntimeException("Parser function did not load", loadingParserError)); } @@ -114,27 +114,27 @@ private static IConstructor makeReifiedType(ParserSpecification spec, IRascalVal } @Override - public InterruptibleFuture runDocumentSymbolService(ITree input) { + public InterruptibleFuture documentSymbol(ITree input) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture runAnalysisService(ISourceLocation loc, ITree input) { + public InterruptibleFuture analysis(ISourceLocation loc, ITree input) { return InterruptibleFuture.completedFuture(EmptySummary.newInstance(loc)); } @Override - public InterruptibleFuture runBuildService(ISourceLocation loc, ITree input) { + public InterruptibleFuture build(ISourceLocation loc, ITree input) { return InterruptibleFuture.completedFuture(EmptySummary.newInstance(loc)); } @Override - public InterruptibleFuture runCodeLensService(ITree input) { + public InterruptibleFuture codeLens(ITree input) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture<@Nullable IValue> runExecutionService(String command) { + public InterruptibleFuture<@Nullable IValue> execution(String command) { return InterruptibleFuture.completedFuture(VF.bool(false)); } @@ -144,87 +144,87 @@ public CompletableFuture parseCodeActions(String commands) { } @Override - public InterruptibleFuture runInlayHintService(@Nullable ITree input) { + public InterruptibleFuture inlayHint(@Nullable ITree input) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture runHoverService(IList focus) { + public InterruptibleFuture hover(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public InterruptibleFuture runDefinitionService(IList focus) { + public InterruptibleFuture definition(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public InterruptibleFuture runReferencesService(IList focus) { + public InterruptibleFuture references(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public InterruptibleFuture runCodeActionService(IList focus) { + public InterruptibleFuture codeAction(IList focus) { return InterruptibleFuture.completedFuture(VF.list()); } @Override - public InterruptibleFuture runImplementationService(IList focus) { + public InterruptibleFuture implementation(IList focus) { return InterruptibleFuture.completedFuture(VF.set()); } @Override - public CompletableFuture hasHoverService() { + public CompletableFuture hasHover() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasDefinitionService() { + public CompletableFuture hasDefinition() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasReferencesService() { + public CompletableFuture hasReferences() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasImplementationService() { + public CompletableFuture hasImplementation() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasDocumentSymbolService() { + public CompletableFuture hasDocumentSymbol() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasAnalysisService() { + public CompletableFuture hasAnalysis() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasBuildService() { + public CompletableFuture hasBuild() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasCodeActionService() { + public CompletableFuture hasCodeAction() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasCodeLensService() { + public CompletableFuture hasCodeLens() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasExecutionService() { + public CompletableFuture hasExecution() { return CompletableFuture.completedFuture(false); } @Override - public CompletableFuture hasInlayHintService() { + public CompletableFuture hasInlayHint() { return CompletableFuture.completedFuture(false); } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java index d2de95508..69956d6e3 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricSummary.java @@ -435,22 +435,22 @@ public OndemandSummary(ISourceLocation file, Versioned tree, Position cur @Override @SuppressWarnings("deprecation") // For `MarkedString` public @Nullable InterruptibleFuture>> getHovers(Position cursor) { - return get(config.providesHovers, cursor, contrib::runHoverService, ParametricSummaryFactory::mapValueToString, SummaryFields.HOVERS); + return get(config.providesHovers, cursor, contrib::hover, ParametricSummaryFactory::mapValueToString, SummaryFields.HOVERS); } @Override public @Nullable InterruptibleFuture> getDefinitions(Position cursor) { - return get(config.providesDefinitions, cursor, contrib::runDefinitionService, locationMapper(columns), SummaryFields.DEFINITIONS); + return get(config.providesDefinitions, cursor, contrib::definition, locationMapper(columns), SummaryFields.DEFINITIONS); } @Override public @Nullable InterruptibleFuture> getReferences(Position cursor) { - return get(config.providesReferences, cursor, contrib::runReferencesService, locationMapper(columns), SummaryFields.REFERENCES); + return get(config.providesReferences, cursor, contrib::references, locationMapper(columns), SummaryFields.REFERENCES); } @Override public @Nullable InterruptibleFuture> getImplementations(Position cursor) { - return get(config.providesImplementations, cursor, contrib::runImplementationService, locationMapper(columns), SummaryFields.IMPLEMENTATIONS); + return get(config.providesImplementations, cursor, contrib::implementation, locationMapper(columns), SummaryFields.IMPLEMENTATIONS); } @Override From b8cdde6b92bcc2dfbbba40ba043afa3124121fd2 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Wed, 23 Oct 2024 11:57:51 +0200 Subject: [PATCH 52/57] Made names shorter (without `run..Service` pre/suffix) --- .../vscode/lsp/parametric/model/ParametricFileFacts.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java index e1adc0bdf..113100fb8 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/ParametricFileFacts.java @@ -114,9 +114,9 @@ private FileFact getFile(ISourceLocation l) { public void reloadContributions() { analyzerSummaryFactory = contrib.getAnalyzerSummaryConfig().thenApply(config -> - new ScheduledSummaryFactory(config, exec, columns, contrib::runAnalysisService)); + new ScheduledSummaryFactory(config, exec, columns, contrib::analysis)); builderSummaryFactory = contrib.getBuilderSummaryConfig().thenApply(config -> - new ScheduledSummaryFactory(config, exec, columns, contrib::runBuildService)); + new ScheduledSummaryFactory(config, exec, columns, contrib::build)); ondemandSummaryFactory = contrib.getOndemandSummaryConfig().thenApply(config -> new OndemandSummaryFactory(config, exec, columns, contrib)); } From 16d87beff97ed72b5d7f2049b06c8d61e40b5c38 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Wed, 23 Oct 2024 12:44:41 +0200 Subject: [PATCH 53/57] Remove horizontal alignment --- .../parametric/ILanguageContributions.java | 22 +++++----- .../InterpretedLanguageContributions.java | 40 +++++++++---------- .../LanguageContributionsMultiplexer.java | 36 ++++++++--------- .../lsp/parametric/model/RascalADTs.java | 34 ++++++++-------- 4 files changed, 66 insertions(+), 66 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java index d73e0fc15..256593af6 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java @@ -46,18 +46,18 @@ public interface ILanguageContributions { public String getName(); - public CompletableFuture parsing(ISourceLocation loc, String input); - public InterruptibleFuture analysis(ISourceLocation loc, ITree input); - public InterruptibleFuture build(ISourceLocation loc, ITree input); - public InterruptibleFuture documentSymbol(ITree input); - public InterruptibleFuture codeLens(ITree input); - public InterruptibleFuture inlayHint(@Nullable ITree input); + public CompletableFuture parsing(ISourceLocation loc, String input); + public InterruptibleFuture analysis(ISourceLocation loc, ITree input); + public InterruptibleFuture build(ISourceLocation loc, ITree input); + public InterruptibleFuture documentSymbol(ITree input); + public InterruptibleFuture codeLens(ITree input); + public InterruptibleFuture inlayHint(@Nullable ITree input); public InterruptibleFuture<@Nullable IValue> execution(String command); - public InterruptibleFuture hover(IList focus); - public InterruptibleFuture definition(IList focus); - public InterruptibleFuture references(IList focus); - public InterruptibleFuture implementation(IList focus); - public InterruptibleFuture codeAction(IList focus); + public InterruptibleFuture hover(IList focus); + public InterruptibleFuture definition(IList focus); + public InterruptibleFuture references(IList focus); + public InterruptibleFuture implementation(IList focus); + public InterruptibleFuture codeAction(IList focus); public CompletableFuture parseCodeActions(String command); diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java index fa78ef1ee..14cc02637 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java @@ -125,34 +125,34 @@ public InterpretedLanguageContributions(LanguageParameter lang, IBaseTextDocumen this.store = eval.thenApply(e -> ((ModuleEnvironment)e.getModule(mainModule)).getStore()); - this.parsing = getFunctionFor(contributions, LanguageContributions.PARSING); - this.analysis = getFunctionFor(contributions, LanguageContributions.ANALYSIS); - this.build = getFunctionFor(contributions, LanguageContributions.BUILD); + this.parsing = getFunctionFor(contributions, LanguageContributions.PARSING); + this.analysis = getFunctionFor(contributions, LanguageContributions.ANALYSIS); + this.build = getFunctionFor(contributions, LanguageContributions.BUILD); this.documentSymbol = getFunctionFor(contributions, LanguageContributions.DOCUMENT_SYMBOL); - this.codeLens = getFunctionFor(contributions, LanguageContributions.CODE_LENS); - this.inlayHint = getFunctionFor(contributions, LanguageContributions.INLAY_HINT); - this.execution = getFunctionFor(contributions, LanguageContributions.EXECUTION); - this.hover = getFunctionFor(contributions, LanguageContributions.HOVER); - this.definition = getFunctionFor(contributions, LanguageContributions.DEFINITION); - this.references = getFunctionFor(contributions, LanguageContributions.REFERENCES); + this.codeLens = getFunctionFor(contributions, LanguageContributions.CODE_LENS); + this.inlayHint = getFunctionFor(contributions, LanguageContributions.INLAY_HINT); + this.execution = getFunctionFor(contributions, LanguageContributions.EXECUTION); + this.hover = getFunctionFor(contributions, LanguageContributions.HOVER); + this.definition = getFunctionFor(contributions, LanguageContributions.DEFINITION); + this.references = getFunctionFor(contributions, LanguageContributions.REFERENCES); this.implementation = getFunctionFor(contributions, LanguageContributions.IMPLEMENTATION); - this.codeAction = getFunctionFor(contributions, LanguageContributions.CODE_ACTION); + this.codeAction = getFunctionFor(contributions, LanguageContributions.CODE_ACTION); // assign boolean properties once instead of wasting futures all the time - this.hasAnalysis = nonNull(this.analysis); - this.hasBuild = nonNull(this.build); + this.hasAnalysis = nonNull(this.analysis); + this.hasBuild = nonNull(this.build); this.hasDocumentSymbol = nonNull(this.documentSymbol); - this.hasCodeLens = nonNull(this.codeLens); - this.hasInlayHint = nonNull(this.inlayHint); - this.hasExecution = nonNull(this.execution); - this.hasHover = nonNull(this.hover); - this.hasDefinition = nonNull(this.definition); - this.hasReferences = nonNull(this.references); + this.hasCodeLens = nonNull(this.codeLens); + this.hasInlayHint = nonNull(this.inlayHint); + this.hasExecution = nonNull(this.execution); + this.hasHover = nonNull(this.hover); + this.hasDefinition = nonNull(this.definition); + this.hasReferences = nonNull(this.references); this.hasImplementation = nonNull(this.implementation); - this.hasCodeAction = nonNull(this.codeAction); + this.hasCodeAction = nonNull(this.codeAction); this.analyzerSummaryConfig = scheduledSummaryConfig(contributions, LanguageContributions.ANALYSIS); - this.builderSummaryConfig = scheduledSummaryConfig(contributions, LanguageContributions.BUILD); + this.builderSummaryConfig = scheduledSummaryConfig(contributions, LanguageContributions.BUILD); this.ondemandSummaryConfig = ondemandSummaryConfig(contributions); } catch (IOException e1) { diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java index a43fb300a..8fb52e459 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java @@ -136,31 +136,31 @@ private synchronized void calculateRouting() { // future parsing = firstOrFail(); - analysis = findFirstOrDefault(ILanguageContributions::hasAnalysis); - build = findFirstOrDefault(ILanguageContributions::hasBuild); + analysis = findFirstOrDefault(ILanguageContributions::hasAnalysis); + build = findFirstOrDefault(ILanguageContributions::hasBuild); documentSymbol = findFirstOrDefault(ILanguageContributions::hasDocumentSymbol); - codeLens = findFirstOrDefault(ILanguageContributions::hasCodeLens); - inlayHint = findFirstOrDefault(ILanguageContributions::hasInlayHint); - execution = findFirstOrDefault(ILanguageContributions::hasExecution); - hover = findFirstOrDefault(ILanguageContributions::hasHover); - definition = findFirstOrDefault(ILanguageContributions::hasDefinition); - references = findFirstOrDefault(ILanguageContributions::hasReferences); + codeLens = findFirstOrDefault(ILanguageContributions::hasCodeLens); + inlayHint = findFirstOrDefault(ILanguageContributions::hasInlayHint); + execution = findFirstOrDefault(ILanguageContributions::hasExecution); + hover = findFirstOrDefault(ILanguageContributions::hasHover); + definition = findFirstOrDefault(ILanguageContributions::hasDefinition); + references = findFirstOrDefault(ILanguageContributions::hasReferences); implementation = findFirstOrDefault(ILanguageContributions::hasImplementation); - codeAction = findFirstOrDefault(ILanguageContributions::hasCodeAction); + codeAction = findFirstOrDefault(ILanguageContributions::hasCodeAction); - hasAnalysis = anyTrue(ILanguageContributions::hasAnalysis); - hasBuild = anyTrue(ILanguageContributions::hasBuild); + hasAnalysis = anyTrue(ILanguageContributions::hasAnalysis); + hasBuild = anyTrue(ILanguageContributions::hasBuild); hasDocumentSymbol = anyTrue(ILanguageContributions::hasDocumentSymbol); - hasCodeLens = anyTrue(ILanguageContributions::hasCodeLens); - hasInlayHint = anyTrue(ILanguageContributions::hasInlayHint); - hasExecution = anyTrue(ILanguageContributions::hasExecution); - hasHover = anyTrue(ILanguageContributions::hasHover); - hasDefinition = anyTrue(ILanguageContributions::hasDefinition); - hasReferences = anyTrue(ILanguageContributions::hasReferences); + hasCodeLens = anyTrue(ILanguageContributions::hasCodeLens); + hasInlayHint = anyTrue(ILanguageContributions::hasInlayHint); + hasExecution = anyTrue(ILanguageContributions::hasExecution); + hasHover = anyTrue(ILanguageContributions::hasHover); + hasDefinition = anyTrue(ILanguageContributions::hasDefinition); + hasReferences = anyTrue(ILanguageContributions::hasReferences); hasImplementation = anyTrue(ILanguageContributions::hasImplementation); analyzerSummaryConfig = anyTrue(ILanguageContributions::getAnalyzerSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); - builderSummaryConfig = anyTrue(ILanguageContributions::getBuilderSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); + builderSummaryConfig = anyTrue(ILanguageContributions::getBuilderSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); ondemandSummaryConfig = anyTrue(ILanguageContributions::getOndemandSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or); } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java index bfa66ddaf..837a3c2c2 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java @@ -34,25 +34,25 @@ private RascalADTs() {} public static class LanguageContributions { private LanguageContributions () {} - public static final String PARSING = "parsing"; - public static final String ANALYSIS = "analysis"; - public static final String BUILD = "build"; + public static final String PARSING = "parsing"; + public static final String ANALYSIS = "analysis"; + public static final String BUILD = "build"; public static final String DOCUMENT_SYMBOL = "documentSymbol"; - public static final String CODE_LENS = "codeLens"; - public static final String INLAY_HINT = "inlayHint"; - public static final String EXECUTION = "execution"; - public static final String HOVER = "hover"; - public static final String DEFINITION = "definition"; - public static final String REFERENCES = "references"; - public static final String IMPLEMENTATION = "implementation"; - public static final String CODE_ACTION = "codeAction"; + public static final String CODE_LENS = "codeLens"; + public static final String INLAY_HINT = "inlayHint"; + public static final String EXECUTION = "execution"; + public static final String HOVER = "hover"; + public static final String DEFINITION = "definition"; + public static final String REFERENCES = "references"; + public static final String IMPLEMENTATION = "implementation"; + public static final String CODE_ACTION = "codeAction"; public static class Summarizers { private Summarizers() {} - public static final String PROVIDES_HOVERS = "providesHovers"; - public static final String PROVIDES_DEFINITIONS = "providesDefinitions"; - public static final String PROVIDES_REFERENCES = "providesReferences"; + public static final String PROVIDES_HOVERS = "providesHovers"; + public static final String PROVIDES_DEFINITIONS = "providesDefinitions"; + public static final String PROVIDES_REFERENCES = "providesReferences"; public static final String PROVIDES_IMPLEMENTATIONS = "providesImplementations"; } } @@ -62,9 +62,9 @@ private SummaryFields() {} public static final String DEPRECATED_DOCUMENTATION = "documentation"; - public static final String HOVERS = "hovers"; - public static final String DEFINITIONS = "definitions"; - public static final String REFERENCES = "references"; + public static final String HOVERS = "hovers"; + public static final String DEFINITIONS = "definitions"; + public static final String REFERENCES = "references"; public static final String IMPLEMENTATIONS = "implementations"; } From b1b54669f46a8ded009780794868d5587f8cd146 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Wed, 23 Oct 2024 13:29:45 +0200 Subject: [PATCH 54/57] renamed LanguageServer to OldStyleLanguageServer and NewLanguageServer to LanguageServer in the pico demo and added documentation to reflect it --- .../rascal/demo/lang/pico/LanguageServer.rsc | 88 +++++--- .../demo/lang/pico/NewLanguageServer.rsc | 205 ------------------ .../src/test/vscode-suite/dsl.test.ts | 2 +- 3 files changed, 56 insertions(+), 239 deletions(-) delete mode 100644 rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc index 1ac8bfdf6..5e0eae424 100644 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc @@ -24,7 +24,13 @@ 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. } -// @deprecated{This demo has been superseded by ((NewLanguageServer)) which avoids the use of deprecated API.} +@synopsis{Demonstrates the API for defining and registering IDE language services for Programming Languages and Domain Specific Languages.} +@description{ +The core functionality of this module is built upon these concepts: +* ((registerLanguage)) for enabling your language services for a given file extension _in the current IDE_. +* ((Language)) is the data-type for defining a language, with meta-data for starting a new LSP server. +* A ((LanguageService)) is a specific feature for an IDE. Each service comes with one Rascal function that implements it. +} module demo::lang::pico::LanguageServer import util::LanguageServer; @@ -33,35 +39,49 @@ import ParseTree; import util::Reflective; import lang::pico::\syntax::Main; -@synopsis{Provides each contribution (IDE feature) as a callback element of the set of LanguageServices.} -set[LanguageService] picoLanguageContributor() = { - parser(parser(#start[Program])), - outliner(picoOutliner), - lenses(picoLenses), - executor(picoCommands), - inlayHinter(picoHinter), - definer(lookupDef), - actions(picoActions) +@synopsis{A language server is simply a set of ((LanguageService))s.} +@description{ +Each ((LanguageService)) for pico is implemented as a function. +Here we group all services such that the LSP server can link them +with the ((Language)) definition later. +} +set[LanguageService] picoLanguageServer() = { + parsing(parser(#start[Program])), + documentSymbol(picoDocumentSymbolService), + codeLens(picoCodeLenseService), + execution(picoExecutionService), + inlayHint(picoInlayHintService), + definition(picoDefinitionService), + codeAction(picoCodeActionService) }; @synopsis{This set of contributions runs slower but provides more detail.} -set[LanguageService] picoLanguageContributorSlowSummary() = { - parser(parser(#start[Program])), - analyzer(picoAnalyzer, providesImplementations = false), - builder(picoBuilder) +@description{ +((LanguageService))s can be registered asynchronously and incrementally, +such that quicky loaded features can be made available while slower to load +tools come in later. +} +set[LanguageService] picoLanguageServerSlowSummary() = { + parsing(parser(#start[Program])), + analysis(picoAnalysisService, providesImplementations = false), + build(picoBuildService) }; -@synopsis{The outliner maps pico syntax trees to lists of DocumentSymbols.} -list[DocumentSymbol] picoOutliner(start[Program] input) +@synopsis{The documentSymbol service maps pico syntax trees to lists of DocumentSymbols.} +@description{ +Here we list the symbols we want in the outline view, and which can be searched using +symbol search in the editor. +} +list[DocumentSymbol] picoDocumentSymbolService(start[Program] input) = [symbol("", DocumentSymbolKind::\file(), input.src, children=[ *[symbol("", \variable(), var.src) | /IdType var := input] ])]; @synopsis{The analyzer maps pico syntax trees to error messages and references} -Summary picoAnalyzer(loc l, start[Program] input) = picoSummarizer(l, input, analyze()); +Summary picoAnalysisService(loc l, start[Program] input) = picoSummaryService(l, input, analyze()); @synopsis{The builder does a more thorough analysis then the analyzer, providing more detail} -Summary picoBuilder(loc l, start[Program] input) = picoSummarizer(l, input, build()); +Summary picoBuildService(loc l, start[Program] input) = picoSummaryService(l, input, build()); @synopsis{A simple "enum" data type for switching between analysis modes} data PicoSummarizerMode @@ -70,7 +90,7 @@ data PicoSummarizerMode ; @synopsis{Translates a pico syntax tree to a model (Summary) of everything we need to know about the program in the IDE.} -Summary picoSummarizer(loc l, start[Program] input, PicoSummarizerMode mode) { +Summary picoSummaryService(loc l, start[Program] input, PicoSummarizerMode mode) { Summary s = summary(l); // definitions of variables @@ -104,19 +124,21 @@ Summary picoSummarizer(loc l, start[Program] input, PicoSummarizerMode mode) { return s; } -@synopsis{Looks up the declaration for any variable use using the / deep match} -set[loc] lookupDef(loc _, start[Program] input, Tree cursor) = - {d.src | /IdType d := input, cursor := d.id}; +@synopsis{Looks up the declaration for any variable use using a list match into a ((Focus))} +@pitfalls{ +This demo actually finds the declaration rather than the definition of a variable in Pico. +} +set[loc] picoDefinitionService([*_, Id use, *_, start[Program] input]) = { def.src | /IdType def := input, use := def.id}; @synopsis{If a variable is not defined, we list a fix of fixes to replace it with a defined variable instead.} list[CodeAction] prepareNotDefinedFixes(loc src, rel[str, loc] defs) = [action(title="Change to >", edits=[changed(src.top, [replace(src, existing<0>)])]) | existing <- defs]; @synopsis{Finds a declaration that the cursor is on and proposes to remove it.} -list[CodeAction] picoActions([*Tree _, IdType x, *Tree _, start[Program] program]) +list[CodeAction] picoCodeActionService([*_, IdType x, *_, start[Program] program]) = [action(command=removeDecl(program, x, title="remove "))]; -default list[CodeAction] picoActions(Focus _focus) = []; +default list[CodeAction] picoCodeActionService(Focus _focus) = []; @synsopsis{Defines three example commands that can be triggered by the user (from a code lens, from a diagnostic, or just from the cursor position)} data Command @@ -125,11 +147,11 @@ data Command ; @synopsis{Adds an example lense to the entire program.} -rel[loc,Command] picoLenses(start[Program] input) - = {}; +lrel[loc,Command] picoCodeLenseService(start[Program] input) + = []; @synopsis{Generates inlay hints that explain the type of each variable usage.} -list[InlayHint] picoHinter(start[Program] input) { +list[InlayHint] picoInlayHintService(start[Program] input) { typeLookup = ( "" : "" | /(IdType)` : ` := input); return [ @@ -144,13 +166,13 @@ list[DocumentEdit] getAtoBEdits(start[Program] input) = [changed(input@\loc.top, [replace(id@\loc, "b") | /id:(Id) `a` := input])]; @synopsis{Command handler for the renameAtoB command} -value picoCommands(renameAtoB(start[Program] input)) { +value picoExecutionService(renameAtoB(start[Program] input)) { applyDocumentsEdits(getAtoBEdits(input)); return ("result": true); } @synopsis{Command handler for the removeDecl command} -value picoCommands(removeDecl(start[Program] program, IdType toBeRemoved)) { +value picoExecutionService(removeDecl(start[Program] program, IdType toBeRemoved)) { applyDocumentsEdits([changed(program@\loc.top, [replace(toBeRemoved@\loc, "")])]); return ("result": true); } @@ -173,8 +195,8 @@ void main() { pathConfig(), "Pico", {"pico", "pico-new"}, - "demo::lang::pico::LanguageServer", - "picoLanguageContributor" + "demo::lang::pico::NewLanguageServer", + "picoLanguageServer" ) ); registerLanguage( @@ -182,8 +204,8 @@ void main() { pathConfig(), "Pico", {"pico", "pico-new"}, - "demo::lang::pico::LanguageServer", - "picoLanguageContributorSlowSummary" + "demo::lang::pico::NewLanguageServer", + "picoLanguageServerSlowSummary" ) ); } diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc deleted file mode 100644 index 3496adbf4..000000000 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc +++ /dev/null @@ -1,205 +0,0 @@ -@license{ -Copyright (c) 2018-2023, NWO-I CWI and Swat.engineering -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{Demonstrates the latest API for defining and registering IDE features for Programming Languages and Domain Specific Languages.} -module demo::lang::pico::NewLanguageServer - -import util::LanguageServer; -import util::IDEServices; -import ParseTree; -import util::Reflective; -import lang::pico::\syntax::Main; - -@synopsis{A language server is simply a set of ((LanguageService))s.} -@description{ -Each ((LanguageService)) for pico is implemented as a function. -Here we group all services such that the LSP server can link them -with the ((Language)) definition later. -} -set[LanguageService] picoLanguageServer() = { - parsing(parser(#start[Program])), - documentSymbol(picoDocumentSymbolService), - codeLens(picoCodeLenseService), - execution(picoExecutionService), - inlayHint(picoInlayHintService), - definition(picoDefinitionService), - codeAction(picoCodeActionService) -}; - -@synopsis{This set of contributions runs slower but provides more detail.} -@description{ -((LanguageService))s can be registered asynchronously and incrementally, -such that quicky loaded features can be made available while slower to load -tools come in later. -} -set[LanguageService] picoLanguageServerSlowSummary() = { - parsing(parser(#start[Program])), - analysis(picoAnalysisService, providesImplementations = false), - build(picoBuildService) -}; - -@synopsis{The documentSymbol service maps pico syntax trees to lists of DocumentSymbols.} -@description{ -Here we list the symbols we want in the outline view, and which can be searched using -symbol search in the editor. -} -list[DocumentSymbol] picoDocumentSymbolService(start[Program] input) - = [symbol("", DocumentSymbolKind::\file(), input.src, children=[ - *[symbol("", \variable(), var.src) | /IdType var := input] - ])]; - -@synopsis{The analyzer maps pico syntax trees to error messages and references} -Summary picoAnalysisService(loc l, start[Program] input) = picoSummaryService(l, input, analyze()); - -@synopsis{The builder does a more thorough analysis then the analyzer, providing more detail} -Summary picoBuildService(loc l, start[Program] input) = picoSummaryService(l, input, build()); - -@synopsis{A simple "enum" data type for switching between analysis modes} -data PicoSummarizerMode - = analyze() - | build() - ; - -@synopsis{Translates a pico syntax tree to a model (Summary) of everything we need to know about the program in the IDE.} -Summary picoSummaryService(loc l, start[Program] input, PicoSummarizerMode mode) { - Summary s = summary(l); - - // definitions of variables - rel[str, loc] defs = {<"", var.src> | /IdType var := input}; - - // uses of identifiers - rel[loc, str] uses = {"> | /Id id := input}; - - // documentation strings for identifier uses - rel[loc, str] docs = {"> | /IdType var := input}; - - // Provide errors (cheap to compute) both in analyze mode and in build mode. - s.messages += { is not defined", src, fixes=prepareNotDefinedFixes(src, defs))> - | <- uses, id notin defs<0>}; - - // "references" are links for loc to loc (from def to use) - s.references += (uses o defs)<1,0>; - - // "definitions" are also links from loc to loc (from use to def) - s.definitions += uses o defs; - - // "documentation" maps locations to strs - s.documentation += (uses o defs) o docs; - - // Provide warnings (expensive to compute) only in build mode - if (build() := mode) { - rel[loc, str] asgn = {"> | /Statement stmt := input, (Statement) ` := ` := stmt}; - s.messages += { is not assigned", src)> | <- defs, id notin asgn<1>}; - } - - return s; -} - -@synopsis{Looks up the declaration for any variable use using a list match into a ((Focus))} -@pitfalls{ -This demo actually finds the declaration rather than the definition of a variable in Pico. -} -set[loc] picoDefinitionService([*_, Id use, *_, start[Program] input]) = { def.src | /IdType def := input, use := def.id}; - -@synopsis{If a variable is not defined, we list a fix of fixes to replace it with a defined variable instead.} -list[CodeAction] prepareNotDefinedFixes(loc src, rel[str, loc] defs) - = [action(title="Change to >", edits=[changed(src.top, [replace(src, existing<0>)])]) | existing <- defs]; - -@synopsis{Finds a declaration that the cursor is on and proposes to remove it.} -list[CodeAction] picoCodeActionService([*_, IdType x, *_, start[Program] program]) - = [action(command=removeDecl(program, x, title="remove "))]; - -default list[CodeAction] picoCodeActionService(Focus _focus) = []; - -@synsopsis{Defines three example commands that can be triggered by the user (from a code lens, from a diagnostic, or just from the cursor position)} -data Command - = renameAtoB(start[Program] program) - | removeDecl(start[Program] program, IdType toBeRemoved) - ; - -@synopsis{Adds an example lense to the entire program.} -lrel[loc,Command] picoCodeLenseService(start[Program] input) - = []; - -@synopsis{Generates inlay hints that explain the type of each variable usage.} -list[InlayHint] picoInlayHintService(start[Program] input) { - typeLookup = ( "" : "" | /(IdType)` : ` := input); - - return [ - hint(name.src, " : "]>", \type(), atEnd = true) - | /(Expression)`` := input - , "" in typeLookup - ]; -} - -@synopsis{Helper function to generate actual edit actions for the renameAtoB command} -list[DocumentEdit] getAtoBEdits(start[Program] input) - = [changed(input@\loc.top, [replace(id@\loc, "b") | /id:(Id) `a` := input])]; - -@synopsis{Command handler for the renameAtoB command} -value picoExecutionService(renameAtoB(start[Program] input)) { - applyDocumentsEdits(getAtoBEdits(input)); - return ("result": true); -} - -@synopsis{Command handler for the removeDecl command} -value picoExecutionService(removeDecl(start[Program] program, IdType toBeRemoved)) { - applyDocumentsEdits([changed(program@\loc.top, [replace(toBeRemoved@\loc, "")])]); - return ("result": true); -} - -@synopsis{The main function registers the Pico language with the IDE} -@description{ -Register the Pico language and the contributions that supply the IDE with features. - -((registerLanguage)) is called twice here: -1. first for fast and cheap contributions -2. asynchronously for the full monty that loads slower -} -@benefits{ -* You can run each contribution on an example in the terminal to test it first. -Any feedback (errors and exceptions) is faster and more clearly printed in the terminal. -} -void main() { - registerLanguage( - language( - pathConfig(), - "Pico", - {"pico", "pico-new"}, - "demo::lang::pico::NewLanguageServer", - "picoLanguageServer" - ) - ); - registerLanguage( - language( - pathConfig(), - "Pico", - {"pico", "pico-new"}, - "demo::lang::pico::NewLanguageServer", - "picoLanguageServerSlowSummary" - ) - ); -} diff --git a/rascal-vscode-extension/src/test/vscode-suite/dsl.test.ts b/rascal-vscode-extension/src/test/vscode-suite/dsl.test.ts index 976452b4a..32abc9c21 100644 --- a/rascal-vscode-extension/src/test/vscode-suite/dsl.test.ts +++ b/rascal-vscode-extension/src/test/vscode-suite/dsl.test.ts @@ -46,7 +46,7 @@ describe('DSL', function () { async function loadPico() { const repl = new RascalREPL(bench, driver); await repl.start(); - await repl.execute("import demo::lang::pico::LanguageServer;"); + await repl.execute("import demo::lang::pico::OldStyleLanguageServer;"); const replExecuteMain = repl.execute("main();"); // we don't wait yet, because we might miss pico loading window const ide = new IDEOperations(browser); const isPicoLoading = ide.statusContains("Pico"); From 3158b01ffe28241e3f9d0bea3413cf3d93aa923f Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Wed, 23 Oct 2024 13:36:35 +0200 Subject: [PATCH 55/57] forgot to add --- .../demo/lang/pico/OldStyleLanguageServer.rsc | 194 ++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 rascal-lsp/src/main/rascal/demo/lang/pico/OldStyleLanguageServer.rsc diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/OldStyleLanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/OldStyleLanguageServer.rsc new file mode 100644 index 000000000..cf15fd068 --- /dev/null +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/OldStyleLanguageServer.rsc @@ -0,0 +1,194 @@ +@license{ +Copyright (c) 2018-2023, NWO-I CWI and Swat.engineering +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{Demonstrating all of the LSP services for the demo language Pico.} +@deprecated{This demo has been superseded by ((LanguageServer)) which avoids the use of deprecated API.} +@description{ +This module is here to test the backward compatibility layer over the new ((LanguageServer)) API. +For learning how to build a new set of lanuage services, please go [here]((LanguageServer)). +} +module demo::lang::pico::OldStyleLanguageServer + +import util::LanguageServer; +import util::IDEServices; +import ParseTree; +import util::Reflective; +import lang::pico::\syntax::Main; + +@synopsis{Provides each contribution (IDE feature) as a callback element of the set of LanguageServices.} +set[LanguageService] picoLanguageContributor() = { + parser(parser(#start[Program])), + outliner(picoOutliner), + lenses(picoLenses), + executor(picoCommands), + inlayHinter(picoHinter), + definer(lookupDef), + actions(picoActions) +}; + +@synopsis{This set of contributions runs slower but provides more detail.} +set[LanguageService] picoLanguageContributorSlowSummary() = { + parser(parser(#start[Program])), + analyzer(picoAnalyzer, providesImplementations = false), + builder(picoBuilder) +}; + +@synopsis{The outliner maps pico syntax trees to lists of DocumentSymbols.} +list[DocumentSymbol] picoOutliner(start[Program] input) + = [symbol("", DocumentSymbolKind::\file(), input.src, children=[ + *[symbol("", \variable(), var.src) | /IdType var := input] + ])]; + +@synopsis{The analyzer maps pico syntax trees to error messages and references} +Summary picoAnalyzer(loc l, start[Program] input) = picoSummarizer(l, input, analyze()); + +@synopsis{The builder does a more thorough analysis then the analyzer, providing more detail} +Summary picoBuilder(loc l, start[Program] input) = picoSummarizer(l, input, build()); + +@synopsis{A simple "enum" data type for switching between analysis modes} +data PicoSummarizerMode + = analyze() + | build() + ; + +@synopsis{Translates a pico syntax tree to a model (Summary) of everything we need to know about the program in the IDE.} +Summary picoSummarizer(loc l, start[Program] input, PicoSummarizerMode mode) { + Summary s = summary(l); + + // definitions of variables + rel[str, loc] defs = {<"", var.src> | /IdType var := input}; + + // uses of identifiers + rel[loc, str] uses = {"> | /Id id := input}; + + // documentation strings for identifier uses + rel[loc, str] docs = {"> | /IdType var := input}; + + // Provide errors (cheap to compute) both in analyze mode and in build mode. + s.messages += { is not defined", src, fixes=prepareNotDefinedFixes(src, defs))> + | <- uses, id notin defs<0>}; + + // "references" are links for loc to loc (from def to use) + s.references += (uses o defs)<1,0>; + + // "definitions" are also links from loc to loc (from use to def) + s.definitions += uses o defs; + + // "documentation" maps locations to strs + s.documentation += (uses o defs) o docs; + + // Provide warnings (expensive to compute) only in build mode + if (build() := mode) { + rel[loc, str] asgn = {"> | /Statement stmt := input, (Statement) ` := ` := stmt}; + s.messages += { is not assigned", src)> | <- defs, id notin asgn<1>}; + } + + return s; +} + +@synopsis{Looks up the declaration for any variable use using the / deep match} +set[loc] lookupDef(loc _, start[Program] input, Tree cursor) = + {d.src | /IdType d := input, cursor := d.id}; + +@synopsis{If a variable is not defined, we list a fix of fixes to replace it with a defined variable instead.} +list[CodeAction] prepareNotDefinedFixes(loc src, rel[str, loc] defs) + = [action(title="Change to >", edits=[changed(src.top, [replace(src, existing<0>)])]) | existing <- defs]; + +@synopsis{Finds a declaration that the cursor is on and proposes to remove it.} +list[CodeAction] picoActions([*Tree _, IdType x, *Tree _, start[Program] program]) + = [action(command=removeDecl(program, x, title="remove "))]; + +default list[CodeAction] picoActions(Focus _focus) = []; + +@synsopsis{Defines three example commands that can be triggered by the user (from a code lens, from a diagnostic, or just from the cursor position)} +data Command + = renameAtoB(start[Program] program) + | removeDecl(start[Program] program, IdType toBeRemoved) + ; + +@synopsis{Adds an example lense to the entire program.} +rel[loc,Command] picoLenses(start[Program] input) + = {}; + +@synopsis{Generates inlay hints that explain the type of each variable usage.} +list[InlayHint] picoHinter(start[Program] input) { + typeLookup = ( "" : "" | /(IdType)` : ` := input); + + return [ + hint(name.src, " : "]>", \type(), atEnd = true) + | /(Expression)`` := input + , "" in typeLookup + ]; +} + +@synopsis{Helper function to generate actual edit actions for the renameAtoB command} +list[DocumentEdit] getAtoBEdits(start[Program] input) + = [changed(input@\loc.top, [replace(id@\loc, "b") | /id:(Id) `a` := input])]; + +@synopsis{Command handler for the renameAtoB command} +value picoCommands(renameAtoB(start[Program] input)) { + applyDocumentsEdits(getAtoBEdits(input)); + return ("result": true); +} + +@synopsis{Command handler for the removeDecl command} +value picoCommands(removeDecl(start[Program] program, IdType toBeRemoved)) { + applyDocumentsEdits([changed(program@\loc.top, [replace(toBeRemoved@\loc, "")])]); + return ("result": true); +} + +@synopsis{The main function registers the Pico language with the IDE} +@description{ +Register the Pico language and the contributions that supply the IDE with features. + +((registerLanguage)) is called twice here: +1. first for fast and cheap contributions +2. asynchronously for the full monty that loads slower +} +@benefits{ +* You can run each contribution on an example in the terminal to test it first. +Any feedback (errors and exceptions) is faster and more clearly printed in the terminal. +} +void main() { + registerLanguage( + language( + pathConfig(), + "Pico", + {"pico", "pico-new"}, + "demo::lang::pico::LanguageServer", + "picoLanguageContributor" + ) + ); + registerLanguage( + language( + pathConfig(), + "Pico", + {"pico", "pico-new"}, + "demo::lang::pico::LanguageServer", + "picoLanguageContributorSlowSummary" + ) + ); +} From fb9a22ea9bc7dfe311c159b001ff9dd4ade17cd9 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Wed, 23 Oct 2024 14:52:02 +0200 Subject: [PATCH 56/57] fixed module names in Language meta data --- .../src/main/rascal/demo/lang/pico/OldStyleLanguageServer.rsc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/OldStyleLanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/OldStyleLanguageServer.rsc index cf15fd068..6d5091bb1 100644 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/OldStyleLanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/OldStyleLanguageServer.rsc @@ -178,7 +178,7 @@ void main() { pathConfig(), "Pico", {"pico", "pico-new"}, - "demo::lang::pico::LanguageServer", + "demo::lang::pico::OldStyleLanguageServer", "picoLanguageContributor" ) ); @@ -187,7 +187,7 @@ void main() { pathConfig(), "Pico", {"pico", "pico-new"}, - "demo::lang::pico::LanguageServer", + "demo::lang::pico::OldStyleLanguageServer", "picoLanguageContributorSlowSummary" ) ); From 4939d4b2684f0e98b14231267cadfcbef7556412 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Wed, 23 Oct 2024 15:50:50 +0200 Subject: [PATCH 57/57] fixed tutor links --- .../src/main/rascal/demo/lang/pico/OldStyleLanguageServer.rsc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/OldStyleLanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/OldStyleLanguageServer.rsc index 6d5091bb1..e9e3dbb5e 100644 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/OldStyleLanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/OldStyleLanguageServer.rsc @@ -27,8 +27,8 @@ POSSIBILITY OF SUCH DAMAGE. @synopsis{Demonstrating all of the LSP services for the demo language Pico.} @deprecated{This demo has been superseded by ((LanguageServer)) which avoids the use of deprecated API.} @description{ -This module is here to test the backward compatibility layer over the new ((LanguageServer)) API. -For learning how to build a new set of lanuage services, please go [here]((LanguageServer)). +This module is here to test the backward compatibility layer over the new ((util::LanguageServer)) API. +For learning how to build a new set of lanuage services, please go [here]((util::LanguageServer)). } module demo::lang::pico::OldStyleLanguageServer