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,9 @@ 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 ;
9195 private final CompletableFuture <@ Nullable IFunction > selectionRange ;
9296
9397 private final CompletableFuture <Boolean > hasAnalysis ;
@@ -101,6 +105,8 @@ public class InterpretedLanguageContributions implements ILanguageContributions
101105 private final CompletableFuture <Boolean > hasReferences ;
102106 private final CompletableFuture <Boolean > hasImplementation ;
103107 private final CompletableFuture <Boolean > hasCodeAction ;
108+ private final CompletableFuture <Boolean > hasRename ;
109+ private final CompletableFuture <Boolean > hasDidRenameFiles ;
104110 private final CompletableFuture <Boolean > hasSelectionRange ;
105111
106112 private final CompletableFuture <Boolean > specialCaseHighlighting ;
@@ -144,6 +150,9 @@ public InterpretedLanguageContributions(LanguageParameter lang, IBaseTextDocumen
144150 this .references = getFunctionFor (contributions , LanguageContributions .REFERENCES );
145151 this .implementation = getFunctionFor (contributions , LanguageContributions .IMPLEMENTATION );
146152 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 );
147156 this .selectionRange = getFunctionFor (contributions , LanguageContributions .SELECTION_RANGE );
148157
149158 // assign boolean properties once instead of wasting futures all the time
@@ -158,6 +167,8 @@ public InterpretedLanguageContributions(LanguageParameter lang, IBaseTextDocumen
158167 this .hasReferences = nonNull (this .references );
159168 this .hasImplementation = nonNull (this .implementation );
160169 this .hasCodeAction = nonNull (this .codeAction );
170+ this .hasRename = nonNull (this .rename );
171+ this .hasDidRenameFiles = nonNull (this .didRenameFiles );
161172 this .hasSelectionRange = nonNull (this .selectionRange );
162173
163174 this .specialCaseHighlighting = getContributionParameter (contributions ,
@@ -260,19 +271,29 @@ private CompletableFuture<IConstructor> parseCommand(String command) {
260271 });
261272 }
262273
263- private static CompletableFuture <@ Nullable IFunction > getFunctionFor (CompletableFuture <ISet > contributions , String cons ) {
274+ private static CompletableFuture <@ Nullable IConstructor > getContribution (CompletableFuture <ISet > contributions , String cons ) {
264275 return contributions .thenApply (conts -> {
265276 for (IValue elem : conts ) {
266277 IConstructor contrib = (IConstructor ) elem ;
267278 if (cons .equals (contrib .getConstructorType ().getName ())) {
268- return ( IFunction ) contrib . get ( 0 ) ;
279+ return contrib ;
269280 }
270281 }
271282 logger .debug ("No {} defined" , cons );
272283 return null ;
273284 });
274285 }
275286
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+
276297 @ Override
277298 public String getName () {
278299 return name ;
@@ -314,6 +335,24 @@ public InterruptibleFuture<IList> inlayHint(@Nullable ITree input) {
314335 return execFunction (LanguageContributions .INLAY_HINT , inlayHint , VF .list (), input );
315336 }
316337
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+
317356 @ Override
318357 public InterruptibleFuture <ISet > hover (IList focus ) {
319358 debug (LanguageContributions .HOVER , focus .length ());
@@ -388,6 +427,16 @@ public CompletableFuture<Boolean> hasInlayHint() {
388427 return hasInlayHint ;
389428 }
390429
430+ @ Override
431+ public CompletableFuture <Boolean > hasRename () {
432+ return hasRename ;
433+ }
434+
435+ @ Override
436+ public CompletableFuture <Boolean > hasDidRenameFiles () {
437+ return hasDidRenameFiles ;
438+ }
439+
391440 @ Override
392441 public CompletableFuture <Boolean > hasCodeLens () {
393442 return hasCodeLens ;
0 commit comments