You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Before a grammar is known, the synthetic base type `tm4e:base` is used.
10
+
- After activation with a grammar, the base becomes `tm4e:<root-scope>` (for example, HTML base `tm4e:text.html`).
11
+
- Installed automatically by `org.eclipse.tm4e.ui` for any document that resolves a TextMate grammar. It is added as a secondary partitioning and does not replace an editor's default partitioner.
12
+
13
+
## Partition Semantics
14
+
15
+
-`computePartitioning(offset, length)` returns regions that cover the entire requested range contiguously. Gaps between known embedded regions are filled with the current base type.
16
+
-`getPartition(offset)` clamps the offset to the valid range `[0, docLength-1]`. Negative offsets resolve to the first region; EOF resolves to the last region.
17
+
- Regions implement `ITMPartitionRegion` (extends `ITypedRegion`) and carry language metadata:
18
+
-`getGrammarScope()` returns the effective grammar scope such as `source.js` or `text.html`.
19
+
20
+
## How to Consume from Code
21
+
22
+
Get partitions from the TM4E partitioner via `IDocumentExtension3`:
23
+
```java
24
+
var ext3 = (IDocumentExtension3) doc;
25
+
var partitioner = ext3.getDocumentPartitioner(org.eclipse.tm4e.ui.text.TMPartitions.TM_PARTITIONING/* or "tm4e.partitioning" */);
26
+
ITypedRegion[] regions = partitioner.computePartitioning(offset, length);
if (ext3.getDocumentPartitioner(TMPartitions.TM_PARTITIONING) instanceofITMPartitioner tmPartitioner) {
41
+
ITypedRegion r = tmPartitioner.getPartition(caretOffset);
42
+
// Prefer matching by normalized language scope (handles embedded variants)
43
+
switch(r.getGrammarScope()) {
44
+
case"source.js":// offer JavaScript proposals
45
+
case"source.css":// offer CSS proposals
46
+
}
47
+
}
48
+
}
49
+
```
50
+
51
+
## Matching by Scope (Recommended)
52
+
53
+
- Partition type strings are base-root only (for example, `tm4e:source.js`, `tm4e:text.html`). If you need to distinguish embedded variants (for example, JavaScript-in-Markdown), use `ITMPartitionRegion.getGrammarScope()` which carries the normalized full scope (such as `source.js`).
54
+
- For most feature switches, detect the language via the normalized scope name from `getGrammarScope()` as shown in the example. This is stable for families like `source.css`, `source.js`, or `text.html`.
55
+
56
+
## Mapping to Content Types (Alternative)
57
+
58
+
- If your feature keys off `IContentType`, translate the partition at the caret offset:
- Register your feature with the Generic Editor as usual (e.g., content assist, hovers). Inside your implementation, use the code above to query TM4E’s partitioning and branch behavior based on the normalized scope (recommended) or the partition type.
67
+
- You do not need to install a partitioner yourself; `org.eclipse.tm4e.ui` installs it automatically when a grammar exists.
0 commit comments