Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
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;
Expand Down Expand Up @@ -120,7 +122,6 @@
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;
Expand Down Expand Up @@ -642,6 +643,7 @@ public void finished(boolean success) {
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) {
Expand All @@ -661,7 +663,7 @@ public void finished(boolean success) {
openingFileOwners.put(p, f.thenApply(unused -> p));
}
}
f.complete(prjs);
f.complete(prjsRequested);
}).exceptionally(e -> {
f.completeExceptionally(e);
return null;
Expand Down Expand Up @@ -736,7 +738,7 @@ private InitializeResult constructInitResponse(InitializeParams init, JavaSource
capabilities.setDocumentFormattingProvider(true);
capabilities.setDocumentRangeFormattingProvider(true);
capabilities.setReferencesProvider(true);

CallHierarchyRegistrationOptions chOpts = new CallHierarchyRegistrationOptions();
chOpts.setWorkDoneProgress(true);
capabilities.setCallHierarchyProvider(chOpts);
Expand Down Expand Up @@ -773,6 +775,14 @@ private InitializeResult constructInitResponse(InitializeParams init, JavaSource
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
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;
Expand All @@ -71,12 +70,14 @@
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;
Expand Down Expand Up @@ -129,10 +130,12 @@
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;
Expand Down Expand Up @@ -1170,6 +1173,54 @@ void updateJavaImportPreferences(FileObject fo, JsonObject configuration) {
}
}

@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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lines 1207 - 1213 look like they should belong to ProjectInformation class

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lines 1207 - 1213 look like they should belong to ProjectInformation class

Rather to ProjectUtils; but yes, some "give-me-suitable-project-name-with-all-fallbacks' could be useful, I did this chain of null checks several times already. I'll address in a separate PR.

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
Expand Down