|
|
@ -121,7 +121,7 @@ enum Align {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn align_view(doc: &Document, view: &mut View, align: Align) {
|
|
|
|
fn align_view(doc: &Document, view: &mut View, align: Align) {
|
|
|
|
let pos = doc.selection(view.id).cursor();
|
|
|
|
let pos = doc.selection(view.id).cursor(doc.text().slice(..));
|
|
|
|
let line = doc.text().char_to_line(pos);
|
|
|
|
let line = doc.text().char_to_line(pos);
|
|
|
|
|
|
|
|
|
|
|
|
let relative = match align {
|
|
|
|
let relative = match align {
|
|
|
@ -868,7 +868,10 @@ fn switch_to_lowercase(cx: &mut Context) {
|
|
|
|
fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
|
|
|
|
fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
|
|
|
|
use Direction::*;
|
|
|
|
use Direction::*;
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let cursor = coords_at_pos(doc.text().slice(..), doc.selection(view.id).cursor());
|
|
|
|
let cursor = coords_at_pos(
|
|
|
|
|
|
|
|
doc.text().slice(..),
|
|
|
|
|
|
|
|
doc.selection(view.id).cursor(doc.text().slice(..)),
|
|
|
|
|
|
|
|
);
|
|
|
|
let doc_last_line = doc.text().len_lines() - 1;
|
|
|
|
let doc_last_line = doc.text().len_lines() - 1;
|
|
|
|
|
|
|
|
|
|
|
|
let last_line = view.last_line(doc);
|
|
|
|
let last_line = view.last_line(doc);
|
|
|
@ -1038,7 +1041,7 @@ fn split_selection_on_newline(cx: &mut Context) {
|
|
|
|
fn search_impl(doc: &mut Document, view: &mut View, contents: &str, regex: &Regex, extend: bool) {
|
|
|
|
fn search_impl(doc: &mut Document, view: &mut View, contents: &str, regex: &Regex, extend: bool) {
|
|
|
|
let text = doc.text();
|
|
|
|
let text = doc.text();
|
|
|
|
let selection = doc.selection(view.id);
|
|
|
|
let selection = doc.selection(view.id);
|
|
|
|
let start = text.char_to_byte(selection.cursor());
|
|
|
|
let start = text.char_to_byte(selection.cursor(text.slice(..)));
|
|
|
|
|
|
|
|
|
|
|
|
// use find_at to find the next match after the cursor, loop around the end
|
|
|
|
// use find_at to find the next match after the cursor, loop around the end
|
|
|
|
// Careful, `Regex` uses `bytes` as offsets, not character indices!
|
|
|
|
// Careful, `Regex` uses `bytes` as offsets, not character indices!
|
|
|
@ -2446,7 +2449,11 @@ fn goto_definition(cx: &mut Context) {
|
|
|
|
|
|
|
|
|
|
|
|
let offset_encoding = language_server.offset_encoding();
|
|
|
|
let offset_encoding = language_server.offset_encoding();
|
|
|
|
|
|
|
|
|
|
|
|
let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
|
|
|
|
let pos = pos_to_lsp_pos(
|
|
|
|
|
|
|
|
doc.text(),
|
|
|
|
|
|
|
|
doc.selection(view.id).cursor(doc.text().slice(..)),
|
|
|
|
|
|
|
|
offset_encoding,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: handle fails
|
|
|
|
// TODO: handle fails
|
|
|
|
let future = language_server.goto_definition(doc.identifier(), pos, None);
|
|
|
|
let future = language_server.goto_definition(doc.identifier(), pos, None);
|
|
|
@ -2483,7 +2490,11 @@ fn goto_type_definition(cx: &mut Context) {
|
|
|
|
|
|
|
|
|
|
|
|
let offset_encoding = language_server.offset_encoding();
|
|
|
|
let offset_encoding = language_server.offset_encoding();
|
|
|
|
|
|
|
|
|
|
|
|
let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
|
|
|
|
let pos = pos_to_lsp_pos(
|
|
|
|
|
|
|
|
doc.text(),
|
|
|
|
|
|
|
|
doc.selection(view.id).cursor(doc.text().slice(..)),
|
|
|
|
|
|
|
|
offset_encoding,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: handle fails
|
|
|
|
// TODO: handle fails
|
|
|
|
let future = language_server.goto_type_definition(doc.identifier(), pos, None);
|
|
|
|
let future = language_server.goto_type_definition(doc.identifier(), pos, None);
|
|
|
@ -2520,7 +2531,11 @@ fn goto_implementation(cx: &mut Context) {
|
|
|
|
|
|
|
|
|
|
|
|
let offset_encoding = language_server.offset_encoding();
|
|
|
|
let offset_encoding = language_server.offset_encoding();
|
|
|
|
|
|
|
|
|
|
|
|
let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
|
|
|
|
let pos = pos_to_lsp_pos(
|
|
|
|
|
|
|
|
doc.text(),
|
|
|
|
|
|
|
|
doc.selection(view.id).cursor(doc.text().slice(..)),
|
|
|
|
|
|
|
|
offset_encoding,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: handle fails
|
|
|
|
// TODO: handle fails
|
|
|
|
let future = language_server.goto_implementation(doc.identifier(), pos, None);
|
|
|
|
let future = language_server.goto_implementation(doc.identifier(), pos, None);
|
|
|
@ -2557,7 +2572,11 @@ fn goto_reference(cx: &mut Context) {
|
|
|
|
|
|
|
|
|
|
|
|
let offset_encoding = language_server.offset_encoding();
|
|
|
|
let offset_encoding = language_server.offset_encoding();
|
|
|
|
|
|
|
|
|
|
|
|
let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
|
|
|
|
let pos = pos_to_lsp_pos(
|
|
|
|
|
|
|
|
doc.text(),
|
|
|
|
|
|
|
|
doc.selection(view.id).cursor(doc.text().slice(..)),
|
|
|
|
|
|
|
|
offset_encoding,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: handle fails
|
|
|
|
// TODO: handle fails
|
|
|
|
let future = language_server.goto_reference(doc.identifier(), pos, None);
|
|
|
|
let future = language_server.goto_reference(doc.identifier(), pos, None);
|
|
|
@ -2616,7 +2635,7 @@ fn goto_next_diag(cx: &mut Context) {
|
|
|
|
let editor = &mut cx.editor;
|
|
|
|
let editor = &mut cx.editor;
|
|
|
|
let (view, doc) = current!(editor);
|
|
|
|
let (view, doc) = current!(editor);
|
|
|
|
|
|
|
|
|
|
|
|
let cursor_pos = doc.selection(view.id).cursor();
|
|
|
|
let cursor_pos = doc.selection(view.id).cursor(doc.text().slice(..));
|
|
|
|
let diag = if let Some(diag) = doc
|
|
|
|
let diag = if let Some(diag) = doc
|
|
|
|
.diagnostics()
|
|
|
|
.diagnostics()
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
@ -2637,7 +2656,7 @@ fn goto_prev_diag(cx: &mut Context) {
|
|
|
|
let editor = &mut cx.editor;
|
|
|
|
let editor = &mut cx.editor;
|
|
|
|
let (view, doc) = current!(editor);
|
|
|
|
let (view, doc) = current!(editor);
|
|
|
|
|
|
|
|
|
|
|
|
let cursor_pos = doc.selection(view.id).cursor();
|
|
|
|
let cursor_pos = doc.selection(view.id).cursor(doc.text().slice(..));
|
|
|
|
let diag = if let Some(diag) = doc
|
|
|
|
let diag = if let Some(diag) = doc
|
|
|
|
.diagnostics()
|
|
|
|
.diagnostics()
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
@ -2665,7 +2684,7 @@ fn signature_help(cx: &mut Context) {
|
|
|
|
|
|
|
|
|
|
|
|
let pos = pos_to_lsp_pos(
|
|
|
|
let pos = pos_to_lsp_pos(
|
|
|
|
doc.text(),
|
|
|
|
doc.text(),
|
|
|
|
doc.selection(view.id).cursor(),
|
|
|
|
doc.selection(view.id).cursor(doc.text().slice(..)),
|
|
|
|
language_server.offset_encoding(),
|
|
|
|
language_server.offset_encoding(),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -3403,13 +3422,14 @@ fn completion(cx: &mut Context) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let offset_encoding = language_server.offset_encoding();
|
|
|
|
let offset_encoding = language_server.offset_encoding();
|
|
|
|
|
|
|
|
let cursor = doc.selection(view.id).cursor(doc.text().slice(..));
|
|
|
|
|
|
|
|
|
|
|
|
let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
|
|
|
|
let pos = pos_to_lsp_pos(doc.text(), cursor, offset_encoding);
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: handle fails
|
|
|
|
// TODO: handle fails
|
|
|
|
let future = language_server.completion(doc.identifier(), pos, None);
|
|
|
|
let future = language_server.completion(doc.identifier(), pos, None);
|
|
|
|
|
|
|
|
|
|
|
|
let trigger_offset = doc.selection(view.id).cursor();
|
|
|
|
let trigger_offset = cursor;
|
|
|
|
|
|
|
|
|
|
|
|
cx.callback(
|
|
|
|
cx.callback(
|
|
|
|
future,
|
|
|
|
future,
|
|
|
@ -3459,7 +3479,7 @@ fn hover(cx: &mut Context) {
|
|
|
|
|
|
|
|
|
|
|
|
let pos = pos_to_lsp_pos(
|
|
|
|
let pos = pos_to_lsp_pos(
|
|
|
|
doc.text(),
|
|
|
|
doc.text(),
|
|
|
|
doc.selection(view.id).cursor(),
|
|
|
|
doc.selection(view.id).cursor(doc.text().slice(..)),
|
|
|
|
language_server.offset_encoding(),
|
|
|
|
language_server.offset_encoding(),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -3525,7 +3545,7 @@ fn match_brackets(cx: &mut Context) {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(syntax) = doc.syntax() {
|
|
|
|
if let Some(syntax) = doc.syntax() {
|
|
|
|
let pos = doc.selection(view.id).cursor();
|
|
|
|
let pos = doc.selection(view.id).cursor(doc.text().slice(..));
|
|
|
|
if let Some(pos) = match_brackets::find(syntax, doc.text(), pos) {
|
|
|
|
if let Some(pos) = match_brackets::find(syntax, doc.text(), pos) {
|
|
|
|
let selection = Selection::point(pos);
|
|
|
|
let selection = Selection::point(pos);
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
@ -3629,7 +3649,7 @@ fn align_view_bottom(cx: &mut Context) {
|
|
|
|
|
|
|
|
|
|
|
|
fn align_view_middle(cx: &mut Context) {
|
|
|
|
fn align_view_middle(cx: &mut Context) {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let pos = doc.selection(view.id).cursor();
|
|
|
|
let pos = doc.selection(view.id).cursor(doc.text().slice(..));
|
|
|
|
let pos = coords_at_pos(doc.text().slice(..), pos);
|
|
|
|
let pos = coords_at_pos(doc.text().slice(..), pos);
|
|
|
|
|
|
|
|
|
|
|
|
const OFFSET: usize = 7; // gutters
|
|
|
|
const OFFSET: usize = 7; // gutters
|
|
|
|