Skip to content

Commit 483a1ff

Browse files
committed
prepareRename as optional rename argument.
1 parent 0c4509c commit 483a1ff

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ set[LanguageService] picoLanguageServer() = {
5353
inlayHint(picoInlayHintService),
5454
definition(picoDefinitionService),
5555
codeAction(picoCodeActionService),
56-
prepareRename(picoRenamePreparingService),
57-
rename(picoRenamingService)
56+
rename(picoRenamingService, prepareRenameService = picoRenamePreparingService)
5857
};
5958

6059
@synopsis{This set of contributions runs slower but provides more detail.}

rascal-lsp/src/main/rascal/util/LanguageServer.rsc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import analysis::diff::edits::TextEdits;
4444
import IO;
4545
import ParseTree;
4646
import Message;
47+
import Exception;
4748

4849
@synopsis{Definition of a language server by its meta-data.}
4950
@description{
@@ -207,8 +208,8 @@ hover documentation, definition with uses, references to declarations, implement
207208
* 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.
208209
* The ((execution)) service executes the commands registered by ((lenses)) and ((inlayHinter))s.
209210
* 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.
210-
* The ((prepareRename)) service discovers places in the editor where a ((util::LanguageServer::rename)) is possible.
211211
* The ((util::LanguageServer::rename)) service renames an identifier by collecting the edits required to rename all occurrences of that identifier. It might fail and report why in diagnostics.
212+
* The optional ((prepareRename)) service argument discovers places in the editor where a ((util::LanguageServer::rename)) is possible. If renameing the location is not supported, it should throw an exception.
212213
* The ((didRenameFiles)) service collects ((DocumentEdit))s corresponding to renamed files (e.g. to rename a class when the class file was renamed). The IDE applies the edits after moving the files. It might fail and report why in diagnostics.
213214

214215
Many services receive a ((Focus)) parameter. The focus lists the syntactical constructs under the current cursor, from the current
@@ -271,11 +272,14 @@ data LanguageService
271272
| references (set[loc] (Focus _focus) referencesService)
272273
| implementation(set[loc] (Focus _focus) implementationService)
273274
| codeAction (list[CodeAction] (Focus _focus) codeActionService)
274-
| prepareRename (loc (Focus _focus) prepareRenameService)
275-
| rename (tuple[list[DocumentEdit], set[Message]] (Focus _focus, str newName) renameService)
275+
| rename (tuple[list[DocumentEdit], set[Message]] (Focus _focus, str newName) renameService
276+
, loc (Focus _focus) prepareRenameService = defaultPrepareRenameService)
276277
| didRenameFiles(tuple[list[DocumentEdit], set[Message]] (lrel[loc old, loc new] fileRenames) didRenameFilesService)
277278
;
278279

280+
loc defaultPrepareRenameService(Focus _:[Tree tr, *_]) = tr.src when tr.src?;
281+
default loc defaultPrepareRenameService(Focus focus) { throw IllegalArgument(focus, "Element under cursor does not have source location"); }
282+
279283
@deprecated{Backward compatible with ((parsing)).}
280284
@synopsis{Construct a `parsing` ((LanguageService))}
281285
LanguageService parser(Parser parser) = parsing(parser);

0 commit comments

Comments
 (0)