Rebase cleanup/fixes and use lsp::CompletionItem in item_to_transaction directly
This commit is contained in:
parent
f8fa0d8a10
commit
2a512f7c48
3 changed files with 9 additions and 10 deletions
|
@ -682,7 +682,7 @@ impl Registry {
|
||||||
|
|
||||||
/// If this method is called, all documents that have a reference to language servers used by the language config have to refresh their language servers,
|
/// If this method is called, all documents that have a reference to language servers used by the language config have to refresh their language servers,
|
||||||
/// as it could be that language servers of these documents were stopped by this method.
|
/// as it could be that language servers of these documents were stopped by this method.
|
||||||
/// See [helix_view::editor::Editor::refresh_language_servers]
|
/// See helix_view::editor::Editor::refresh_language_servers
|
||||||
pub fn restart(
|
pub fn restart(
|
||||||
&mut self,
|
&mut self,
|
||||||
language_config: &LanguageConfiguration,
|
language_config: &LanguageConfiguration,
|
||||||
|
|
|
@ -4242,7 +4242,7 @@ pub fn completion(cx: &mut Context) {
|
||||||
.map(|language_server| {
|
.map(|language_server| {
|
||||||
let language_server_id = language_server.id();
|
let language_server_id = language_server.id();
|
||||||
let offset_encoding = language_server.offset_encoding();
|
let offset_encoding = language_server.offset_encoding();
|
||||||
let pos = pos_to_lsp_pos(doc.text(), cursor, offset_encoding);
|
let pos = pos_to_lsp_pos(&text, cursor, offset_encoding);
|
||||||
let doc_id = doc.identifier();
|
let doc_id = doc.identifier();
|
||||||
let completion_request = language_server.completion(doc_id, pos, None).unwrap();
|
let completion_request = language_server.completion(doc_id, pos, None).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ impl Completion {
|
||||||
fn item_to_transaction(
|
fn item_to_transaction(
|
||||||
doc: &Document,
|
doc: &Document,
|
||||||
view_id: ViewId,
|
view_id: ViewId,
|
||||||
item: &CompletionItem,
|
item: &lsp::CompletionItem,
|
||||||
offset_encoding: OffsetEncoding,
|
offset_encoding: OffsetEncoding,
|
||||||
trigger_offset: usize,
|
trigger_offset: usize,
|
||||||
include_placeholder: bool,
|
include_placeholder: bool,
|
||||||
|
@ -130,7 +130,7 @@ impl Completion {
|
||||||
let text = doc.text().slice(..);
|
let text = doc.text().slice(..);
|
||||||
let primary_cursor = selection.primary().cursor(text);
|
let primary_cursor = selection.primary().cursor(text);
|
||||||
|
|
||||||
let (edit_offset, new_text) = if let Some(edit) = &item.item.text_edit {
|
let (edit_offset, new_text) = if let Some(edit) = &item.text_edit {
|
||||||
let edit = match edit {
|
let edit = match edit {
|
||||||
lsp::CompletionTextEdit::Edit(edit) => edit.clone(),
|
lsp::CompletionTextEdit::Edit(edit) => edit.clone(),
|
||||||
lsp::CompletionTextEdit::InsertAndReplace(item) => {
|
lsp::CompletionTextEdit::InsertAndReplace(item) => {
|
||||||
|
@ -153,10 +153,9 @@ impl Completion {
|
||||||
(Some((start_offset, end_offset)), edit.new_text)
|
(Some((start_offset, end_offset)), edit.new_text)
|
||||||
} else {
|
} else {
|
||||||
let new_text = item
|
let new_text = item
|
||||||
.item
|
|
||||||
.insert_text
|
.insert_text
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or_else(|| item.item.label.clone());
|
.unwrap_or_else(|| item.label.clone());
|
||||||
// check that we are still at the correct savepoint
|
// check that we are still at the correct savepoint
|
||||||
// we can still generate a transaction regardless but if the
|
// we can still generate a transaction regardless but if the
|
||||||
// document changed (and not just the selection) then we will
|
// document changed (and not just the selection) then we will
|
||||||
|
@ -165,9 +164,9 @@ impl Completion {
|
||||||
(None, new_text)
|
(None, new_text)
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches!(item.item.kind, Some(lsp::CompletionItemKind::SNIPPET))
|
if matches!(item.kind, Some(lsp::CompletionItemKind::SNIPPET))
|
||||||
|| matches!(
|
|| matches!(
|
||||||
item.item.insert_text_format,
|
item.insert_text_format,
|
||||||
Some(lsp::InsertTextFormat::SNIPPET)
|
Some(lsp::InsertTextFormat::SNIPPET)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -256,7 +255,7 @@ impl Completion {
|
||||||
let transaction = item_to_transaction(
|
let transaction = item_to_transaction(
|
||||||
doc,
|
doc,
|
||||||
view.id,
|
view.id,
|
||||||
item,
|
&item.item,
|
||||||
language_server!(item).offset_encoding(),
|
language_server!(item).offset_encoding(),
|
||||||
trigger_offset,
|
trigger_offset,
|
||||||
true,
|
true,
|
||||||
|
@ -294,7 +293,7 @@ impl Completion {
|
||||||
let transaction = item_to_transaction(
|
let transaction = item_to_transaction(
|
||||||
doc,
|
doc,
|
||||||
view.id,
|
view.id,
|
||||||
&item,
|
&item.item,
|
||||||
offset_encoding,
|
offset_encoding,
|
||||||
trigger_offset,
|
trigger_offset,
|
||||||
false,
|
false,
|
||||||
|
|
Loading…
Add table
Reference in a new issue