Skip to content

Commit

Permalink
Merge pull request apache#5692 from sdedic/vscode/commands-rename
Browse files Browse the repository at this point in the history
Better LSP command names, conflict resolution
  • Loading branch information
sdedic authored Mar 22, 2023
2 parents eba3855 + 90acd9a commit 4c90ff3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,26 @@ public class ProjectAuditCommand extends CodeActionsProvider {
/**
* Force executes the project audit using the supplied compartment and knowledgebase IDs.
*/
private static final String COMMAND_EXECUTE_AUDIT = "nbls.gcn.projectAudit.execute"; // NOI18N
private static final String COMMAND_EXECUTE_AUDIT = "nbls.projectAudit.execute"; // NOI18N
/**
* @deprecated will be removed in NB 19
*/
private static final String COMMAND_EXECUTE_AUDIT_OLD = "nbls.gcn.projectAudit.execute"; // NOI18N

/**
* Displays the audit from the Knowledgebase and compartment.
*/
private static final String COMMAND_LOAD_AUDIT = "nbls.gcn.projectAudit.display"; // NOI18N
private static final String COMMAND_LOAD_AUDIT = "nbls.projectAudit.display"; // NOI18N
/**
* @deprecated will be removed in NB 19
*/
private static final String COMMAND_LOAD_AUDIT_OLD = "nbls.gcn.projectAudit.display"; // NOI18N

public static final Set<String> COMMANDS = new HashSet<>(Arrays.asList(
COMMAND_EXECUTE_AUDIT,
COMMAND_LOAD_AUDIT
COMMAND_LOAD_AUDIT,
COMMAND_EXECUTE_AUDIT_OLD,
COMMAND_LOAD_AUDIT_OLD
));

@Override
Expand Down Expand Up @@ -195,9 +205,11 @@ public CompletableFuture<Object> processCommand(NbCodeLanguageClient client, Str

switch (command) {
case COMMAND_EXECUTE_AUDIT:
case COMMAND_EXECUTE_AUDIT_OLD:
exec = v.runProjectAudit(kb, auditOpts);
break;
case COMMAND_LOAD_AUDIT: {
case COMMAND_LOAD_AUDIT:
case COMMAND_LOAD_AUDIT_OLD: {
exec = v.runProjectAudit(kb, auditOpts.setRunIfNotExists(forceAudit).setAuditName(preferredName));
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@
*/
@ServiceProvider(service = CodeActionsProvider.class)
public class ProjectMetadataCommand extends CodeActionsProvider {
private static final String COMMAND_ARTIFACTS = "nbls.gcn.project.artifacts"; // NOI18N
private static final String COMMAND_ARTIFACTS = "nbls.project.artifacts"; // NOI18N
/**
* @deprecated will be removed in NB 19
*/
private static final String COMMAND_ARTIFACTS_OLD = "nbls.gcn.project.artifacts"; // NOI18N

private static final Set<String> COMMANDS = new HashSet<>(Arrays.asList(
COMMAND_ARTIFACTS
COMMAND_ARTIFACTS,
COMMAND_ARTIFACTS_OLD
));
private static final Set<String> ARTIFACT_BLOCK_FIELDS = new HashSet<>(Arrays.asList(
"data" // NOI18N
Expand Down
33 changes: 31 additions & 2 deletions java/java.lsp.server/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,33 @@ class InitialPromise extends Promise<NbLanguageClient> {
}
}

/**
* Determines the outcome, if there's a conflict betwee RH Java and us: disable java, enable java, ask the user.
* @returns false, if java should be disablde; true, if enabled. Undefined if no config is present, ask the user
*/
function shouldEnableConflictingJavaSupport() : boolean | undefined {
// backwards compatibility; remove in NBLS 19
if (vscode.extensions.getExtension('oracle-labs-graalvm.gcn')) {
return false;
}
let r = undefined;
for (const ext of vscode.extensions.all) {
const services = ext.packageJSON?.contributes && ext.packageJSON?.contributes['netbeans.options'];
if (!services) {
continue;
}
if (services['javaSupport.conflict'] !== undefined) {
const v = !!services['javaSupport.conflict'];
if (!v) {
// request to disable wins.
return false;
}
r = v;
}
}
return r;
}

export function activate(context: ExtensionContext): VSNetBeansAPI {
let log = vscode.window.createOutputChannel("Apache NetBeans Language Server");

Expand All @@ -318,8 +345,10 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
function checkConflict(): void {
let conf = workspace.getConfiguration();
if (conf.get("netbeans.conflict.check") && conf.get("netbeans.javaSupport.enabled")) {
if (vscode.extensions.getExtension('redhat.java')) {
if (vscode.extensions.getExtension('oracle-labs-graalvm.gcn')) {
const e : boolean | undefined = shouldEnableConflictingJavaSupport();
if (!e && vscode.extensions.getExtension('redhat.java')) {
if (e === false) {
// do not ask, an extension wants us to disable on conflict
conf.update("netbeans.javaSupport.enabled", false, true);
} else {
const DISABLE_EXTENSION = `Manually disable extension`;
Expand Down

0 comments on commit 4c90ff3

Please sign in to comment.