5757import io .usethesource .vallang .IList ;
5858import io .usethesource .vallang .ISet ;
5959import io .usethesource .vallang .ISourceLocation ;
60+ import io .usethesource .vallang .ITuple ;
6061import io .usethesource .vallang .IValue ;
6162import io .usethesource .vallang .IValueFactory ;
6263import io .usethesource .vallang .exceptions .FactTypeUseException ;
@@ -88,6 +89,10 @@ public class InterpretedLanguageContributions implements ILanguageContributions
8889 private final CompletableFuture <@ Nullable IFunction > references ;
8990 private final CompletableFuture <@ Nullable IFunction > implementation ;
9091 private final CompletableFuture <@ Nullable IFunction > codeAction ;
92+ private final CompletableFuture <@ Nullable IFunction > prepareRename ;
93+ private final CompletableFuture <@ Nullable IFunction > rename ;
94+ private final CompletableFuture <@ Nullable IFunction > didRenameFiles ;
95+ private final CompletableFuture <@ Nullable IFunction > selectionRange ;
9196
9297 private final CompletableFuture <Boolean > hasAnalysis ;
9398 private final CompletableFuture <Boolean > hasBuild ;
@@ -100,6 +105,9 @@ public class InterpretedLanguageContributions implements ILanguageContributions
100105 private final CompletableFuture <Boolean > hasReferences ;
101106 private final CompletableFuture <Boolean > hasImplementation ;
102107 private final CompletableFuture <Boolean > hasCodeAction ;
108+ private final CompletableFuture <Boolean > hasRename ;
109+ private final CompletableFuture <Boolean > hasDidRenameFiles ;
110+ private final CompletableFuture <Boolean > hasSelectionRange ;
103111
104112 private final CompletableFuture <Boolean > specialCaseHighlighting ;
105113
@@ -142,6 +150,10 @@ public InterpretedLanguageContributions(LanguageParameter lang, IBaseTextDocumen
142150 this .references = getFunctionFor (contributions , LanguageContributions .REFERENCES );
143151 this .implementation = getFunctionFor (contributions , LanguageContributions .IMPLEMENTATION );
144152 this .codeAction = getFunctionFor (contributions , LanguageContributions .CODE_ACTION );
153+ this .prepareRename = getKeywordParamFunctionFor (contributions , LanguageContributions .RENAME , LanguageContributions .PREPARE_RENAME_SERVICE );
154+ this .rename = getFunctionFor (contributions , LanguageContributions .RENAME );
155+ this .didRenameFiles = getFunctionFor (contributions , LanguageContributions .DID_RENAME_FILES );
156+ this .selectionRange = getFunctionFor (contributions , LanguageContributions .SELECTION_RANGE );
145157
146158 // assign boolean properties once instead of wasting futures all the time
147159 this .hasAnalysis = nonNull (this .analysis );
@@ -155,6 +167,9 @@ public InterpretedLanguageContributions(LanguageParameter lang, IBaseTextDocumen
155167 this .hasReferences = nonNull (this .references );
156168 this .hasImplementation = nonNull (this .implementation );
157169 this .hasCodeAction = nonNull (this .codeAction );
170+ this .hasRename = nonNull (this .rename );
171+ this .hasDidRenameFiles = nonNull (this .didRenameFiles );
172+ this .hasSelectionRange = nonNull (this .selectionRange );
158173
159174 this .specialCaseHighlighting = getContributionParameter (contributions ,
160175 LanguageContributions .PARSING ,
@@ -256,19 +271,29 @@ private CompletableFuture<IConstructor> parseCommand(String command) {
256271 });
257272 }
258273
259- private static CompletableFuture <@ Nullable IFunction > getFunctionFor (CompletableFuture <ISet > contributions , String cons ) {
274+ private static CompletableFuture <@ Nullable IConstructor > getContribution (CompletableFuture <ISet > contributions , String cons ) {
260275 return contributions .thenApply (conts -> {
261276 for (IValue elem : conts ) {
262277 IConstructor contrib = (IConstructor ) elem ;
263278 if (cons .equals (contrib .getConstructorType ().getName ())) {
264- return ( IFunction ) contrib . get ( 0 ) ;
279+ return contrib ;
265280 }
266281 }
267282 logger .debug ("No {} defined" , cons );
268283 return null ;
269284 });
270285 }
271286
287+ private static CompletableFuture <@ Nullable IFunction > getFunctionFor (CompletableFuture <ISet > contributions , String cons ) {
288+ return getContribution (contributions , cons ).thenApply (contribution -> (IFunction ) contribution .get (0 ));
289+ }
290+
291+ private static CompletableFuture <@ Nullable IFunction > getKeywordParamFunctionFor (CompletableFuture <ISet > contributions , String cons , String kwParam ) {
292+ return getContribution (contributions , cons ).thenApply (contribution ->
293+ (IFunction ) contribution .asWithKeywordParameters ().getParameter (kwParam )
294+ );
295+ }
296+
272297 @ Override
273298 public String getName () {
274299 return name ;
@@ -310,6 +335,24 @@ public InterruptibleFuture<IList> inlayHint(@Nullable ITree input) {
310335 return execFunction (LanguageContributions .INLAY_HINT , inlayHint , VF .list (), input );
311336 }
312337
338+ @ Override
339+ public InterruptibleFuture <ISourceLocation > prepareRename (IList focus ) {
340+ debug (LanguageContributions .PREPARE_RENAME_SERVICE , focus .isEmpty () ? "" : focus .get (0 ));
341+ return execFunction (LanguageContributions .PREPARE_RENAME_SERVICE , prepareRename , URIUtil .unknownLocation (), focus );
342+ }
343+
344+ @ Override
345+ public InterruptibleFuture <ITuple > rename (IList focus , String newName ) {
346+ debug (LanguageContributions .RENAME_SERVICE , newName , focus .isEmpty () ? "" : focus .get (0 ));
347+ return execFunction (LanguageContributions .RENAME_SERVICE , rename , VF .tuple (VF .list (), VF .list ()), focus , VF .string (newName ));
348+ }
349+
350+ @ Override
351+ public InterruptibleFuture <ITuple > didRenameFiles (IList fileRenames ) {
352+ debug (LanguageContributions .DID_RENAME_FILES , fileRenames );
353+ return execFunction (LanguageContributions .DID_RENAME_FILES , didRenameFiles , VF .tuple (VF .list (), VF .list ()), fileRenames );
354+ }
355+
313356 @ Override
314357 public InterruptibleFuture <ISet > hover (IList focus ) {
315358 debug (LanguageContributions .HOVER , focus .length ());
@@ -340,6 +383,12 @@ public InterruptibleFuture<IList> codeAction(IList focus) {
340383 return execFunction (LanguageContributions .CODE_ACTION , codeAction , VF .list (), focus );
341384 }
342385
386+ @ Override
387+ public InterruptibleFuture <IList > selectionRange (IList focus ) {
388+ debug (LanguageContributions .SELECTION_RANGE , focus .length ());
389+ return execFunction (LanguageContributions .SELECTION_RANGE , selectionRange , VF .list (), focus );
390+ }
391+
343392 private void debug (String name , Object param ) {
344393 logger .debug ("{}({})" , name , param );
345394 }
@@ -378,6 +427,16 @@ public CompletableFuture<Boolean> hasInlayHint() {
378427 return hasInlayHint ;
379428 }
380429
430+ @ Override
431+ public CompletableFuture <Boolean > hasRename () {
432+ return hasRename ;
433+ }
434+
435+ @ Override
436+ public CompletableFuture <Boolean > hasDidRenameFiles () {
437+ return hasDidRenameFiles ;
438+ }
439+
381440 @ Override
382441 public CompletableFuture <Boolean > hasCodeLens () {
383442 return hasCodeLens ;
@@ -393,6 +452,11 @@ public CompletableFuture<Boolean> hasCodeAction() {
393452 return hasCodeAction ;
394453 }
395454
455+ @ Override
456+ public CompletableFuture <Boolean > hasSelectionRange () {
457+ return hasSelectionRange ;
458+ }
459+
396460 @ Override
397461 public CompletableFuture <Boolean > hasAnalysis () {
398462 return hasAnalysis ;
0 commit comments