[ty] Add LSP debug information command (#20379)

Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
GF 2025-09-20 11:15:13 +00:00 committed by GitHub
parent 12086dfa69
commit eb354608d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 458 additions and 1 deletions

View file

@ -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 {