This is an automated email from the ASF dual-hosted git repository. sdedic pushed a commit to branch vsnetbeans_1603 in repository https://gitbox.apache.org/repos/asf/netbeans.git
commit 4dc1d89947d1eeba6ceed646f5e8464b52968051 Author: Svata Dedic <svatopluk.de...@oracle.com> AuthorDate: Thu Jan 12 14:28:19 2023 +0100 Open projects that correspond to workspace folders. Prevents "do you want to open project ?" questions. --- .../modules/java/lsp/server/protocol/Server.java | 16 +++++-- .../lsp/server/protocol/WorkspaceServiceImpl.java | 53 +++++++++++++++++++++- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java index cd19b1bbd3..be030ade1e 100644 --- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java @@ -73,6 +73,8 @@ import org.eclipse.lsp4j.TextDocumentSyncOptions; import org.eclipse.lsp4j.WorkDoneProgressCancelParams; import org.eclipse.lsp4j.WorkDoneProgressParams; import org.eclipse.lsp4j.WorkspaceFolder; +import org.eclipse.lsp4j.WorkspaceFoldersOptions; +import org.eclipse.lsp4j.WorkspaceServerCapabilities; import org.eclipse.lsp4j.jsonrpc.Endpoint; import org.eclipse.lsp4j.jsonrpc.JsonRpcException; import org.eclipse.lsp4j.jsonrpc.Launcher; @@ -120,7 +122,6 @@ import org.netbeans.spi.project.ActionProgress; import org.netbeans.spi.project.ActionProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; -import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.util.NbPreferences; @@ -642,6 +643,7 @@ public final class Server { projectSet.retainAll(openedProjects); projectSet.addAll(projects); + Project[] prjsRequested = projects.toArray(new Project[projects.size()]); Project[] prjs = projects.toArray(new Project[projects.size()]); LOG.log(Level.FINER, "{0}: Finished opening projects: {1}", new Object[]{id, Arrays.asList(projects)}); synchronized (this) { @@ -661,7 +663,7 @@ public final class Server { openingFileOwners.put(p, f.thenApply(unused -> p)); } } - f.complete(prjs); + f.complete(prjsRequested); }).exceptionally(e -> { f.completeExceptionally(e); return null; @@ -736,7 +738,7 @@ public final class Server { capabilities.setDocumentFormattingProvider(true); capabilities.setDocumentRangeFormattingProvider(true); capabilities.setReferencesProvider(true); - + CallHierarchyRegistrationOptions chOpts = new CallHierarchyRegistrationOptions(); chOpts.setWorkDoneProgress(true); capabilities.setCallHierarchyProvider(chOpts); @@ -773,6 +775,14 @@ public final class Server { FoldingRangeProviderOptions foldingOptions = new FoldingRangeProviderOptions(); capabilities.setFoldingRangeProvider(foldingOptions); textDocumentService.init(init.getCapabilities(), capabilities); + + // register for workspace changess + WorkspaceServerCapabilities wcaps = new WorkspaceServerCapabilities(); + WorkspaceFoldersOptions wfopts = new WorkspaceFoldersOptions(); + wfopts.setSupported(true); + wfopts.setChangeNotifications(true); + wcaps.setWorkspaceFolders(wfopts); + capabilities.setWorkspace(wcaps); } return new InitializeResult(capabilities); } diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceServiceImpl.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceServiceImpl.java index 00688d22cf..e73d65d0f1 100644 --- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceServiceImpl.java +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceServiceImpl.java @@ -50,7 +50,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; -import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; @@ -71,12 +70,14 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.lsp4j.CompletionItem; import org.eclipse.lsp4j.DidChangeConfigurationParams; import org.eclipse.lsp4j.DidChangeWatchedFilesParams; +import org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams; import org.eclipse.lsp4j.ExecuteCommandParams; import org.eclipse.lsp4j.Location; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.ShowDocumentParams; import org.eclipse.lsp4j.SymbolInformation; +import org.eclipse.lsp4j.WorkspaceFolder; import org.eclipse.lsp4j.WorkspaceSymbol; import org.eclipse.lsp4j.WorkspaceSymbolLocation; import org.eclipse.lsp4j.WorkspaceSymbolParams; @@ -129,10 +130,12 @@ import org.netbeans.spi.project.ProjectConfigurationProvider; import org.netbeans.spi.project.ui.ProjectProblemsProvider; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; +import org.openide.awt.StatusDisplayer; import org.openide.filesystems.FileObject; import org.openide.filesystems.URLMapper; 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; @@ -1170,6 +1173,54 @@ public final class WorkspaceServiceImpl implements WorkspaceService, LanguageCli } } + @NbBundle.Messages({ + "# {0} - project name", + "MSG_ProjectFolderInitializationComplete=Completed initialization of project {0}", + "# {0} - some project name", + "# {1} - number of other projects loaded", + "MSG_ProjectFolderInitializationComplete2=Completed initialization of {0} and {1} other projectss" + }) + @Override + public void didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams params) { + List<FileObject> refreshProjectFolders = new ArrayList<>(); + for (WorkspaceFolder wkspFolder : params.getEvent().getAdded()) { + String uri = wkspFolder.getUri(); + try { + FileObject f = Utils.fromUri(uri); + if (f != null) { + refreshProjectFolders.add(f); + } + } catch (MalformedURLException ex) { + // expected, perhaps some client-specific URL scheme ? + LOG.fine("Workspace folder URI could not be converted into fileobject: {0}"); + } + } + if (!refreshProjectFolders.isEmpty()) { + server.asyncOpenSelectedProjects(refreshProjectFolders, true).thenAccept((projects) -> { + // report initialization of a project / projects + String msg; + if (projects.length == 0) { + // this should happen immediately + return; + } + ProjectInformation pi = ProjectUtils.getInformation(projects[0]); + String n = pi.getDisplayName(); + if (n == null) { + n = pi.getName(); + } + if (n == null) { + n = projects[0].getProjectDirectory().getName(); + } + if (projects.length == 1) { + msg = Bundle.MSG_ProjectFolderInitializationComplete(n); + } else { + msg = Bundle.MSG_ProjectFolderInitializationComplete2(n, projects.length); + } + StatusDisplayer.getDefault().setStatusText(msg, StatusDisplayer.IMPORTANCE_ANNOTATION); + }); + } + } + @Override public void didChangeWatchedFiles(DidChangeWatchedFilesParams arg0) { //TODO: not watching files for now --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists