Skip to content

Commit

Permalink
renameOptions по запросу с клиента
Browse files Browse the repository at this point in the history
  • Loading branch information
asosnoviy committed May 27, 2022
1 parent 369089e commit b14cca6
Showing 1 changed file with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics;
import com.github._1c_syntax.bsl.languageserver.jsonrpc.ProtocolExtension;
import com.github._1c_syntax.bsl.languageserver.providers.DocumentSymbolProvider;
import com.github._1c_syntax.bsl.languageserver.providers.RenameProvider;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.lsp4j.CallHierarchyRegistrationOptions;
import org.eclipse.lsp4j.ClientCapabilities;
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.CodeActionOptions;
import org.eclipse.lsp4j.CodeLensOptions;
Expand All @@ -45,14 +45,17 @@
import org.eclipse.lsp4j.InitializeParams;
import org.eclipse.lsp4j.InitializeResult;
import org.eclipse.lsp4j.ReferenceOptions;
import org.eclipse.lsp4j.RenameCapabilities;
import org.eclipse.lsp4j.RenameOptions;
import org.eclipse.lsp4j.SaveOptions;
import org.eclipse.lsp4j.SelectionRangeRegistrationOptions;
import org.eclipse.lsp4j.ServerCapabilities;
import org.eclipse.lsp4j.ServerInfo;
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
import org.eclipse.lsp4j.TextDocumentSyncKind;
import org.eclipse.lsp4j.TextDocumentSyncOptions;
import org.eclipse.lsp4j.WorkspaceSymbolOptions;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.services.LanguageServer;
import org.eclipse.lsp4j.services.TextDocumentService;
import org.eclipse.lsp4j.services.WorkspaceService;
Expand All @@ -64,6 +67,7 @@
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

@Slf4j
Expand Down Expand Up @@ -103,7 +107,7 @@ public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
capabilities.setCallHierarchyProvider(getCallHierarchyProvider());
capabilities.setSelectionRangeProvider(getSelectionRangeProvider());
capabilities.setColorProvider(getColorProvider());
capabilities.setRenameProvider(getRenameProvider());
capabilities.setRenameProvider(getRenameProvider(params));

var result = new InitializeResult(capabilities, serverInfo);

Expand Down Expand Up @@ -277,10 +281,31 @@ private static ColorProviderOptions getColorProvider() {
return colorProviderOptions;
}

private static RenameOptions getRenameProvider() {
var renameOptions = new RenameOptions();
renameOptions.setWorkDoneProgress(Boolean.FALSE);
renameOptions.setPrepareProvider(Boolean.TRUE);
return renameOptions;
private static Either<Boolean, RenameOptions> getRenameProvider(InitializeParams params) {

if (Boolean.TRUE.equals(getRenamePrepareSupport(params))) {

var renameOptions = new RenameOptions();
renameOptions.setWorkDoneProgress(Boolean.FALSE);
renameOptions.setPrepareProvider(Boolean.TRUE);

return Either.forRight(renameOptions);

} else {

return Either.forLeft(Boolean.TRUE);

}

}

private static Boolean getRenamePrepareSupport(InitializeParams params) {
return Optional.of(params)
.map(InitializeParams::getCapabilities)
.map(ClientCapabilities::getTextDocument)
.map(TextDocumentClientCapabilities::getRename)
.map(RenameCapabilities::getPrepareSupport)
.orElse(false);
}

}

0 comments on commit b14cca6

Please sign in to comment.