Skip to content

Commit bcb879c

Browse files
committed
progress
1 parent b72c5d3 commit bcb879c

File tree

4 files changed

+15
-28
lines changed

4 files changed

+15
-28
lines changed

crates/pgt_lsp/src/capabilities.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
use crate::adapters::{PositionEncoding, WideEncoding, negotiated_encoding};
2+
use crate::handlers::code_actions::command_id;
3+
use pgt_workspace::features::code_actions::CommandActionCategory;
4+
use strum::IntoEnumIterator;
25
use tower_lsp::lsp_types::{
36
ClientCapabilities, CompletionOptions, ExecuteCommandOptions, PositionEncodingKind,
47
SaveOptions, ServerCapabilities, TextDocumentSyncCapability, TextDocumentSyncKind,
@@ -47,8 +50,9 @@ pub(crate) fn server_capabilities(capabilities: &ClientCapabilities) -> ServerCa
4750
},
4851
}),
4952
execute_command_provider: Some(ExecuteCommandOptions {
50-
commands: available_command_ids(),
51-
53+
commands: CommandActionCategory::iter()
54+
.map(|c| command_id(&c))
55+
.collect::<Vec<String>>(),
5256
..Default::default()
5357
}),
5458
document_formatting_provider: None,
@@ -61,13 +65,3 @@ pub(crate) fn server_capabilities(capabilities: &ClientCapabilities) -> ServerCa
6165
..Default::default()
6266
}
6367
}
64-
65-
/// Returns all available command IDs for capability registration.
66-
/// Since CommandActionCategory has variants with data, we can't use strum::IntoEnumIterator.
67-
/// Instead, we manually list the command IDs we want to register.
68-
fn available_command_ids() -> Vec<String> {
69-
vec![
70-
"postgres-tools.executeStatement".to_string(),
71-
// Add other command IDs here as needed
72-
]
73-
}

crates/pgt_workspace/src/features/code_actions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub struct CommandAction {
4444
pub category: CommandActionCategory,
4545
}
4646

47-
#[derive(Debug, serde::Serialize, serde::Deserialize)]
47+
#[derive(Debug, serde::Serialize, serde::Deserialize, strum::EnumIter)]
4848
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
4949
pub enum CommandActionCategory {
5050
ExecuteStatement(StatementId),

crates/pgt_workspace/src/workspace/server.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ impl Workspace for WorkspaceServer {
626626
tracing::debug!("No statement found.");
627627
Ok(CompletionsResult::default())
628628
}
629-
Some((id, range, content, cst)) => {
629+
Some((_id, range, content, cst)) => {
630630
let position = params.position - range.start();
631631

632632
let items = pgt_completions::complete(pgt_completions::CompletionParams {
@@ -636,12 +636,6 @@ impl Workspace for WorkspaceServer {
636636
text: content,
637637
});
638638

639-
tracing::debug!(
640-
"Found {} completion items for statement with id {:?}",
641-
items.len(),
642-
id
643-
);
644-
645639
Ok(CompletionsResult { items })
646640
}
647641
}

crates/pgt_workspace/src/workspace/server/statement_identifier.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,20 @@ pub enum StatementId {
2727
},
2828
}
2929

30+
// this is only here for strum to work on the code actions enum
31+
impl Default for StatementId {
32+
fn default() -> Self {
33+
StatementId::Root { content: "".into() }
34+
}
35+
}
36+
3037
impl StatementId {
3138
pub fn new(statement: &str) -> Self {
3239
StatementId::Root {
3340
content: statement.into(),
3441
}
3542
}
3643

37-
/// Creates a child statement ID with the given content and parent content.
38-
pub fn new_child(child_content: &str, parent_content: &str) -> Self {
39-
StatementId::Child {
40-
content: child_content.into(),
41-
parent_content: parent_content.into(),
42-
}
43-
}
44-
4544
/// Use this if you need to create a matching `StatementId::Child` for `Root`.
4645
/// You cannot create a `Child` of a `Child`.
4746
/// Note: This method requires the child content to be provided.

0 commit comments

Comments
 (0)