Skip to content

Commit

Permalink
Add IFormatOnSave service
Browse files Browse the repository at this point in the history
  • Loading branch information
ghentschke committed Aug 30, 2023
1 parent a9adfdf commit 3d2da5a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bundles/org.eclipse.cdt.lsp/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ Require-Bundle: org.eclipse.ui,
Bundle-RequiredExecutionEnvironment: JavaSE-17
Automatic-Module-Name: org.eclipse.cdt.lsp
Bundle-ActivationPolicy: lazy
Service-Component: OSGI-INF/org.eclipse.cdt.lsp.internal.InitialFileManager.xml
Service-Component: OSGI-INF/org.eclipse.cdt.lsp.editor.LspEditorFormatOnSave.xml,
OSGI-INF/org.eclipse.cdt.lsp.internal.InitialFileManager.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.cdt.lsp.editor.LspEditorFormatOnSave">
<property name="service.ranking" type="Integer" value="10"/>
<service>
<provide interface="org.eclipse.lsp4e.IFormatOnSave"/>
</service>
<implementation class="org.eclipse.cdt.lsp.editor.LspEditorFormatOnSave"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.eclipse.cdt.lsp.editor;

import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
import org.eclipse.lsp4e.IFormatOnSave;
import org.osgi.service.component.annotations.Component;

@Component(property = { "service.ranking:Integer=10" })
public class LspEditorFormatOnSave implements IFormatOnSave {

@Override
public boolean isEnabledFor(IDocument document) {
return true;
}

@Override
public IRegion[] getFormattingRegions(ITextFileBuffer buffer) {
// try {
// return EditorUtility.calculateChangedLineRegions(buffer, new NullProgressMonitor());
// } catch (CoreException e) {
// Platform.getLog(CEditorAssociationOverride.class).log(e.getStatus());
// }
// return null;

return new IRegion[] { new Region(0, buffer.getDocument().getLength()) };
}

}

0 comments on commit 3d2da5a

Please sign in to comment.