Skip to content

Commit

Permalink
Make formatting operations available to consumers (#942)
Browse files Browse the repository at this point in the history
This commit adds org.eclipse.lsp4e.operations.format to the list of
exported packages. We need this to use LSPFormatFilesHandler in a
context action for objects which can't be adapted to an IFile. There is
also a small refactor of the class for the same reason.
  • Loading branch information
ava-fred authored Mar 5, 2024
1 parent c3abe76 commit 4d1f527
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions org.eclipse.lsp4e/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Export-Package: org.eclipse.lsp4e;x-internal:=true,
org.eclipse.lsp4e.format;x-internal:=true,
org.eclipse.lsp4e.operations.codeactions;x-internal:=true,
org.eclipse.lsp4e.operations.completion;x-internal:=true,
org.eclipse.lsp4e.operations.format;x-internal:=true,
org.eclipse.lsp4e.operations.hover;x-internal:=true,
org.eclipse.lsp4e.outline;x-internal:=true,
org.eclipse.lsp4e.server;version="0.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ protected void formatFile(final @NonNull IFile file, final IProgressMonitor moni
}
});
docProvider.changed(doc);
try {
docProvider.saveDocument(monitor, file, doc, true);
} catch (CoreException e) {
LanguageServerPlugin.logError(e);
}
saveDocument(docProvider, file, monitor);
});
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
Expand All @@ -118,6 +114,14 @@ protected IDocumentProvider getDocumentProvider(IFile file) {
return DocumentProviderRegistry.getDefault().getDocumentProvider(new FileEditorInput(file));
}

protected void saveDocument(IDocumentProvider docProvider, IFile file, IProgressMonitor monitor) {
try {
docProvider.saveDocument(monitor, file, docProvider.getDocument(file), true);
} catch (CoreException e) {
LanguageServerPlugin.logError(e);
}
}

protected Set<@NonNull IFile> getSelectedFiles(final ExpressionContext ctx) {
final var selection = getSelection(ctx);
if (selection.isEmpty())
Expand Down

0 comments on commit 4d1f527

Please sign in to comment.