Skip to content

Commit

Permalink
Correctly declare support for "workspace/willRenameFiles".
Browse files Browse the repository at this point in the history
- The server capabilities in the initialize response must contain a
  "willRename" object in the workspace's "fileOperations" object if the
  client indicates support for the request.

Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
  • Loading branch information
rgrunber committed Apr 8, 2024
1 parent d518f6d commit d559507
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
import org.eclipse.lsp4j.DocumentFilter;
import org.eclipse.lsp4j.DocumentOnTypeFormattingOptions;
import org.eclipse.lsp4j.ExecuteCommandOptions;
import org.eclipse.lsp4j.FileOperationFilter;
import org.eclipse.lsp4j.FileOperationOptions;
import org.eclipse.lsp4j.FileOperationPattern;
import org.eclipse.lsp4j.FileOperationPatternKind;
import org.eclipse.lsp4j.FileOperationsServerCapabilities;
import org.eclipse.lsp4j.InitializeParams;
import org.eclipse.lsp4j.InitializeResult;
import org.eclipse.lsp4j.SaveOptions;
Expand Down Expand Up @@ -219,6 +224,15 @@ public void registerCapabilities(InitializeResult initializeResult) {
WorkspaceFoldersOptions wsFoldersOptions = new WorkspaceFoldersOptions();
wsFoldersOptions.setSupported(Boolean.TRUE);
wsFoldersOptions.setChangeNotifications(Boolean.TRUE);

if (preferenceManager.getClientPreferences().isWorkspaceWillRenameFilesSupported()) {
FileOperationsServerCapabilities wsFileOperations = new FileOperationsServerCapabilities();
FileOperationPattern fileOpPattern = new FileOperationPattern("**/*.java");
fileOpPattern.setMatches(FileOperationPatternKind.File);
wsFileOperations.setWillRename(new FileOperationOptions(List.of(new FileOperationFilter(fileOpPattern, "file"))));
wsCapabilities.setFileOperations(wsFileOperations);
}

wsCapabilities.setWorkspaceFolders(wsFoldersOptions);
capabilities.setWorkspace(wsCapabilities);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public boolean isWorkspaceFoldersSupported() {
return capabilities.getWorkspace() != null && isTrue(capabilities.getWorkspace().getWorkspaceFolders());
}

public boolean isWorkspaceWillRenameFilesSupported() {
return v3supported && capabilities.getWorkspace() != null && capabilities.getWorkspace().getFileOperations() != null && isTrue(capabilities.getWorkspace().getFileOperations().getWillRename());
}

public boolean isCompletionDynamicRegistered() {
return v3supported && isDynamicRegistrationSupported(capabilities.getTextDocument().getCompletion());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
import org.eclipse.lsp4j.ExecuteCommandOptions;
import org.eclipse.lsp4j.FileChangeType;
import org.eclipse.lsp4j.FileEvent;
import org.eclipse.lsp4j.FileOperationOptions;
import org.eclipse.lsp4j.FileOperationPatternKind;
import org.eclipse.lsp4j.FileOperationsServerCapabilities;
import org.eclipse.lsp4j.FileSystemWatcher;
import org.eclipse.lsp4j.InitializeParams;
import org.eclipse.lsp4j.InitializeResult;
Expand Down Expand Up @@ -368,6 +371,21 @@ public void testWatchers() throws Exception {
assertEquals(newWatchers, watchers);
}

@Test
public void testWorkspaceWillRenameFiles() throws Exception {
ClientPreferences mockCapabilies = mock(ClientPreferences.class);
when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
when(mockCapabilies.isWorkspaceWillRenameFilesSupported()).thenReturn(Boolean.TRUE);
InitializeResult result = initialize(true);
FileOperationsServerCapabilities fileOpSrvCap = result.getCapabilities().getWorkspace().getFileOperations();
assertNotNull(fileOpSrvCap);
FileOperationOptions fileOpOps = fileOpSrvCap.getWillRename();
assertNotNull(fileOpOps);
assertEquals("file", fileOpOps.getFilters().get(0).getScheme());
assertEquals(FileOperationPatternKind.File, fileOpOps.getFilters().get(0).getPattern().getMatches());
assertEquals("**/*.java", fileOpOps.getFilters().get(0).getPattern().getGlob());
}

// https://github.com/redhat-developer/vscode-java/issues/2429
@Test
public void testSettingsWatchers() throws Exception {
Expand Down

0 comments on commit d559507

Please sign in to comment.