Skip to content

Instantly share code, notes, and snippets.

@nbhusare
Last active September 9, 2016 12:23
Show Gist options
  • Save nbhusare/13ef1fd7c609e1747077970c1e8c2277 to your computer and use it in GitHub Desktop.
Save nbhusare/13ef1fd7c609e1747077970c1e8c2277 to your computer and use it in GitHub Desktop.
public class MyDslDocumentProvider extends XtextDocumentProvider {
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
throws CoreException {
try {
final IHandlerService service = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
service.executeCommand("org.eclipse.xtext.ui.FormatAction", null);
} catch (Exception e) {
e.printStackTrace();
}
super.doSaveDocument(monitor, element, document, overwrite);
}
}
// Add binding in the DSL UI Module
def Class<? extends XtextDocumentProvider> bindXtextDocumentProvider() { return MyDslDocumentProvider }
// Courtesy: http://stackoverflow.com/questions/31116928/auto-pretty-formatting-in-xtext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment