Skip to content

Commit 8027996

Browse files
authored
Ignore ending $ when looking at end marker names (#22798)
## Fix scalameta/metals#7246 - Add a test for renaming local objects - Drop ending `$` marker when looking for end marker names
1 parent 4b09b13 commit 8027996

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ object EndMarker:
315315
def getPosition(df: NamedDefTree, pos: SourcePosition, sourceText: String)(
316316
implicit ct: Context
317317
): Option[SourcePosition] =
318-
val name = df.name.toString()
318+
val name = df.name.toString().stripSuffix("$")
319319
val endMarkerLine =
320320
sourceText.slice(df.span.start, df.span.end).split('\n').last
321321
val index = endMarkerLine.length() - name.length()

presentation-compiler/test/dotty/tools/pc/tests/edit/PcRenameSuite.scala

+11
Original file line numberDiff line numberDiff line change
@@ -534,3 +534,14 @@ class PcRenameSuite extends BasePcRenameSuite:
534534
|""".stripMargin,
535535
wrap = false
536536
)
537+
538+
@Test def `local-object-with-end-rename` =
539+
check(
540+
"""|def bar =
541+
| object <<fo@@o>>:
542+
| def aaa = ???
543+
| end <<foo>>
544+
| 1
545+
|""".stripMargin,
546+
wrap = false
547+
)

presentation-compiler/test/dotty/tools/pc/tests/tokens/SemanticTokensSuite.scala

+11-2
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite:
262262
| } = new:
263263
| def <<scalameta>>/*method,definition*/ = "4.0"
264264
| <<V>>/*variable,readonly*/.<<scalameta>>/*method*/
265-
|end StructuralTypes
265+
|end <<StructuralTypes>>/*class,definition*/
266266
|""".stripMargin
267267
)
268268

@@ -435,4 +435,13 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite:
435435
| <<usage>>/*method*/[<<Option>>/*class,abstract*/[<<Int>>/*class,abstract*/]](<<_>>/*parameter,readonly*/.<<typeArg>>/*method*/[<<Some>>/*class*/[<<Int>>/*class,abstract*/]].<<value>>/*variable,readonly*/.<<inferredTypeArg>>/*method*/[<<String>>/*type*/]("str"))
436436
|}
437437
|""".stripMargin
438-
)
438+
)
439+
440+
@Test def `local-object-with-end-i7246` =
441+
check(
442+
"""|def <<bar>>/*method,definition*/ =
443+
| object <<foo>>/*class*/:
444+
| def <<aaa>>/*method,definition*/ = <<???>>/*method*/
445+
| end <<foo>>/*class,definition*/
446+
|""".stripMargin
447+
)

0 commit comments

Comments
 (0)