mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:21 +00:00
[ty] Stabilize completions (#18650)
Specifically, this PR reverts "Make completions an opt-in LSP feature
(#17921)",
corresponding to commit 51e2effd2d
.
In practice, this means you don't need to opt into completions working
by enabling experimental features. i.e., I was able to remove this from
my LSP configuration:
```
"experimental": {
"completions": {
"enable": true
}
},
```
There's still a lot of work left to do to make completions awesome, but
I think it's in a state where it would be useful to get real user
feedback. It's also meaningfully using ty to provide completions that
use type information.
Ref astral-sh/ty#86
This commit is contained in:
parent
2f3bd24900
commit
869d7bf9a8
4 changed files with 7 additions and 39 deletions
|
@ -9,7 +9,6 @@ use ruff_text_size::{Ranged, TextRange, TextSize};
|
||||||
use crate::Db;
|
use crate::Db;
|
||||||
use crate::find_node::covering_node;
|
use crate::find_node::covering_node;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Completion {
|
pub struct Completion {
|
||||||
pub label: String,
|
pub label: String,
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use self::schedule::spawn_main_loop;
|
use self::schedule::spawn_main_loop;
|
||||||
use crate::PositionEncoding;
|
use crate::PositionEncoding;
|
||||||
use crate::session::{AllSettings, ClientSettings, Experimental, Session};
|
use crate::session::{AllSettings, ClientSettings, Session};
|
||||||
use lsp_server::Connection;
|
use lsp_server::Connection;
|
||||||
use lsp_types::{
|
use lsp_types::{
|
||||||
ClientCapabilities, DiagnosticOptions, DiagnosticServerCapabilities, HoverProviderCapability,
|
ClientCapabilities, DiagnosticOptions, DiagnosticServerCapabilities, HoverProviderCapability,
|
||||||
|
@ -53,8 +53,7 @@ impl Server {
|
||||||
|
|
||||||
let client_capabilities = init_params.capabilities;
|
let client_capabilities = init_params.capabilities;
|
||||||
let position_encoding = Self::find_best_position_encoding(&client_capabilities);
|
let position_encoding = Self::find_best_position_encoding(&client_capabilities);
|
||||||
let server_capabilities =
|
let server_capabilities = Self::server_capabilities(position_encoding);
|
||||||
Self::server_capabilities(position_encoding, global_settings.experimental.as_ref());
|
|
||||||
|
|
||||||
let connection = connection.initialize_finish(
|
let connection = connection.initialize_finish(
|
||||||
id,
|
id,
|
||||||
|
@ -154,10 +153,7 @@ impl Server {
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn server_capabilities(
|
fn server_capabilities(position_encoding: PositionEncoding) -> ServerCapabilities {
|
||||||
position_encoding: PositionEncoding,
|
|
||||||
experimental: Option<&Experimental>,
|
|
||||||
) -> ServerCapabilities {
|
|
||||||
ServerCapabilities {
|
ServerCapabilities {
|
||||||
position_encoding: Some(position_encoding.into()),
|
position_encoding: Some(position_encoding.into()),
|
||||||
diagnostic_provider: Some(DiagnosticServerCapabilities::Options(DiagnosticOptions {
|
diagnostic_provider: Some(DiagnosticServerCapabilities::Options(DiagnosticOptions {
|
||||||
|
@ -177,12 +173,10 @@ impl Server {
|
||||||
inlay_hint_provider: Some(lsp_types::OneOf::Right(
|
inlay_hint_provider: Some(lsp_types::OneOf::Right(
|
||||||
InlayHintServerCapabilities::Options(InlayHintOptions::default()),
|
InlayHintServerCapabilities::Options(InlayHintOptions::default()),
|
||||||
)),
|
)),
|
||||||
completion_provider: experimental
|
completion_provider: Some(lsp_types::CompletionOptions {
|
||||||
.is_some_and(Experimental::is_completions_enabled)
|
trigger_characters: Some(vec!['.'.to_string()]),
|
||||||
.then_some(lsp_types::CompletionOptions {
|
..Default::default()
|
||||||
trigger_characters: Some(vec!['.'.to_string()]),
|
}),
|
||||||
..Default::default()
|
|
||||||
}),
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ pub(crate) use self::capabilities::ResolvedClientCapabilities;
|
||||||
pub use self::index::DocumentQuery;
|
pub use self::index::DocumentQuery;
|
||||||
pub(crate) use self::settings::AllSettings;
|
pub(crate) use self::settings::AllSettings;
|
||||||
pub use self::settings::ClientSettings;
|
pub use self::settings::ClientSettings;
|
||||||
pub(crate) use self::settings::Experimental;
|
|
||||||
use crate::document::{DocumentKey, DocumentVersion, NotebookDocument};
|
use crate::document::{DocumentKey, DocumentVersion, NotebookDocument};
|
||||||
use crate::session::request_queue::RequestQueue;
|
use crate::session::request_queue::RequestQueue;
|
||||||
use crate::system::{AnySystemPath, LSPSystem};
|
use crate::system::{AnySystemPath, LSPSystem};
|
||||||
|
|
|
@ -7,35 +7,11 @@ use serde::Deserialize;
|
||||||
/// Maps a workspace URI to its associated client settings. Used during server initialization.
|
/// Maps a workspace URI to its associated client settings. Used during server initialization.
|
||||||
pub(crate) type WorkspaceSettingsMap = FxHashMap<Url, ClientSettings>;
|
pub(crate) type WorkspaceSettingsMap = FxHashMap<Url, ClientSettings>;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Default)]
|
|
||||||
#[cfg_attr(test, derive(PartialEq, Eq))]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
struct Completions {
|
|
||||||
enable: Option<bool>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Default)]
|
|
||||||
#[cfg_attr(test, derive(PartialEq, Eq))]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub(crate) struct Experimental {
|
|
||||||
completions: Option<Completions>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Experimental {
|
|
||||||
/// Returns `true` if completions are enabled in the settings.
|
|
||||||
pub(crate) fn is_completions_enabled(&self) -> bool {
|
|
||||||
self.completions
|
|
||||||
.as_ref()
|
|
||||||
.is_some_and(|completions| completions.enable.unwrap_or_default())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This is a direct representation of the settings schema sent by the client.
|
/// This is a direct representation of the settings schema sent by the client.
|
||||||
#[derive(Debug, Deserialize, Default)]
|
#[derive(Debug, Deserialize, Default)]
|
||||||
#[cfg_attr(test, derive(PartialEq, Eq))]
|
#[cfg_attr(test, derive(PartialEq, Eq))]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct ClientSettings {
|
pub struct ClientSettings {
|
||||||
pub(crate) experimental: Option<Experimental>,
|
|
||||||
// These settings are only needed for tracing, and are only read from the global configuration.
|
// These settings are only needed for tracing, and are only read from the global configuration.
|
||||||
// These will not be in the resolved settings.
|
// These will not be in the resolved settings.
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue