mirror of https://github.com/astral-sh/ruff
[ty] Always register rename provider if client doesn't support dynamic registration (#21789)
This commit is contained in:
parent
3aefe85b32
commit
326025d45f
|
|
@ -1,5 +1,5 @@
|
||||||
use lsp_types::{
|
use lsp_types::{
|
||||||
ClientCapabilities, CodeActionKind, CodeActionOptions, CompletionOptions,
|
self as types, ClientCapabilities, CodeActionKind, CodeActionOptions, CompletionOptions,
|
||||||
DeclarationCapability, DiagnosticOptions, DiagnosticServerCapabilities,
|
DeclarationCapability, DiagnosticOptions, DiagnosticServerCapabilities,
|
||||||
HoverProviderCapability, InlayHintOptions, InlayHintServerCapabilities, MarkupKind,
|
HoverProviderCapability, InlayHintOptions, InlayHintServerCapabilities, MarkupKind,
|
||||||
NotebookCellSelector, NotebookSelector, OneOf, RenameOptions, SelectionRangeProviderCapability,
|
NotebookCellSelector, NotebookSelector, OneOf, RenameOptions, SelectionRangeProviderCapability,
|
||||||
|
|
@ -8,11 +8,9 @@ use lsp_types::{
|
||||||
TextDocumentSyncCapability, TextDocumentSyncKind, TextDocumentSyncOptions,
|
TextDocumentSyncCapability, TextDocumentSyncKind, TextDocumentSyncOptions,
|
||||||
TypeDefinitionProviderCapability, WorkDoneProgressOptions,
|
TypeDefinitionProviderCapability, WorkDoneProgressOptions,
|
||||||
};
|
};
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use crate::PositionEncoding;
|
use crate::PositionEncoding;
|
||||||
use crate::session::GlobalSettings;
|
|
||||||
use lsp_types as types;
|
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
bitflags::bitflags! {
|
bitflags::bitflags! {
|
||||||
/// Represents the resolved client capabilities for the language server.
|
/// Represents the resolved client capabilities for the language server.
|
||||||
|
|
@ -349,7 +347,6 @@ impl ResolvedClientCapabilities {
|
||||||
pub(crate) fn server_capabilities(
|
pub(crate) fn server_capabilities(
|
||||||
position_encoding: PositionEncoding,
|
position_encoding: PositionEncoding,
|
||||||
resolved_client_capabilities: ResolvedClientCapabilities,
|
resolved_client_capabilities: ResolvedClientCapabilities,
|
||||||
global_settings: &GlobalSettings,
|
|
||||||
) -> ServerCapabilities {
|
) -> ServerCapabilities {
|
||||||
let diagnostic_provider =
|
let diagnostic_provider =
|
||||||
if resolved_client_capabilities.supports_diagnostic_dynamic_registration() {
|
if resolved_client_capabilities.supports_diagnostic_dynamic_registration() {
|
||||||
|
|
@ -368,11 +365,9 @@ pub(crate) fn server_capabilities(
|
||||||
// dynamically based on the `ty.experimental.rename` setting.
|
// dynamically based on the `ty.experimental.rename` setting.
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, we check whether user has enabled rename support via the resolved settings
|
// Otherwise, we always register the rename provider and bail out in `prepareRename` if
|
||||||
// from initialization options.
|
// the feature is disabled.
|
||||||
global_settings
|
Some(OneOf::Right(server_rename_options()))
|
||||||
.is_rename_enabled()
|
|
||||||
.then(|| OneOf::Right(server_rename_options()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ServerCapabilities {
|
ServerCapabilities {
|
||||||
|
|
|
||||||
|
|
@ -72,15 +72,8 @@ impl Server {
|
||||||
tracing::debug!("Resolved client capabilities: {resolved_client_capabilities}");
|
tracing::debug!("Resolved client capabilities: {resolved_client_capabilities}");
|
||||||
|
|
||||||
let position_encoding = Self::find_best_position_encoding(&client_capabilities);
|
let position_encoding = Self::find_best_position_encoding(&client_capabilities);
|
||||||
let server_capabilities = server_capabilities(
|
let server_capabilities =
|
||||||
position_encoding,
|
server_capabilities(position_encoding, resolved_client_capabilities);
|
||||||
resolved_client_capabilities,
|
|
||||||
&initialization_options
|
|
||||||
.options
|
|
||||||
.global
|
|
||||||
.clone()
|
|
||||||
.into_settings(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let version = ruff_db::program_version().unwrap_or("Unknown");
|
let version = ruff_db::program_version().unwrap_or("Unknown");
|
||||||
tracing::info!("Version: {version}");
|
tracing::info!("Version: {version}");
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ impl BackgroundDocumentRequestHandler for PrepareRenameRequestHandler {
|
||||||
if snapshot
|
if snapshot
|
||||||
.workspace_settings()
|
.workspace_settings()
|
||||||
.is_language_services_disabled()
|
.is_language_services_disabled()
|
||||||
|
|| !snapshot.global_settings().is_rename_enabled()
|
||||||
{
|
{
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -564,7 +564,7 @@ impl Session {
|
||||||
publish_settings_diagnostics(self, client, root);
|
publish_settings_diagnostics(self, client, root);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(global_options) = combined_global_options.take() {
|
if let Some(global_options) = combined_global_options {
|
||||||
let global_settings = global_options.into_settings();
|
let global_settings = global_options.into_settings();
|
||||||
if global_settings.diagnostic_mode().is_workspace() {
|
if global_settings.diagnostic_mode().is_workspace() {
|
||||||
for project in self.projects.values_mut() {
|
for project in self.projects.values_mut() {
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,9 @@ expression: initialization_result
|
||||||
"quickfix"
|
"quickfix"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"renameProvider": {
|
||||||
|
"prepareProvider": true
|
||||||
|
},
|
||||||
"declarationProvider": true,
|
"declarationProvider": true,
|
||||||
"executeCommandProvider": {
|
"executeCommandProvider": {
|
||||||
"commands": [
|
"commands": [
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,9 @@ expression: initialization_result
|
||||||
"quickfix"
|
"quickfix"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"renameProvider": {
|
||||||
|
"prepareProvider": true
|
||||||
|
},
|
||||||
"declarationProvider": true,
|
"declarationProvider": true,
|
||||||
"executeCommandProvider": {
|
"executeCommandProvider": {
|
||||||
"commands": [
|
"commands": [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue