Skip to content

Commit 449be71

Browse files
committed
feat: add TextMate document partitioner
1 parent f85de1e commit 449be71

File tree

13 files changed

+1567
-54
lines changed

13 files changed

+1567
-54
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
```

org.eclipse.tm4e.ui.tests/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<extension
1616
point="org.eclipse.core.contenttype.contentTypes">
1717
<content-type
18+
base-type="org.eclipse.core.runtime.text"
1819
file-extensions="ts"
1920
id="org.eclipse.tm4e.ui.tests.testContentType"
2021
name="Test Content Type for TM4E (typescipt)"

0 commit comments

Comments
 (0)