mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:18 +00:00
[ty] Add LSP debug information command (#20379)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
12086dfa69
commit
eb354608d2
10 changed files with 458 additions and 1 deletions
|
@ -10,6 +10,8 @@ use lsp_types::{
|
|||
|
||||
use crate::PositionEncoding;
|
||||
use crate::session::GlobalSettings;
|
||||
use lsp_types as types;
|
||||
use std::str::FromStr;
|
||||
|
||||
bitflags::bitflags! {
|
||||
/// Represents the resolved client capabilities for the language server.
|
||||
|
@ -37,6 +39,36 @@ bitflags::bitflags! {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub(crate) enum SupportedCommand {
|
||||
Debug,
|
||||
}
|
||||
|
||||
impl SupportedCommand {
|
||||
/// Returns the identifier of the command.
|
||||
const fn identifier(self) -> &'static str {
|
||||
match self {
|
||||
SupportedCommand::Debug => "ty.printDebugInformation",
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns all the commands that the server currently supports.
|
||||
const fn all() -> [SupportedCommand; 1] {
|
||||
[SupportedCommand::Debug]
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for SupportedCommand {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(name: &str) -> anyhow::Result<Self, Self::Err> {
|
||||
Ok(match name {
|
||||
"ty.printDebugInformation" => Self::Debug,
|
||||
_ => return Err(anyhow::anyhow!("Invalid command `{name}`")),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ResolvedClientCapabilities {
|
||||
/// Returns `true` if the client supports workspace diagnostic refresh.
|
||||
pub(crate) const fn supports_workspace_diagnostic_refresh(self) -> bool {
|
||||
|
@ -319,6 +351,15 @@ pub(crate) fn server_capabilities(
|
|||
|
||||
ServerCapabilities {
|
||||
position_encoding: Some(position_encoding.into()),
|
||||
execute_command_provider: Some(types::ExecuteCommandOptions {
|
||||
commands: SupportedCommand::all()
|
||||
.map(|command| command.identifier().to_string())
|
||||
.to_vec(),
|
||||
work_done_progress_options: WorkDoneProgressOptions {
|
||||
work_done_progress: Some(false),
|
||||
},
|
||||
}),
|
||||
|
||||
diagnostic_provider,
|
||||
text_document_sync: Some(TextDocumentSyncCapability::Options(
|
||||
TextDocumentSyncOptions {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue