|
| 1 | +# TM Partitioner (IDocumentPartitioner) |
| 2 | + |
| 3 | +- Partitioning ID: `tm4e.partitioning` |
| 4 | +- Partition type naming: `tm4e:<root-scope>` (e.g., `tm4e:text.html.basic`, `tm4e:source.js`, `tm4e:source.css`). |
| 5 | +- 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. |
| 6 | + |
| 7 | +How to consume from code |
| 8 | + |
| 9 | +- Get partitions from the TM4E partitioner via `IDocumentExtension3`: |
| 10 | + - `var ext3 = (IDocumentExtension3) doc;` |
| 11 | + - `var part = ext3.getDocumentPartitioner("tm4e.partitioning");` |
| 12 | + - `ITypedRegion[] regions = part.computePartitioning(offset, length);` |
| 13 | + |
| 14 | +Example (content assist/feature code): |
| 15 | + |
| 16 | +```java |
| 17 | +IDocument doc = viewer.getDocument(); |
| 18 | +if (doc instanceof IDocumentExtension3 ext3) { |
| 19 | + var tmPart = ext3.getDocumentPartitioner("tm4e.partitioning"); |
| 20 | + if (tmPart != null) { |
| 21 | + ITypedRegion r = tmPart.getPartition(caretOffset); |
| 22 | + switch (r.getType()) { |
| 23 | + case "tm4e:source.js": |
| 24 | + // offer JavaScript proposals |
| 25 | + break; |
| 26 | + case "tm4e:source.css": |
| 27 | + // offer CSS proposals |
| 28 | + break; |
| 29 | + default: |
| 30 | + // base language behavior |
| 31 | + } |
| 32 | + } |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +Generic Editor contributions |
| 37 | + |
| 38 | +- 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 `r.getType()`. |
| 39 | +- You do not need to install a partitioner yourself; `org.eclipse.tm4e.ui` installs it automatically when a grammar exists. |
| 40 | + |
| 41 | +Example plugin.xml (content assist): |
| 42 | + |
| 43 | +```xml |
| 44 | +<extension point="org.eclipse.ui.genericeditor.contentAssistProcessors"> |
| 45 | + <contentAssistProcessor |
| 46 | + class="com.example.MyTM4EAwareAssist" |
| 47 | + contentType="org.eclipse.core.runtime.text" |
| 48 | + targetId="org.eclipse.ui.genericeditor.GenericEditor"/> |
| 49 | + <!-- partitionType here refers to the editor's default partitioning; |
| 50 | + to use TM4E partitions, query tm4e.partitioning from your code. --> |
| 51 | + </extension> |
| 52 | +``` |
0 commit comments