Skip to content

Commit

Permalink
Merge pull request apache#8111 from dbalek/dbalek/vscode-ext-formatte…
Browse files Browse the repository at this point in the history
…r-settings-remove

VSCode: Removing option for external formatters.
  • Loading branch information
dbalek authored Jan 7, 2025
2 parents b9ac871 + de61868 commit d72b592
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
Expand Down Expand Up @@ -125,7 +124,6 @@
import org.netbeans.modules.java.lsp.server.Utils;
import org.netbeans.modules.java.lsp.server.debugging.attach.AttachConfigurations;
import org.netbeans.modules.java.lsp.server.debugging.attach.AttachNativeConfigurations;
import org.netbeans.modules.java.lsp.server.progress.ModuleInfo;
import org.netbeans.modules.java.lsp.server.project.LspProjectInfo;
import org.netbeans.modules.java.lsp.server.singlesourcefile.SingleFileOptionsQueryImpl;
import org.netbeans.modules.java.source.ElementHandleAccessor;
Expand All @@ -152,7 +150,6 @@
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.NbPreferences;
import org.openide.util.Pair;
import org.openide.util.RequestProcessor;
import org.openide.util.WeakListeners;
Expand Down Expand Up @@ -1412,32 +1409,18 @@ public void didChangeConfiguration(DidChangeConfigurationParams params) {

void updateJavaFormatPreferences(FileObject fo, JsonObject configuration) {
if (configuration != null && client.getNbCodeCapabilities().wantsJavaSupport()) {
NbPreferences.Provider provider = Lookup.getDefault().lookup(NbPreferences.Provider.class);
Preferences prefs = provider != null ? provider.preferencesRoot().node("de/funfried/netbeans/plugins/externalcodeformatter") : null;
JsonPrimitive formatterPrimitive = configuration.getAsJsonPrimitive("codeFormatter");
String formatter = formatterPrimitive != null ? formatterPrimitive.getAsString() : null;
JsonPrimitive pathPrimitive = configuration.getAsJsonPrimitive("settingsPath");
String path = pathPrimitive != null ? pathPrimitive.getAsString() : null;
if (formatter == null || "NetBeans".equals(formatter)) {
if (prefs != null) {
prefs.put("enabledFormatter.JAVA", "netbeans-formatter");
}
Path p = path != null ? Paths.get(path) : null;
File file = p != null ? p.toFile() : null;
try {
if (file != null && file.exists() && file.canRead() && file.getName().endsWith(".zip")) {
OptionsExportModel.get().doImport(file);
} else {
OptionsExportModel.get().clean();
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
} else if (prefs != null) {
prefs.put("enabledFormatter.JAVA", formatter.toLowerCase(Locale.ENGLISH).concat("-java-formatter"));
if (path != null) {
prefs.put(formatter.toLowerCase(Locale.ENGLISH).concat("FormatterLocation"), path);
JsonElement pathElement = configuration.get("settingsPath");
String path = pathElement != null && pathElement.isJsonPrimitive() ? pathElement.getAsString() : null;
Path p = path != null ? Paths.get(path) : null;
File file = p != null ? p.toFile() : null;
try {
if (file != null && file.exists() && file.canRead() && file.getName().endsWith(".zip")) {
OptionsExportModel.get().doImport(file);
} else {
OptionsExportModel.get().clean();
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions java/java.lsp.server/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ When adding JavaDoc to code NetBeans assists by suggesting to insert preformatte
![JavaDoc Completion](images/javadoc.png)

## Source Code formatting
Formatting source code is possible using also other styles than NetBeans. Eclipse, Google and Spring formatters can be used. For Eclipse formatter simply export settings from Eclipse IDE into standard file and then set `Netbeans > Format: Settings Path:` in VSCode Settings.
![Source Code formatter](images/SourceCodeFormatter.png)
Formatting source code is possible using the NetBeans code style. For using non default formatter options, simply export desired settings from NetBeans IDE into standard file and then set `Netbeans > Format: Settings Path:` in VSCode Settings.

## Test Explorer
NetBeans Language Server provides Test Explorer view which allows to run all tests in a project, examine the results, go to source code and run particular test.
![Test Explorer](images/Test_explorer.png)
Expand Down
Binary file not shown.
17 changes: 0 additions & 17 deletions java/java.lsp.server/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,6 @@
"default": 10000,
"description": "When code completion takes longer than this specified time (in milliseconds), there will be a warning produced (-1 to disable)"
},
"netbeans.format.codeFormatter": {
"type": "string",
"enum": [
"NetBeans",
"Eclipse",
"Google",
"Spring"
],
"enumDescriptions": [
"Internal NetBeans Code Formatter",
"Eclipse Code Formatter",
"Goolge Code Formatter",
"Spring Code Formatter"
],
"description": "Code formatter to use",
"default": "NetBeans"
},
"netbeans.format.settingsPath": {
"type": "string",
"description": "Path to the file containing exported formatter settings",
Expand Down

0 comments on commit d72b592

Please sign in to comment.