Skip to content

Commit 9c1de44

Browse files
committed
refactor completion and signature help using hooks
1 parent c4fc6c3 commit 9c1de44

File tree

19 files changed

+1022
-560
lines changed

19 files changed

+1022
-560
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

book/src/configuration.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ Its settings will be merged with the configuration directory `config.toml` and t
5151
| `auto-completion` | Enable automatic pop up of auto-completion | `true` |
5252
| `auto-format` | Enable automatic formatting on save | `true` |
5353
| `auto-save` | Enable automatic saving on the focus moving away from Helix. Requires [focus event support](https://github.com/helix-editor/helix/wiki/Terminal-Support) from your terminal | `false` |
54-
| `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. Used for autocompletion, set to 0 for instant | `250` |
54+
| `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. | `250` |
55+
| `completion-timeout` | Time in milliseconds after typing a word character before completions are shown, set to 5 for instant. | `250` |
5556
| `preview-completion-insert` | Whether to apply completion item instantly when selected | `true` |
5657
| `completion-trigger-len` | The min-length of word under cursor to trigger autocompletion | `2` |
5758
| `completion-replace` | Set to `true` to make completions always replace the entire word and not just the part before the cursor | `false` |

helix-lsp/src/client.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use helix_loader::{self, VERSION_AND_GIT_HASH};
99
use helix_stdx::path;
1010
use lsp::{
1111
notification::DidChangeWorkspaceFolders, CodeActionCapabilityResolveSupport,
12-
DidChangeWorkspaceFoldersParams, OneOf, PositionEncodingKind, WorkspaceFolder,
12+
DidChangeWorkspaceFoldersParams, OneOf, PositionEncodingKind, SignatureHelp, WorkspaceFolder,
1313
WorkspaceFoldersChangeEvent,
1414
};
1515
use lsp_types as lsp;
@@ -999,6 +999,7 @@ impl Client {
999999
text_document: lsp::TextDocumentIdentifier,
10001000
position: lsp::Position,
10011001
work_done_token: Option<lsp::ProgressToken>,
1002+
context: lsp::CompletionContext,
10021003
) -> Option<impl Future<Output = Result<Value>>> {
10031004
let capabilities = self.capabilities.get().unwrap();
10041005

@@ -1010,13 +1011,12 @@ impl Client {
10101011
text_document,
10111012
position,
10121013
},
1014+
context: Some(context),
10131015
// TODO: support these tokens by async receiving and updating the choice list
10141016
work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token },
10151017
partial_result_params: lsp::PartialResultParams {
10161018
partial_result_token: None,
10171019
},
1018-
context: None,
1019-
// lsp::CompletionContext { trigger_kind: , trigger_character: Some(), }
10201020
};
10211021

10221022
Some(self.call::<lsp::request::Completion>(params))
@@ -1063,7 +1063,7 @@ impl Client {
10631063
text_document: lsp::TextDocumentIdentifier,
10641064
position: lsp::Position,
10651065
work_done_token: Option<lsp::ProgressToken>,
1066-
) -> Option<impl Future<Output = Result<Value>>> {
1066+
) -> Option<impl Future<Output = Result<Option<SignatureHelp>>>> {
10671067
let capabilities = self.capabilities.get().unwrap();
10681068

10691069
// Return early if the server does not support signature help.
@@ -1079,7 +1079,8 @@ impl Client {
10791079
// lsp::SignatureHelpContext
10801080
};
10811081

1082-
Some(self.call::<lsp::request::SignatureHelpRequest>(params))
1082+
let res = self.call::<lsp::request::SignatureHelpRequest>(params);
1083+
Some(async move { Ok(serde_json::from_value(res.await?)?) })
10831084
}
10841085

10851086
pub fn text_document_range_inlay_hints(

helix-stdx/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ homepage.workspace = true
1414
[dependencies]
1515
dunce = "1.0"
1616
etcetera = "0.8"
17+
ropey = { version = "1.6.1", default-features = false }
1718

1819
[dev-dependencies]
1920
tempfile = "3.9"

helix-stdx/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod env;
22
pub mod path;
3+
pub mod rope;

helix-stdx/src/rope.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use ropey::RopeSlice;
2+
3+
pub trait RopeSliceExt: Sized {
4+
fn ends_with(self, text: &str) -> bool;
5+
fn starts_with(self, text: &str) -> bool;
6+
}
7+
8+
impl RopeSliceExt for RopeSlice<'_> {
9+
fn ends_with(self, text: &str) -> bool {
10+
let len = self.len_bytes();
11+
if len < text.len() {
12+
return false;
13+
}
14+
self.get_byte_slice(len - text.len()..)
15+
.map_or(false, |end| end == text)
16+
}
17+
18+
fn starts_with(self, text: &str) -> bool {
19+
let len = self.len_bytes();
20+
if len < text.len() {
21+
return false;
22+
}
23+
self.get_byte_slice(..len - text.len())
24+
.map_or(false, |start| start == text)
25+
}
26+
}

helix-term/src/application.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
use arc_swap::{access::Map, ArcSwap};
22
use futures_util::Stream;
3-
use helix_core::{
4-
chars::char_is_word,
5-
diagnostic::{DiagnosticTag, NumberOrString},
6-
pos_at_coords, syntax, Selection,
7-
};
3+
use helix_core::{diagnostic::Severity, pos_at_coords, syntax, Selection};
84
use helix_lsp::{
95
lsp::{self, notification::Notification},
106
util::lsp_range_to_range,

0 commit comments

Comments
 (0)