mirror of https://github.com/lapce/lapce.git
code actions change to cursor
This commit is contained in:
parent
5f571c8b9f
commit
f6d1ce926a
|
@ -1399,7 +1399,7 @@ pub fn go_to_definition(
|
|||
pub fn set_code_actions(
|
||||
&mut self,
|
||||
buffer_id: BufferId,
|
||||
line: usize,
|
||||
offset: usize,
|
||||
rev: u64,
|
||||
value: Value,
|
||||
) -> Option<()> {
|
||||
|
@ -1417,11 +1417,12 @@ pub fn set_code_actions(
|
|||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
buffer.code_actions.insert(line, resp);
|
||||
buffer.code_actions.insert(offset, resp);
|
||||
|
||||
let editor = self.editors.get(&self.active)?;
|
||||
if editor.buffer_id == Some(buffer_id)
|
||||
&& buffer.line_of_offset(editor.selection.get_cursor_offset()) == line
|
||||
&& buffer.line_of_offset(editor.selection.get_cursor_offset())
|
||||
== buffer.line_of_offset(offset)
|
||||
{
|
||||
editor.request_paint();
|
||||
}
|
||||
|
@ -1505,11 +1506,11 @@ pub fn get_code_actions(&self) -> Option<()> {
|
|||
let editor = self.editors.get(&self.active)?;
|
||||
let buffer_id = editor.buffer_id.clone()?;
|
||||
let buffer = self.buffers.get(&buffer_id)?;
|
||||
let current_line =
|
||||
buffer.line_of_offset(editor.selection.get_cursor_offset());
|
||||
if buffer.code_actions.get(¤t_line).is_none() {
|
||||
let offset = editor.selection.get_cursor_offset();
|
||||
let prev_offset = buffer.prev_code_boundary(offset);
|
||||
if buffer.code_actions.get(&prev_offset).is_none() {
|
||||
let state = LAPCE_APP_STATE.get_tab_state(&self.window_id, &self.tab_id);
|
||||
state.lsp.lock().get_code_actions(current_line, buffer);
|
||||
state.lsp.lock().get_code_actions(prev_offset, buffer);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
@ -1568,9 +1569,10 @@ pub fn run_command(
|
|||
let editor = self.editors.get_mut(&self.active)?;
|
||||
let buffer_id = editor.buffer_id.clone()?;
|
||||
let buffer = self.buffers.get_mut(&buffer_id)?;
|
||||
let current_line =
|
||||
buffer.line_of_offset(editor.selection.get_cursor_offset());
|
||||
let code_actions = buffer.code_actions.get(¤t_line)?;
|
||||
let code_action_offset = buffer
|
||||
.prev_code_boundary(editor.selection.get_cursor_offset());
|
||||
let code_actions =
|
||||
buffer.code_actions.get(&code_action_offset)?;
|
||||
let code_action = &code_actions[self.current_code_actions];
|
||||
let rev = buffer.rev;
|
||||
match code_action {
|
||||
|
@ -1614,9 +1616,10 @@ pub fn run_command(
|
|||
let editor = self.editors.get_mut(&self.active)?;
|
||||
let buffer_id = editor.buffer_id.clone()?;
|
||||
let buffer = self.buffers.get_mut(&buffer_id)?;
|
||||
let current_line =
|
||||
buffer.line_of_offset(editor.selection.get_cursor_offset());
|
||||
let code_actions = buffer.code_actions.get(¤t_line)?;
|
||||
let code_action_offset = buffer
|
||||
.prev_code_boundary(editor.selection.get_cursor_offset());
|
||||
let code_actions =
|
||||
buffer.code_actions.get(&code_action_offset)?;
|
||||
self.current_code_actions = Movement::Down.update_index(
|
||||
self.current_code_actions,
|
||||
code_actions.len(),
|
||||
|
@ -1640,9 +1643,10 @@ pub fn run_command(
|
|||
let editor = self.editors.get_mut(&self.active)?;
|
||||
let buffer_id = editor.buffer_id.clone()?;
|
||||
let buffer = self.buffers.get_mut(&buffer_id)?;
|
||||
let current_line =
|
||||
buffer.line_of_offset(editor.selection.get_cursor_offset());
|
||||
let code_actions = buffer.code_actions.get(¤t_line)?;
|
||||
let code_action_offset = buffer
|
||||
.prev_code_boundary(editor.selection.get_cursor_offset());
|
||||
let code_actions =
|
||||
buffer.code_actions.get(&code_action_offset)?;
|
||||
self.current_code_actions = Movement::Up.update_index(
|
||||
self.current_code_actions,
|
||||
code_actions.len(),
|
||||
|
@ -2032,9 +2036,9 @@ pub fn run_command(
|
|||
let editor = self.editors.get_mut(&self.active)?;
|
||||
let buffer_id = editor.buffer_id.clone()?;
|
||||
let buffer = self.buffers.get_mut(&buffer_id)?;
|
||||
let line =
|
||||
buffer.line_of_offset(editor.selection.get_cursor_offset());
|
||||
let actions = buffer.code_actions.get(&line)?;
|
||||
let code_action_offset =
|
||||
buffer.prev_code_boundary(editor.selection.get_cursor_offset());
|
||||
let actions = buffer.code_actions.get(&code_action_offset)?;
|
||||
if actions.len() == 0 {
|
||||
return None;
|
||||
}
|
||||
|
@ -2855,13 +2859,13 @@ fn paint_code_action_edits(
|
|||
&mut self,
|
||||
ctx: &mut PaintCtx,
|
||||
buffer: &Buffer,
|
||||
line: usize,
|
||||
offset: usize,
|
||||
current_code_actions: usize,
|
||||
width: f64,
|
||||
env: &Env,
|
||||
) -> Option<()> {
|
||||
let line_height = env.get(LapceTheme::EDITOR_LINE_HEIGHT);
|
||||
let code_actions = buffer.code_actions.get(&line)?;
|
||||
let code_actions = buffer.code_actions.get(&offset)?;
|
||||
if code_actions.len() == 0 {
|
||||
return None;
|
||||
}
|
||||
|
@ -2885,7 +2889,16 @@ fn paint_code_action_edits(
|
|||
)
|
||||
.to_string();
|
||||
let left_col = match line {
|
||||
_ if line == start_line => start_col,
|
||||
_ if line == start_line => {
|
||||
let line_len = buffer.line_len(line);
|
||||
if line_len == 0 {
|
||||
0
|
||||
} else if start_col > line_len - 1 {
|
||||
line_len - 1
|
||||
} else {
|
||||
start_col
|
||||
}
|
||||
}
|
||||
_ => 0,
|
||||
};
|
||||
let x0 = (left_col
|
||||
|
@ -2893,7 +2906,16 @@ fn paint_code_action_edits(
|
|||
as f64
|
||||
* width;
|
||||
let right_col = match line {
|
||||
_ if line == end_line => end_col,
|
||||
_ if line == end_line => {
|
||||
let line_len = buffer.line_len(line);
|
||||
if line_len == 0 {
|
||||
0
|
||||
} else if end_col > line_len - 1 {
|
||||
line_len - 1
|
||||
} else {
|
||||
end_col
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
buffer.offset_of_line(line + 1)
|
||||
- buffer.offset_of_line(line)
|
||||
|
@ -3116,6 +3138,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceUIState, env: &Env) {
|
|||
let buffer = editor_split.buffers.get(&buffer_id).unwrap();
|
||||
let editor = editor_split.editors.get(&self.view_id).unwrap();
|
||||
let editor_offset = editor.selection.get_cursor_offset();
|
||||
let code_action_offset = buffer.prev_code_boundary(editor_offset);
|
||||
let cursor = buffer.offset_to_line_col(editor_offset);
|
||||
|
||||
let mode = editor_split.mode.clone();
|
||||
|
@ -3125,7 +3148,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceUIState, env: &Env) {
|
|||
self.paint_code_action_edits(
|
||||
ctx,
|
||||
buffer,
|
||||
cursor.0,
|
||||
code_action_offset,
|
||||
editor_split.current_code_actions,
|
||||
width,
|
||||
env,
|
||||
|
@ -3234,7 +3257,9 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceUIState, env: &Env) {
|
|||
}
|
||||
}
|
||||
if editor_split.active == self.view_id && line == cursor.0 {
|
||||
if let Some(code_actions) = buffer.code_actions.get(&line) {
|
||||
if let Some(code_actions) =
|
||||
buffer.code_actions.get(&code_action_offset)
|
||||
{
|
||||
if code_actions.len() > 0 {
|
||||
let svg = SvgData::from_str(
|
||||
ICONS_DIR
|
||||
|
@ -3279,9 +3304,11 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceUIState, env: &Env) {
|
|||
let x0 = if line == start.line as usize {
|
||||
start.character as f64 * width
|
||||
} else {
|
||||
buffer.first_non_blank_character_on_line(line)
|
||||
as f64
|
||||
* width
|
||||
let (_, col) = buffer.offset_to_line_col(
|
||||
buffer
|
||||
.first_non_blank_character_on_line(line),
|
||||
);
|
||||
col as f64 * width
|
||||
};
|
||||
let x1 = if line == end.line as usize {
|
||||
end.character as f64 * width
|
||||
|
@ -3348,7 +3375,8 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceUIState, env: &Env) {
|
|||
* 3
|
||||
+ cursor.1) as f64
|
||||
* width;
|
||||
if let Some(code_actions) = buffer.code_actions.get(&line) {
|
||||
if let Some(code_actions) = buffer.code_actions.get(&code_action_offset)
|
||||
{
|
||||
if code_actions.len() > 0 {
|
||||
let action_text_layouts: Vec<TextLayout<String>> = code_actions
|
||||
.iter()
|
||||
|
|
|
@ -167,15 +167,17 @@ pub fn get_completion(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_code_actions(&self, line: usize, buffer: &Buffer) {
|
||||
let start_offset = buffer.first_non_blank_character_on_line(line);
|
||||
let end_offset = buffer.offset_of_line(line + 1) - 1;
|
||||
pub fn get_code_actions(&self, offset: usize, buffer: &Buffer) {
|
||||
// let start_offset = buffer.first_non_blank_character_on_line(line);
|
||||
// let end_offset = buffer.offset_of_line(line + 1) - 1;
|
||||
let range = Range {
|
||||
start: buffer.offset_to_position(start_offset),
|
||||
end: buffer.offset_to_position(end_offset),
|
||||
start: buffer.offset_to_position(offset),
|
||||
end: buffer.offset_to_position(offset),
|
||||
};
|
||||
if let Some(client) = self.clients.get(&buffer.language_id) {
|
||||
client.lock().get_code_actions(buffer, range.clone());
|
||||
client
|
||||
.lock()
|
||||
.get_code_actions(buffer, offset, range.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -388,7 +390,12 @@ pub fn get_completion(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn get_code_actions(&mut self, buffer: &Buffer, range: Range) {
|
||||
pub fn get_code_actions(
|
||||
&mut self,
|
||||
buffer: &Buffer,
|
||||
offset: usize,
|
||||
range: Range,
|
||||
) {
|
||||
let uri = self.get_uri(buffer);
|
||||
let window_id = self.window_id;
|
||||
let tab_id = self.tab_id;
|
||||
|
@ -401,12 +408,7 @@ pub fn get_code_actions(&mut self, buffer: &Buffer, range: Range) {
|
|||
.get_tab_state(&window_id, &tab_id)
|
||||
.editor_split
|
||||
.lock()
|
||||
.set_code_actions(
|
||||
buffer_id,
|
||||
range.start.line as usize,
|
||||
rev,
|
||||
res,
|
||||
);
|
||||
.set_code_actions(buffer_id, offset, rev, res);
|
||||
});
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue