Skip to content

Commit

Permalink
Ensure 'workspace/willRenameFiles' is handled only by extension.
Browse files Browse the repository at this point in the history
- JDT-LS now respects the LSP Spec, and will respond to
  'workspace/willRenameFiles' requests handled by vsc-languageserver-node
- This extension performs the request manually in order to produce a
  prompt/dialog allowing a user to select which changes should be
  applied
- To keep this behaviour, and prevent duplicate requests, we must
  prevent the client from advertising this option to the language server

Signed-off-by: Roland Grunberg <[email protected]>
  • Loading branch information
rgrunber committed Apr 8, 2024
1 parent 9bfd8a8 commit e578b50
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/standardLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import * as net from 'net';
import * as path from 'path';
import { CancellationToken, CodeActionKind, commands, ConfigurationTarget, DocumentSelector, EventEmitter, ExtensionContext, extensions, languages, Location, ProgressLocation, TextEditor, Uri, ViewColumn, window, workspace } from "vscode";
import { ConfigurationParams, ConfigurationRequest, LanguageClientOptions, Location as LSLocation, MessageType, Position as LSPosition, TextDocumentPositionParams, WorkspaceEdit } from "vscode-languageclient";
import { ConfigurationParams, ConfigurationRequest, LanguageClientOptions, Location as LSLocation, MessageType, Position as LSPosition, TextDocumentPositionParams, WorkspaceEdit, StaticFeature, ClientCapabilities, FeatureState } from "vscode-languageclient";
import { LanguageClient, StreamInfo } from "vscode-languageclient/node";
import { apiManager } from "./apiManager";
import * as buildPath from './buildpath';
Expand Down Expand Up @@ -107,6 +107,7 @@ export class StandardLanguageClient {

// Create the language client and start the client.
this.languageClient = new TracingLanguageClient('java', extensionName, serverOptions, clientOptions, DEBUG);
this.languageClient.registerFeature(new DisableWillRenameFeature());

this.registerCommandsForStandardServer(context, jdtEventEmitter);
fileEventHandler.registerFileEventHandlers(this.languageClient, context);
Expand Down Expand Up @@ -871,4 +872,21 @@ export async function applyWorkspaceEdit(workspaceEdit: WorkspaceEdit, languageC
} else {
return Promise.resolve(true);
}
}

/**
* 'workspace/willRenameFiles' already handled so we need to disable it.
* @see fileEventHandler.registerFileEventHandlers
*/
export class DisableWillRenameFeature implements StaticFeature {
fillClientCapabilities(capabilities: ClientCapabilities): void {
capabilities.workspace.fileOperations.willRename = false;
}
getState(): FeatureState {
return null;
}
clear(): void {}
fillInitializeParams?: () => void;
preInitialize?: () => void;
initialize(): void {}
}

0 comments on commit e578b50

Please sign in to comment.