5959import  io .usethesource .vallang .IList ;
6060import  io .usethesource .vallang .ISet ;
6161import  io .usethesource .vallang .ISourceLocation ;
62+ import  io .usethesource .vallang .ITuple ;
6263import  io .usethesource .vallang .IValue ;
6364import  io .usethesource .vallang .IValueFactory ;
6465import  io .usethesource .vallang .exceptions .FactTypeUseException ;
@@ -90,6 +91,9 @@ public class InterpretedLanguageContributions implements ILanguageContributions
9091    private  final  CompletableFuture <@ Nullable  IFunction > references ;
9192    private  final  CompletableFuture <@ Nullable  IFunction > implementation ;
9293    private  final  CompletableFuture <@ Nullable  IFunction > codeAction ;
94+     private  final  CompletableFuture <@ Nullable  IFunction > prepareRename ;
95+     private  final  CompletableFuture <@ Nullable  IFunction > rename ;
96+     private  final  CompletableFuture <@ Nullable  IFunction > didRenameFiles ;
9397    private  final  CompletableFuture <@ Nullable  IFunction > selectionRange ;
9498    private  final  CompletableFuture <@ Nullable  IFunction > formatting ;
9599
@@ -104,6 +108,8 @@ public class InterpretedLanguageContributions implements ILanguageContributions
104108    private  final  CompletableFuture <Boolean > hasReferences ;
105109    private  final  CompletableFuture <Boolean > hasImplementation ;
106110    private  final  CompletableFuture <Boolean > hasCodeAction ;
111+     private  final  CompletableFuture <Boolean > hasRename ;
112+     private  final  CompletableFuture <Boolean > hasDidRenameFiles ;
107113    private  final  CompletableFuture <Boolean > hasSelectionRange ;
108114    private  final  CompletableFuture <Boolean > hasFormatting ;
109115
@@ -148,6 +154,9 @@ public InterpretedLanguageContributions(LanguageParameter lang, IBaseTextDocumen
148154            this .references  = getFunctionFor (contributions , LanguageContributions .REFERENCES );
149155            this .implementation  = getFunctionFor (contributions , LanguageContributions .IMPLEMENTATION );
150156            this .codeAction  = getFunctionFor (contributions , LanguageContributions .CODE_ACTION );
157+             this .prepareRename  = getKeywordParamFunctionFor (contributions , LanguageContributions .RENAME , LanguageContributions .PREPARE_RENAME_SERVICE );
158+             this .rename  = getFunctionFor (contributions , LanguageContributions .RENAME );
159+             this .didRenameFiles  = getFunctionFor (contributions , LanguageContributions .DID_RENAME_FILES );
151160            this .selectionRange  = getFunctionFor (contributions , LanguageContributions .SELECTION_RANGE );
152161            this .formatting  = getFunctionFor (contributions , LanguageContributions .FORMATTING );
153162
@@ -163,6 +172,8 @@ public InterpretedLanguageContributions(LanguageParameter lang, IBaseTextDocumen
163172            this .hasReferences  = nonNull (this .references );
164173            this .hasImplementation  = nonNull (this .implementation );
165174            this .hasCodeAction  = nonNull (this .codeAction );
175+             this .hasRename  = nonNull (this .rename );
176+             this .hasDidRenameFiles  = nonNull (this .didRenameFiles );
166177            this .hasSelectionRange  = nonNull (this .selectionRange );
167178            this .hasFormatting  = nonNull (this .formatting );
168179
@@ -266,19 +277,29 @@ private CompletableFuture<IConstructor> parseCommand(String command) {
266277        });
267278    }
268279
269-     private  static  CompletableFuture <@ Nullable  IFunction >  getFunctionFor (CompletableFuture <ISet > contributions , String  cons ) {
280+     private  static  CompletableFuture <@ Nullable  IConstructor >  getContribution (CompletableFuture <ISet > contributions , String  cons ) {
270281        return  contributions .thenApply (conts  -> {
271282            for  (IValue  elem  : conts ) {
272283                IConstructor  contrib  = (IConstructor ) elem ;
273284                if  (cons .equals (contrib .getConstructorType ().getName ())) {
274-                     return  ( IFunction )  contrib . get ( 0 ) ;
285+                     return  contrib ;
275286                }
276287            }
277288            logger .debug ("No {} defined" , cons );
278289            return  null ;
279290        });
280291    }
281292
293+     private  static  CompletableFuture <@ Nullable  IFunction > getFunctionFor (CompletableFuture <ISet > contributions , String  cons ) {
294+         return  getContribution (contributions , cons ).thenApply (contribution  -> (IFunction ) contribution .get (0 ));
295+     }
296+ 
297+     private  static  CompletableFuture <@ Nullable  IFunction > getKeywordParamFunctionFor (CompletableFuture <ISet > contributions , String  cons , String  kwParam ) {
298+         return  getContribution (contributions , cons ).thenApply (contribution  ->
299+             (IFunction ) contribution .asWithKeywordParameters ().getParameter (kwParam )
300+         );
301+     }
302+ 
282303    @ Override 
283304    public  String  getName () {
284305        return  name ;
@@ -320,6 +341,24 @@ public InterruptibleFuture<IList> inlayHint(@Nullable ITree input) {
320341        return  execFunction (LanguageContributions .INLAY_HINT , inlayHint , VF .list (), input );
321342    }
322343
344+     @ Override 
345+     public  InterruptibleFuture <ISourceLocation > prepareRename (IList  focus ) {
346+         debug (LanguageContributions .PREPARE_RENAME_SERVICE , focus .isEmpty () ? ""  : focus .get (0 ));
347+         return  execFunction (LanguageContributions .PREPARE_RENAME_SERVICE , prepareRename , URIUtil .unknownLocation (), focus );
348+     }
349+ 
350+     @ Override 
351+     public  InterruptibleFuture <ITuple > rename (IList  focus , String  newName ) {
352+         debug (LanguageContributions .RENAME_SERVICE , newName , focus .isEmpty () ? ""  : focus .get (0 ));
353+         return  execFunction (LanguageContributions .RENAME_SERVICE , rename , VF .tuple (VF .list (), VF .list ()), focus , VF .string (newName ));
354+     }
355+ 
356+     @ Override 
357+     public  InterruptibleFuture <ITuple > didRenameFiles (IList  fileRenames ) {
358+         debug (LanguageContributions .DID_RENAME_FILES , fileRenames );
359+         return  execFunction (LanguageContributions .DID_RENAME_FILES , didRenameFiles , VF .tuple (VF .list (), VF .list ()), fileRenames );
360+     }
361+ 
323362    @ Override 
324363    public  InterruptibleFuture <ISet > hover (IList  focus ) {
325364        debug (LanguageContributions .HOVER , focus .length ());
@@ -400,6 +439,16 @@ public CompletableFuture<Boolean> hasInlayHint() {
400439        return  hasInlayHint ;
401440    }
402441
442+     @ Override 
443+     public  CompletableFuture <Boolean > hasRename () {
444+         return  hasRename ;
445+     }
446+ 
447+     @ Override 
448+     public  CompletableFuture <Boolean > hasDidRenameFiles () {
449+         return  hasDidRenameFiles ;
450+     }
451+ 
403452    @ Override 
404453    public  CompletableFuture <Boolean > hasCodeLens () {
405454        return  hasCodeLens ;
0 commit comments