forked from eclipse-lsp4e/lsp4e
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use formatDocument as fallback for willSaveWaitUntil
if server does not support willSaveWaitUntil the code can be formatted prior to save. fixes eclipse-lsp4e#761
- Loading branch information
1 parent
9c92a32
commit 42d70fb
Showing
8 changed files
with
122 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
org.eclipse.lsp4e/OSGI-INF/org.eclipse.lsp4e.DefaultFormatOnSave.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.lsp4e.DefaultFormatOnSave"> | ||
<property name="service.ranking" type="Integer" value="0"/> | ||
<implementation class="org.eclipse.lsp4e.DefaultFormatOnSave"/> | ||
<service> | ||
<provide interface="org.eclipse.lsp4e.IFormatOnSave"/> | ||
</service> | ||
</scr:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ bin.includes = META-INF/,\ | |
icons/,\ | ||
.options,\ | ||
resources/,\ | ||
schema/ | ||
schema/,\ | ||
OSGI-INF/ | ||
src.includes = schema/ |
36 changes: 36 additions & 0 deletions
36
org.eclipse.lsp4e/src/org/eclipse/lsp4e/DefaultFormatOnSave.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* See git history | ||
*******************************************************************************/ | ||
package org.eclipse.lsp4e; | ||
|
||
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.osgi.service.component.annotations.Component; | ||
|
||
@Component(property = { "service.ranking:Integer=0" }) | ||
public class DefaultFormatOnSave implements IFormatOnSave { | ||
|
||
@Override | ||
public boolean isEnabledFor(IDocument document) { | ||
return false; | ||
} | ||
|
||
/** | ||
* Formats the full file | ||
*/ | ||
@Override | ||
public IRegion[] getFormattingRegions(ITextFileBuffer buffer) { | ||
return new IRegion[] { new Region(0, buffer.getDocument().getLength()) }; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
org.eclipse.lsp4e/src/org/eclipse/lsp4e/IFormatOnSave.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* See git history | ||
*******************************************************************************/ | ||
package org.eclipse.lsp4e; | ||
|
||
import org.eclipse.core.filebuffers.ITextFileBuffer; | ||
import org.eclipse.jface.text.IDocument; | ||
import org.eclipse.jface.text.IRegion; | ||
|
||
public interface IFormatOnSave { | ||
|
||
/** | ||
* Checks whether formatting shall be performed prior to file buffer saving. | ||
* @param document | ||
* @return true if document buffer shall be formatted prior saving | ||
*/ | ||
boolean isEnabledFor(IDocument document); | ||
|
||
/** | ||
* Get the regions to be formatted (e.g. full file, lines edited this session, lines edited vs. source control baseline). | ||
* @param buffer the buffer to compare contents from | ||
* @return regions to be formatted before saving. | ||
*/ | ||
IRegion[] getFormattingRegions(ITextFileBuffer buffer); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters