Skip to content

Commit af36596

Browse files
ok
1 parent c923810 commit af36596

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

crates/pgt_lsp/src/handlers/code_actions.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
use crate::session::Session;
2+
use anyhow::Result;
3+
use pgt_text_size::{TextRange, TextSize};
24
use tower_lsp::lsp_types::{self, CodeAction, CodeActionDisabled, CodeActionOrCommand, Command};
35

4-
use pgt_workspace::code_actions::{CodeActionKind, CommandAction, CommandActionCategory};
6+
use pgt_workspace::code_actions::{
7+
CodeActionKind, CodeActionsParams, CommandAction, CommandActionCategory,
8+
};
59

610
pub fn get_actions(
711
session: &Session,
@@ -12,7 +16,10 @@ pub fn get_actions(
1216

1317
let workspace_actions = session.workspace.pull_code_actions(CodeActionsParams {
1418
path,
15-
range: params.range,
19+
range: Some(TextRange::new(
20+
TextSize::new(params.range.start.character),
21+
TextSize::new(params.range.end.character),
22+
)),
1623
only: vec![],
1724
skip: vec![],
1825
})?;
@@ -22,20 +29,23 @@ pub fn get_actions(
2229
.into_iter()
2330
.filter_map(|action| match action.kind {
2431
CodeActionKind::Command(command) => {
25-
let title = match command.category {
32+
let title = match &command.category {
2633
CommandActionCategory::ExecuteStatement(stmt) => {
27-
format!("Execute Statement: {}...", stmt[..50])
34+
format!(
35+
"Execute Statement: {}...",
36+
stmt.chars().take(50).collect::<String>()
37+
)
2838
}
2939
};
3040

3141
return Some(CodeAction {
32-
title,
42+
title: title.clone(),
3343
command: Some(Command {
34-
title,
44+
title: title.clone(),
3545
command: command.category.into(),
3646
arguments: None,
3747
}),
38-
disabled: action
48+
disabled: actio
3949
.disabled_reason
4050
.map(|reason| CodeActionDisabled { reason }),
4151
..Default::default()

crates/pgt_lsp/src/server.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,11 @@ impl LanguageServer for LSPServer {
254254
}
255255

256256
#[tracing::instrument(level = "trace", skip(self))]
257-
async fn code_action(&self, params: CodeActionParams) -> Result<Option<CodeActionResponse>> {
258-
let actions = handlers::code_actions::get_actions(session, params);
257+
async fn code_action(&self, params: CodeActionParams) -> LspResult<Option<CodeActionResponse>> {
258+
match handlers::code_actions::get_actions(&self.session, params) {
259+
Ok(result) => LspResult::Ok(Some(result)),
260+
Err(e) => LspResult::Err(into_lsp_error(e)),
261+
}
259262
}
260263
}
261264

0 commit comments

Comments
 (0)