@@ -50,6 +50,7 @@ import org.eclipse.lsp4j.VersionedTextDocumentIdentifier
50
50
import org .eclipse .lsp4j .WorkspaceEdit
51
51
import org .eclipse .lsp4j .jsonrpc .messages .{Either => LSPEither }
52
52
import org .eclipse .lsp4j .{Range => LSPRange }
53
+ import scala .meta .internal .pc .PcSymbolInformation
53
54
54
55
final class RenameProvider (
55
56
referenceProvider : ReferenceProvider ,
@@ -117,6 +118,7 @@ final class RenameProvider(
117
118
token : CancelToken ,
118
119
): Future [WorkspaceEdit ] = {
119
120
val source = params.getTextDocument.getUri.toAbsolutePath
121
+ // val scalaVersion =
120
122
val localRename = compilers
121
123
.rename(params, token)
122
124
.map(_.asScala.toList)
@@ -164,7 +166,8 @@ final class RenameProvider(
164
166
if (suggestedName.isBackticked)
165
167
suggestedName.stripBackticks
166
168
else suggestedName
167
- val newName = Identifier .backtickWrap(withoutBackticks)
169
+ val newName =
170
+ KeywordWrapper .Scala3 ().backtickWrap(withoutBackticks)
168
171
169
172
def isNotRenamedSymbol (
170
173
textDocument : TextDocument ,
@@ -179,15 +182,6 @@ final class RenameProvider(
179
182
foundName.contains(realName)
180
183
}
181
184
182
- def shouldCheckImplementation (
183
- symbol : String ,
184
- path : AbsolutePath ,
185
- textDocument : TextDocument ,
186
- ) =
187
- ! symbol.desc.isType && ! (symbol.isLocal && symbolHierarchyOps
188
- .defaultSymbolSearch(path, textDocument)(symbol)
189
- .exists(info => info.isTrait || info.isClass))
190
-
191
185
val allReferences =
192
186
for {
193
187
(occurence, semanticDb) <- symbolOccurrence.toIterable
@@ -235,13 +229,14 @@ final class RenameProvider(
235
229
source,
236
230
newName,
237
231
)
232
+ shouldCheckImplementationFut = shouldCheckImplementation(
233
+ occurence.symbol,
234
+ source,
235
+ semanticDb,
236
+ )
238
237
implReferences = implementations(
239
238
txtParams,
240
- shouldCheckImplementation(
241
- occurence.symbol,
242
- source,
243
- semanticDb,
244
- ),
239
+ shouldCheckImplementationFut,
245
240
newName,
246
241
)
247
242
} yield Future
@@ -327,6 +322,32 @@ final class RenameProvider(
327
322
Future .sequence(all.map(waiting => waiting())).ignoreValue
328
323
}
329
324
325
+ private def shouldCheckImplementation (
326
+ symbol : String ,
327
+ path : AbsolutePath ,
328
+ textDocument : TextDocument ,
329
+ ): Future [Boolean ] = {
330
+ val notLocalAndType = ! symbol.desc.isType && ! symbol.isLocal
331
+
332
+ if (notLocalAndType) Future .successful(true )
333
+ else if (! symbol.isLocal) Future .successful(false )
334
+ else
335
+ symbolHierarchyOps
336
+ .defaultSymbolSearch(path, textDocument)(symbol)
337
+ .match {
338
+ case Some (info) =>
339
+ Future .successful(info.isTrait || info.isClass)
340
+ case None =>
341
+ compilers.info(path, symbol).map {
342
+ case None => false
343
+ case Some (value) =>
344
+ value.kind.getValue() == 13 ||
345
+ value.kind.getValue() == 14
346
+ }
347
+
348
+ }
349
+ }
350
+
330
351
/**
331
352
* In case of import renames, we can only rename the symbol in file.
332
353
* Global rename will not return any results, so this method will be used as
@@ -466,31 +487,32 @@ final class RenameProvider(
466
487
467
488
private def implementations (
468
489
textParams : TextDocumentPositionParams ,
469
- shouldCheckImplementation : Boolean ,
490
+ shouldCheckImplementationFut : Future [ Boolean ] ,
470
491
newName : String ,
471
- ): Future [Seq [Location ]] = {
472
- if (shouldCheckImplementation) {
473
- for {
474
- implLocs <- implementationProvider.implementations(textParams)
475
- result <- {
476
- val result = for {
477
- implLoc <- implLocs
478
- locParams = toReferenceParams(implLoc, includeDeclaration = true )
479
- } yield {
480
- referenceProvider
481
- .references(
482
- locParams,
483
- findRealRange = AdjustRange (findRealRange(newName)),
484
- includeSynthetic,
485
- )
486
- .map(_.flatMap(_.locations))
492
+ ): Future [Seq [Location ]] = shouldCheckImplementationFut.flatMap {
493
+ shouldCheckImplementation =>
494
+ if (shouldCheckImplementation) {
495
+ for {
496
+ implLocs <- implementationProvider.implementations(textParams)
497
+ result <- {
498
+ val result = for {
499
+ implLoc <- implLocs
500
+ locParams = toReferenceParams(implLoc, includeDeclaration = true )
501
+ } yield {
502
+ referenceProvider
503
+ .references(
504
+ locParams,
505
+ findRealRange = AdjustRange (findRealRange(newName)),
506
+ includeSynthetic,
507
+ )
508
+ .map(_.flatMap(_.locations))
509
+ }
510
+ Future .sequence(result)
487
511
}
488
- Future .sequence(result)
489
- }
490
- } yield result.flatten
491
- } else {
492
- Future .successful(Nil )
493
- }
512
+ } yield result.flatten
513
+ } else {
514
+ Future .successful(Nil )
515
+ }
494
516
}
495
517
496
518
private def canRenameSymbol (
0 commit comments