Skip to content

Commit

Permalink
Fix saving of modified MN deps, fix OCI props provider
Browse files Browse the repository at this point in the history
Accept file:/ as well as file:/// for save
  • Loading branch information
jhorvath committed Sep 20, 2024
1 parent 0374e1f commit a75339d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ public CompletableFuture<Object> runCommand(String command, List<Object> argumen
try {
Path temp = configFileGenerator.writePropertiesFile(dbProps);
result.put("MICRONAUT_CONFIG_FILES", temp.toAbsolutePath().toString()); // NOI18N
ret.complete(result);
} catch (IOException ex) {
ret.completeExceptionally(ex);
return ret;
}
}
ret.complete(result);
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.netbeans.api.java.source.JavaSource;
import org.netbeans.api.java.source.TreeMaker;
import org.netbeans.api.java.source.WorkingCopy;
import org.netbeans.api.lsp.WorkspaceEdit;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.aggregate.BasicAggregateProgressFactory;
import org.netbeans.api.progress.aggregate.ProgressContributor;
Expand Down Expand Up @@ -86,9 +87,9 @@
import org.netbeans.modules.project.dependency.DependencyChange;
import org.netbeans.modules.project.dependency.DependencyChangeException;
import org.netbeans.modules.project.dependency.ProjectDependencies;
import org.netbeans.modules.project.dependency.ProjectModificationResult;
import org.netbeans.modules.project.dependency.ProjectOperationException;
import org.netbeans.modules.project.dependency.Scopes;
import org.netbeans.modules.refactoring.spi.ModificationResult;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
Expand Down Expand Up @@ -154,9 +155,9 @@ protected List<FileObject> createFromTemplate(CreateDescriptor desc) throws IOEx
Dependency dep = Dependency.make(spec, Scopes.COMPILE);
DependencyChange change = DependencyChange.add(Collections.singletonList(dep), DependencyChange.Options.skipConflicts);
try {
ModificationResult mod = ProjectDependencies.modifyDependencies(project, change);
mod.commit();
} catch (IOException | DependencyChangeException | ProjectOperationException ex) {
ProjectModificationResult mod = ProjectDependencies.modifyDependencies(project, change);
WorkspaceEdit.applyEdits(Collections.singletonList(mod.getWorkspaceEdit()), true);
} catch (DependencyChangeException | ProjectOperationException ex) {
throw new IllegalStateException(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,7 @@ public CompletableFuture<List<String>> applyChanges(List<WorkspaceEdit> edits, b
return null;
}
Worker wk = new Worker(client, edits, saveResources);
try {
wk.execute();
return CompletableFuture.completedFuture(wk.getProcessedResources());
} catch (ResourceModificationException ex) {
CompletableFuture failed = new CompletableFuture();
failed.completeExceptionally(ex);
return failed;
}
return wk.execute().thenApply(v -> wk.getProcessedResources());
}

final static class Worker {
Expand Down Expand Up @@ -148,8 +141,11 @@ CompletableFuture<Void> handleClientResponse(WorkspaceEdit edit, ApplyWorkspaceE
}
}

public void execute() throws ResourceModificationException {
public CompletableFuture<Void> execute() {
CompletableFuture<Void> response = null;
if (edits.isEmpty()) {
return CompletableFuture.completedFuture(null);
}
for (WorkspaceEdit e : edits) {
currentEdit = e;

Expand All @@ -164,7 +160,13 @@ public void execute() throws ResourceModificationException {
}

if (doSave) {
client.requestDocumentSave(new SaveDocumentRequestParams(new ArrayList<>(processed)));
return response.thenCompose(v -> client.requestDocumentSave(new SaveDocumentRequestParams(new ArrayList<>(processed))))
.thenApply(success -> {
saved.addAll(processed);
return null;
});
} else {
return response;
}
}
}
Expand Down
19 changes: 16 additions & 3 deletions java/java.lsp.server/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1333,12 +1333,25 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
// don't ask why vscode mangles URIs this way; in addition, it uses lowercase drive letter ???
return `file:///${re[1].toLowerCase()}%3A/${re[2]}`;
});
let ok = true;
for (let ed of workspace.textDocuments) {
if (uriList.includes(ed.uri.toString())) {
return ed.save();
let uri = ed.uri.toString();

if (uriList.includes(uri)) {
ed.save();
continue;
}
if (uri.startsWith("file:///")) {
// make file:/// just file:/
uri = "file:/" + uri.substring(8);
if (uriList.includes(uri)) {
ed.save();
continue;
}
}
ok = false;
}
return false;
return ok;
});
c.onRequest(InputBoxRequest.type, async param => {
return await window.showInputBox({ title: param.title, prompt: param.prompt, value: param.value, password: param.password });
Expand Down

0 comments on commit a75339d

Please sign in to comment.