> ## Documentation Index
> Fetch the complete documentation index at: https://differens.ossl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Scala

> Semantic diffing for Scala

## Scala extractor

The Scala extractor maps tree-sitter Scala CST nodes to canonical concepts. Class, object, and definition names come from the standard `name` field; `val` and `var` names come from the pattern field.

### Detected concepts

| tree-sitter node type | Canonical concept |
| - | - |
| `class_definition` | Class |
| `trait_definition` | Trait |
| `object_definition` | SingletonObject |
| `function_definition` | Function |
| `val_definition` | Constant |
| `var_definition` | Variable |
| `package_clause` | Namespace |
| `import_declaration` | Import |
| `if_expression` | IfBlock |
| `match_expression` | MatchBlock |
| `string` | string\_literal |
| `boolean_literal` | boolean\_literal |

### Example

Renaming a method:

```scala theme={null}
// old.scala
class Counter { def total(n: Int): Int = n + 1 }
```

```scala theme={null}
// new.scala
class Counter { def sum(n: Int): Int = n + 1 }
```

Running `differens old.scala new.scala`:

```
~ renamed function `total` to `sum` in class `Counter`
```

### Known limitations

* Implicits and given clauses are structure: adding one reports as an insert on the declaration.
* `var` definitions in some template contexts produce an ERROR node in the grammar; they parse cleanly in class and object bodies.
