如何使用 Xtext 格式化程序在同一文档中定义不同的缩进级别
How to define different indentation levels in the same document with Xtext formatter
是否可以使用 Xtext 格式对文档进行如下格式设置?如您所见,Test 子项缩进了 4 个空格,而 External 子项仅缩进了 2 个空格。我正在使用 Xtext 2.12.0.
Test my_prog {
Device = "my_device";
Param = 0;
}
External {
Path = "my_path";
File = "my_file";
}
您可以尝试使用自定义替换器,但不知道这是否适用于嵌套块
def dispatch void format(External model, extension IFormattableDocument document) {
model.regionFor.keyword("}").prepend[newLine]
for (l : model.ids) {
val region = l.regionFor.feature(MyDslPackage.Literals.IDX__NAME)
region.prepend[newLine]
val r = new AbstractTextReplacer(document, region) {
override createReplacements(ITextReplacerContext it) {
val offset = region.offset
it.addReplacement(region.textRegionAccess.rewriter.createReplacement(offset, 0, " "))
it
}
}
addReplacer(r)
}
}
是否可以使用 Xtext 格式对文档进行如下格式设置?如您所见,Test 子项缩进了 4 个空格,而 External 子项仅缩进了 2 个空格。我正在使用 Xtext 2.12.0.
Test my_prog {
Device = "my_device";
Param = 0;
}
External {
Path = "my_path";
File = "my_file";
}
您可以尝试使用自定义替换器,但不知道这是否适用于嵌套块
def dispatch void format(External model, extension IFormattableDocument document) {
model.regionFor.keyword("}").prepend[newLine]
for (l : model.ids) {
val region = l.regionFor.feature(MyDslPackage.Literals.IDX__NAME)
region.prepend[newLine]
val r = new AbstractTextReplacer(document, region) {
override createReplacements(ITextReplacerContext it) {
val offset = region.offset
it.addReplacement(region.textRegionAccess.rewriter.createReplacement(offset, 0, " "))
it
}
}
addReplacer(r)
}
}