mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-03 22:14:37 +00:00
refactor: add send_normal_action
This commit is contained in:
parent
953eac6218
commit
ff741d5235
2 changed files with 11 additions and 6 deletions
|
@ -16,7 +16,7 @@ use crate::server::{ELSResult, Server};
|
||||||
use crate::util;
|
use crate::util;
|
||||||
|
|
||||||
impl<Checker: BuildRunnable> Server<Checker> {
|
impl<Checker: BuildRunnable> Server<Checker> {
|
||||||
fn perform_eliminate_unused_vars_action(
|
fn send_eliminate_unused_vars_action(
|
||||||
&self,
|
&self,
|
||||||
_msg: &Value,
|
_msg: &Value,
|
||||||
uri: &Url,
|
uri: &Url,
|
||||||
|
@ -70,7 +70,7 @@ impl<Checker: BuildRunnable> Server<Checker> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn perform_code_action(&self, msg: &Value) -> ELSResult<()> {
|
pub(crate) fn send_code_action(&self, msg: &Value) -> ELSResult<()> {
|
||||||
Self::send_log(format!("code action requested: {msg}"))?;
|
Self::send_log(format!("code action requested: {msg}"))?;
|
||||||
let params = CodeActionParams::deserialize(&msg["params"])?;
|
let params = CodeActionParams::deserialize(&msg["params"])?;
|
||||||
let result = match params
|
let result = match params
|
||||||
|
@ -79,7 +79,8 @@ impl<Checker: BuildRunnable> Server<Checker> {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|kinds| kinds.first().map(|s| s.as_str()))
|
.and_then(|kinds| kinds.first().map(|s| s.as_str()))
|
||||||
{
|
{
|
||||||
Some("quickfix") | None => self.perform_quick_fix(msg, params)?,
|
Some("quickfix") => self.send_quick_fix(msg, params)?,
|
||||||
|
None => self.send_normal_action(msg, params)?,
|
||||||
Some(other) => {
|
Some(other) => {
|
||||||
Self::send_log(&format!("Unknown code action requested: {other}"))?;
|
Self::send_log(&format!("Unknown code action requested: {other}"))?;
|
||||||
vec![]
|
vec![]
|
||||||
|
@ -90,17 +91,21 @@ impl<Checker: BuildRunnable> Server<Checker> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn perform_quick_fix(
|
fn send_normal_action(
|
||||||
&self,
|
&self,
|
||||||
msg: &Value,
|
msg: &Value,
|
||||||
params: CodeActionParams,
|
params: CodeActionParams,
|
||||||
) -> ELSResult<Vec<CodeAction>> {
|
) -> ELSResult<Vec<CodeAction>> {
|
||||||
|
self.send_quick_fix(msg, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn send_quick_fix(&self, msg: &Value, params: CodeActionParams) -> ELSResult<Vec<CodeAction>> {
|
||||||
let mut result: Vec<CodeAction> = vec![];
|
let mut result: Vec<CodeAction> = vec![];
|
||||||
let uri = util::normalize_url(params.text_document.uri);
|
let uri = util::normalize_url(params.text_document.uri);
|
||||||
for diag in params.context.diagnostics.into_iter() {
|
for diag in params.context.diagnostics.into_iter() {
|
||||||
match &diag.message {
|
match &diag.message {
|
||||||
unused if unused.ends_with("is not used") => {
|
unused if unused.ends_with("is not used") => {
|
||||||
result.extend(self.perform_eliminate_unused_vars_action(msg, &uri, diag)?);
|
result.extend(self.send_eliminate_unused_vars_action(msg, &uri, diag)?);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
Self::send_log(&format!("Unknown diagnostic for action: {}", diag.message))?;
|
Self::send_log(&format!("Unknown diagnostic for action: {}", diag.message))?;
|
||||||
|
|
|
@ -338,7 +338,7 @@ impl<Checker: BuildRunnable> Server<Checker> {
|
||||||
"textDocument/references" => self.show_references(msg),
|
"textDocument/references" => self.show_references(msg),
|
||||||
"textDocument/semanticTokens/full" => self.get_semantic_tokens_full(msg),
|
"textDocument/semanticTokens/full" => self.get_semantic_tokens_full(msg),
|
||||||
"textDocument/inlayHint" => self.get_inlay_hint(msg),
|
"textDocument/inlayHint" => self.get_inlay_hint(msg),
|
||||||
"textDocument/codeAction" => self.perform_code_action(msg),
|
"textDocument/codeAction" => self.send_code_action(msg),
|
||||||
other => Self::send_error(Some(id), -32600, format!("{other} is not supported")),
|
other => Self::send_error(Some(id), -32600, format!("{other} is not supported")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue