Skip to content

Commit e90c42a

Browse files
committed
refactor(lsp-client): change transformation to from
1 parent cb51dd6 commit e90c42a

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

src/app/lsp_server/command_generator.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use serde_json::{Value, json};
2-
use tower_lsp::lsp_types::{Location, Range, Url};
2+
use tower_lsp::lsp_types::{CodeLens, Command, Location, Range, Url};
33

44
use crate::app::lsp_server::supported_commands::SupportedCommands;
55
use crate::infra::{parse_compose_file, parse_dockerfile};
@@ -31,6 +31,30 @@ impl From<SupportedCommands> for CommandInfo {
3131
}
3232
}
3333

34+
impl From<CommandInfo> for Command {
35+
fn from(value: CommandInfo) -> Self {
36+
Command {
37+
title: value.title,
38+
command: value.command,
39+
arguments: value.arguments,
40+
}
41+
}
42+
}
43+
44+
impl From<CommandInfo> for CodeLens {
45+
fn from(value: CommandInfo) -> Self {
46+
CodeLens {
47+
range: value.range,
48+
command: Some(Command {
49+
title: value.title,
50+
command: value.command,
51+
arguments: value.arguments,
52+
}),
53+
data: None,
54+
}
55+
}
56+
}
57+
3458
pub fn generate_commands_for_uri(uri: &Url, content: &str) -> Vec<CommandInfo> {
3559
let file_uri = uri.as_str();
3660

src/app/lsp_server/lsp_server_inner.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use serde_json::Value;
22
use tower_lsp::jsonrpc::{Error, ErrorCode, Result};
33
use tower_lsp::lsp_types::{
44
CodeActionOrCommand, CodeActionParams, CodeActionProviderCapability, CodeActionResponse,
5-
CodeLens, CodeLensOptions, CodeLensParams, Command, DidChangeConfigurationParams,
5+
CodeLens, CodeLensOptions, CodeLensParams, DidChangeConfigurationParams,
66
DidChangeTextDocumentParams, DidOpenTextDocumentParams, ExecuteCommandOptions,
77
ExecuteCommandParams, InitializeParams, InitializeResult, InitializedParams, MessageType,
88
ServerCapabilities, TextDocumentSyncCapability, TextDocumentSyncKind,
@@ -150,13 +150,7 @@ where
150150
let code_actions: Vec<CodeActionOrCommand> = commands
151151
.into_iter()
152152
.filter(|cmd| cmd.range.start.line == params.range.start.line)
153-
.map(|cmd| {
154-
CodeActionOrCommand::Command(Command {
155-
title: cmd.title,
156-
command: cmd.command,
157-
arguments: cmd.arguments,
158-
})
159-
})
153+
.map(|cmd| CodeActionOrCommand::Command(cmd.into()))
160154
.collect();
161155

162156
Ok(Some(code_actions))
@@ -166,18 +160,7 @@ where
166160
let commands = self
167161
.get_commands_for_document(&params.text_document.uri)
168162
.await?;
169-
let code_lenses = commands
170-
.into_iter()
171-
.map(|cmd| CodeLens {
172-
range: cmd.range,
173-
command: Some(Command {
174-
title: cmd.title,
175-
command: cmd.command,
176-
arguments: cmd.arguments,
177-
}),
178-
data: None,
179-
})
180-
.collect();
163+
let code_lenses = commands.into_iter().map(|cmd| cmd.into()).collect();
181164

182165
Ok(Some(code_lenses))
183166
}

0 commit comments

Comments
 (0)