Docs chevron_right How It Works

How It Works

Deslop parses source code with tree-sitter, finds candidate copies, checks their content, and groups the surviving findings. The CLI, editor and MCP tools share the same Rust engine.

This guide covers 0.35.0.

How Deslop finds copied and similar code · 1:00 · English narration and captions
Read the English transcript

Find a copy worth reviewing

Deslop looks through the project and brings possible copies into the sidebar. I open one of those findings here. Instead of taking a number on trust, I can follow its file links and inspect the exact code that was reported.

See past different names

These two files use different names, but the calculation is the same. I open the comparison to see that directly. Renaming a class or a variable has not made the repeated work disappear, and the side-by-side view makes that easy to check.

Read the surrounding code

I visit each original file and look beyond the highlighted lines. The surrounding code tells me how the calculation is used. This is where I decide whether one shared helper would make sense, or whether the two copies should stay separate.

Watch the result update

I make an edit in the source file and save it. Deslop checks the changed project and refreshes the finding in the editor. I can compare again straight away, which keeps the review connected to the code I am actually working on.

Find candidate copies

Deslop supports C, C#, Rust, Python, Dart, JavaScript, TypeScript/TSX, PHP, F#, Go and Osprey. It respects .gitignore and excludes dependency trees and build artifacts by default. See Configuration for exclusions.

For Osprey's .osp syntax, Python-flavor opt-in and the native ML integration status, see Osprey support.

The engine normalizes syntax trees so changes to names, literals and formatting do not hide candidates. It fingerprints both subtrees and consecutive statement runs, including copies inside a single file. Structural overlap and MinHash similarity help recover edited copies whose enclosing methods differ.

Normalization alone cannot establish a clone. The engine also checks source content, consistent renaming and the operations being performed. Changing a collaborator's name differs from changing which operation it calls.

Read the categories

Report label Meaning
Identical code Source text matches apart from permitted whitespace differences. Corresponds to Type I; Deslop's identity rule is stricter than the research definition, which also permits comment changes.
Nearly identical code Renamed or parameterized copies, or copies with small edits: Type II and close Type III.
Similar code Substantial copied work with larger statement or control-flow edits: Type III.
Same behavior, different code Optional embedding-based candidates for Type IV. Review both implementations; this is not proof that they are interchangeable.
Same shape, different content Matching layout with negligible shared content. Informational, not a clone.

Shape-only findings contribute nothing to clone counts, duplicated mass or duplication percentages. They appear after clones and have no diagnostic by default. A group label describes its established member relations; a chain of matches does not prove every possible pair matches.

Compare two occurrences

Similarity evidence belongs to two explicit source ranges. A cluster carries its kind, occurrences, mass and rank; it does not carry one pair's similarity score as a group-wide confidence value.

In VS Code, use Compare To Canonical, or Select for Compare followed by Compare with Selected. The CLI also supports --compare. The engine recomputes the verdict for the chosen endpoints.

Rank by duplicated mass

mass = canonical_node_count × max(visible_members − 1, 0)

Mass measures the size of a copied syntax tree multiplied by its additional visible copies. Clones are sorted by mass descending, with stable IDs breaking ties. Shape-only findings have zero duplicated mass and no clone rank.

Mass is neither confidence nor a percentage. The duplication percentage counts covered source lines, with overlapping ranges counted once.

Optional embeddings

Embeddings are off by default. --embeddings auto uses the configured provider if available; --embeddings required fails if it cannot be reached. The Ollama provider defaults to nomic-embed-text, with a configurable model and endpoint. Embedding similarity adds candidates; it does not prove equivalent behaviour or a safe extraction.

Keep the report current

Cached parse and signature work can be reused for unchanged files. A live session watches edits, updates the analysis and broadcasts the fresh report to the editor. MCP queries consult that session; the CLI performs a separate scan for CI or a one-off review.

JSON, text and HTML expose the same report. See Report output, Accuracy Transparency and Research Background for the contracts and evidence.