Commit graph

2302 commits

Author SHA1 Message Date
Michael Davis
953073a679 highlighted_code_block: Take input text as &str
This removes a handful of allocations for functions calling into the
function, which is nice because the prompt may call this function on
every keypress.
2023-07-27 11:50:19 +09:00
Michael Davis
98ef05d768 Prefer RopeSlice to &Rope in helix_core::syntax
Pascal and I discussed this and we think it's generally better to
take a 'RopeSlice' rather than a '&Rope'. The code block rendering
function in the markdown component module is a good example for how
this can be useful: we can remove an allocation of a rope and instead
directly turn a '&str' into a 'RopeSlice' which is very cheap.

A change to prefer 'RopeSlice' to '&Rope' whenever the rope isn't
modified would be nice, but it would be a very large diff (around 500+
500-). Starting off with just the syntax functions seems like a nice
middle-ground, and we can remove a Rope allocation because of it.

Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
2023-07-27 11:50:19 +09:00
Michael Davis
f0b877e258 Tune regex highlights for usage in prompts
Since regex is almost always injected into other languages,
`pattern_character`s will inherit the highlight for the structure that
injects them (for example `/foo/` in JavaScript or `~r/foo/` in Elixir).
This removes the string highlight when used in the prompt.

We also add `ERROR` node highlighting so that errors in regex syntax
appear in the prompt. This resolves a TODO in the `regex_prompt`
function about highlighting errors in the regex.
2023-07-27 11:50:19 +09:00
Michael Davis
0dc3753eb2 Syntax-highlight regex prompts
We can use tree-sitter-regex highlighting in prompts for entering
regexes, like `search` or `global_search`. The `highlighted_code_block`
function from the markdown component makes this a very small change.

This could be improved in the future by leaving the parsed syntax tree
on the prompt, allowing incremental updates. Prompt lines are usually so
short though and tree-sitter-regex is rather small and uncomplicated,
so that improvement probably wouldn't make a big difference.
2023-07-27 11:50:19 +09:00
Michael Davis
6a431afc4e
Save an undo checkpoint before accepting completion (#7747) 2023-07-27 11:48:16 +09:00
dependabot[bot]
46251a1411
build(deps): bump tempfile from 3.6.0 to 3.7.0 (#7726)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-25 03:03:03 +02:00
Ryan Fowler
5c41f22c2a
Add support for LSP DidChangeWatchedFiles (#7665)
* Add initial support for LSP DidChangeWatchedFiles

* Move file event Handler to helix-lsp

* Simplify file event handling

* Refactor file event handling

* Block on future within LSP file event handler

* Fully qualify uses of the file_event::Handler type

* Rename ops field to options

* Revert newline removal from helix-view/Cargo.toml

* Ensure file event Handler is cleaned up when lsp client is shutdown
2023-07-22 00:21:21 +02:00
sigmaSd
8977123f25
feat: resolve code action (#7677) 2023-07-21 14:50:08 -05:00
dependabot[bot]
b87858b7b4
build(deps): bump indoc from 2.0.2 to 2.0.3 (#7663)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-18 10:49:11 +09:00
Pascal Kuthe
8f1c6456f3
Clear statusline while prompt is visible (#7646) 2023-07-17 14:09:07 +09:00
Alex Vinyals
843ae97120
enhanced surround_replace to provide visual feedback (#7588) 2023-07-13 22:01:44 +09:00
Jonathan
0e0501c510
Fix piping to Helix on macOS (#5468) 2023-07-13 12:01:17 +09:00
Tudyx
9893a1fbcc
Auto indent change if selection is linewise (#7316) 2023-07-11 14:01:48 -05:00
Yomain
8afc0282f2
Fix crash when cwd is deleted (#7185) 2023-07-11 19:51:04 +02:00
Pascal Kuthe
1adb19464f
search buffer contents during global search (#5652) 2023-07-11 21:26:11 +09:00
dependabot[bot]
ac57e93583
build(deps): bump smallvec from 1.10.0 to 1.11.0 (#7597)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-11 10:26:00 +09:00
Gabriel Hansson
c1488267e5
(Updated) Apply motion API refinements (#6078)
* _apply_motion generalization where possible

API encourages users to not forget setting `editor.last_motion` when
applying a motion. But also not setting `last_motion` without applying a
motion first.

* (rename) will_find_char -> find_char

method name makes it sound like it would be returning a boolean.

* use _apply_motion in find_char

Feature that falls out from this is that repetitions of t,T,f,F are
saved with the context extention/move and count. (Not defaulting to extend
by 1 count).

* Finalize apply_motion API

last_motion is now a private field and can only be set by calling
Editor.apply_motion(). Removing need (and possibility) of writing:

`motion(editor); editor.last_motion = motion`

Now it's just: `editor.apply_motion(motion)`

* editor.last_message: rm Box wrap around Arc

* Use pre-existing `Direction` rather than custom `SearchDirection`.

* `LastMotion` type alias for `Option<Arc<dyn Fn(&mut Editor)>>`

* Take motion rather than cloning it.

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

* last_motion as Option<Motion>.

* Use `Box` over `Arc` for `last_motion`.

---------

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2023-07-09 16:50:24 -04:00
Alex Vinyals
28452e1f2a
Initialize log and config files right after parsing arguments (#7585) 2023-07-09 11:30:43 -05:00
Ryan Fowler
828c7432e3
Implement the wa! command (#7577) 2023-07-09 09:38:50 -05:00
Alex Vinyals
1698992de6
Fix :log-open when --log is specified (#7573) 2023-07-09 16:35:07 +02:00
Alberto Romero
507dd50860
Add filename completer for shell prompt (#7569) 2023-07-08 18:12:28 +02:00
Pascal Kuthe
618620b369
use redraw handle for debouncing LSP messages (#7538) 2023-07-08 06:46:34 +09:00
dependabot[bot]
83e59197ac
build(deps): bump indoc from 2.0.1 to 2.0.2 (#7529)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-04 02:13:58 +02:00
Michael Davis
4fab60030f
LSP: Use negotiated position encoding for workspace edits (#7469)
Previously this was hard-coded to UTF-8 but we might have negotiated
another position encoding.
2023-06-30 00:24:13 +09:00
Michael Davis
d3f8e0592b
LSP: Discard publishDiagnostic from uninitialized servers (#7467)
The spec explicitly disallows publishDiagnostic to be sent before
the initialize response:

> ... the server is not allowed to send any requests or notifications to
> the client until it has responded with an InitializeResult ...

(https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize)

But if a non-compliant server sends this we currently panic because we
'.expect()' the server capabilities to be known to fetch the position
encoding. Instead of panicking we can discard the notification and log
the non-compliant behavior.
2023-06-28 16:59:13 -04:00
dependabot[bot]
d8f9b901dd
build(deps): bump libc from 0.2.146 to 0.2.147 (#7463)
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.146 to 0.2.147.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.146...0.2.147)

---
updated-dependencies:
- dependency-name: libc
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-27 15:37:22 +02:00
Pascal Kuthe
a0359f7f22 make TS matching fallback to plaintext 2023-06-22 16:00:08 +09:00
Michael Davis
9690e0b733
Fix Component implementations for Picker (#7382) 2023-06-19 18:55:46 +09:00
Gokul Soumya
f18acadbd0
Completely remove old Picker and rename FilePicker to Picker 2023-06-18 12:28:26 -05:00
Michael Davis
545acfda88
Make file preview callback optional
When Picker and FilePicker are merged, not all Pickers will be able to
show a preview.

Co-authored-by: Gokul Soumya <gokulps15@gmail.com>
2023-06-18 12:28:16 -05:00
Gokul Soumya
fc111213b5
Move FilePicker struct def closer to impl block 2023-06-18 12:14:41 -05:00
Gokul Soumya
15cc09fc81
Render the preview in FilePicker 2023-06-18 12:14:09 -05:00
Gokul Soumya
34c8f9ab73
Move Picker::render into FilePicker::render 2023-06-18 12:11:24 -05:00
Gokul Soumya
49fbf8df53
Move Component methods except render() to FilePicker 2023-06-18 12:10:00 -05:00
Gokul Soumya
1e66e9198c
Move handle_event methods from Picker to FilePicker 2023-06-18 12:07:38 -05:00
Gokul Soumya
8516f43837
Move navigation methods from Picker to FilePicker 2023-06-18 12:05:59 -05:00
Gokul Soumya
7a058c7361
Move scoring functions from Picker to FilePicker 2023-06-18 12:05:17 -05:00
Gokul Soumya
104036bd7f
Copy struct fields and new() from Picker to FilePicker 2023-06-18 12:01:16 -05:00
Gokul Soumya
40916dff63
Move FilePicker::render from Component impl to normal impl
Merges the code for the Picker and FilePicker into a single Picker that
can show a file preview if a preview callback is provided. This change
was mainly made to facilitate refactoring out a simple skeleton of a
picker that does not do any filtering to be reused in a normal Picker
and a DynamicPicker (see #5714; in particular [mikes-comment] and
[gokuls-comment]).

The crux of the issue is that a picker maintains a list of predefined
options (eg. list of files in the directory) and (re-)filters them every
time the picker prompt changes, while a dynamic picker (eg. interactive
global search, #4687) recalculates the full list of options on every
prompt change. Using a filtering picker to drive a dynamic picker hence
does duplicate work of filtering thousands of matches for no reason. It
could also cause problems like interfering with the regex pattern in the
global search.

I tried to directly extract a PickerBase to be reused in Picker and
FilePicker and DynamicPicker, but the problem is that DynamicPicker is
actually a DynamicFilePicker (i.e. it can preview file contents) which
means we would need PickerBase, Picker, FilePicker, DynamicPicker and
DynamicFilePicker and then another way of sharing the previewing code
between a FilePicker and a DynamicFilePicker. By merging Picker and
FilePicker into Picker, we only need PickerBase, Picker and
DynamicPicker.

[gokuls-comment]: https://github.com/helix-editor/helix/issues/5714#issuecomment-1410949578
[mikes-comment]: https://github.com/helix-editor/helix/issues/5714#issuecomment-1407451963
2023-06-18 11:34:13 -05:00
spectre256
d8b7232a47
Add yank_joined command (#7195)
Resolves issue #6888 by adding a command to join all selections and yank
them to the specified register. The typed command takes an argument as
the separator to use when joining the selections.
2023-06-16 21:13:23 +02:00
Alex
3fb9fafb2a
Add config for default line ending (#5621) 2023-06-16 12:02:15 -05:00
A-Walrus
4d8c9a394e
Preview scratch buffers in jumplist picker (#7331) 2023-06-13 16:05:01 +02:00
Zisulin Morbrot
fbd22afe29
Add rl and rla aliasses for reload and reload-all commands (#7158) 2023-06-13 08:50:50 -05:00
Robert
015c079acc
Add reverse_selection_contents (#7329) 2023-06-13 08:36:28 -05:00
dependabot[bot]
0e42e4e193
build(deps): bump libc from 0.2.145 to 0.2.146 (#7327)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-13 09:52:06 +09:00
dependabot[bot]
0d998c99d4
build(deps): bump tempfile from 3.5.0 to 3.6.0 (#7326)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-13 09:51:34 +09:00
Philipp Mildenberger
2a11fb485d
Fix underflow when repeating a completion that has a negative shift position (#7322) 2023-06-13 01:37:47 +09:00
0xHiro / ヒロ
8c6eb88c6a
fix: add file argument in help text (#7307) 2023-06-10 18:40:39 +02:00
Luca Schlecker
dbd248fdfa add config option for instant completion entry preview (defaulting to true).
Signed-off-by: Luca Schlecker <luca.schlecker@hotmail.com>
2023-06-09 13:23:29 -04:00
spectre256
00b152facd
Add register statusline element (#7222) 2023-06-08 14:34:07 -05:00
Alex
993c68ad6f
Auto indent on insert_at_line_start (#5837) 2023-06-08 19:11:40 +02:00
Michael Davis
d4427125eb
Bail if no language servers support workspace symbols (#7286) 2023-06-08 09:48:11 +09:00
vwkd
352d1574a6
add move_prev_long_word_end and extend_prev_long_word_end (#6905) 2023-06-08 00:41:35 +02:00
Michael Davis
b3949979ae Propagate the count and register to command palette commands
Previously a count or register selection would be lost while opening
the command palette. This change allows using a register selection or
count in any command chosen from the command palette.
2023-06-08 00:48:25 +09:00
Michael Davis
0e083497a5 Persist register selection in pending keymaps
Previously the register selection (via `"`) would be lost in the middle
of any key sequence longer than one key. For example, `<space>f` would
clear the register selection after the `<space>` making it inaccessible
for the `file_picker` command.

This behavior does not currently have any effect in the default keymap
but might affect custom keymaps. This change aligns the behavior of the
register with count. Making this change allows propagating the register
to the `command_palette` (see the child commit) or other pickers should
we decide to use registers in those in the future. (Interactive global
search for example.)
2023-06-08 00:48:25 +09:00
Alex Vinyals
204bac1706
commands(toggle): use pattern matching on the Value enum (#7240) 2023-06-07 17:50:16 +09:00
gibbz00
9926c2d292 Remove Keymap(KeyTrie) and simply use KeyTrie. 2023-06-07 10:11:13 +09:00
gibbz00
b8563685ec Move keymap.reverse_keymap() to Keytrie:
The plan is let `Keymaps` simply store `KeyTrie`s, as the `Keymap(Keytrie)` wrapping serves little to no purpose.
2023-06-07 10:11:13 +09:00
gibbz00
eda4c79f2f Remove pub keymap.name();
`keymap.name` is only used internally.
2023-06-07 10:11:13 +09:00
gibbz00
3d0bc72099 Place Info::from_keymap() contents in keymap.infobox():
This makes it easier later control the order in which the key events
are presented.
2023-06-07 10:11:13 +09:00
gibbz00
19326d23d1 Keymap infobox: Idiomatic body tuple.
Does not change any behavior other than making the tuple slightly
more idiomatic.  Keymap infobox shows key events, then the respective
description. This commit makes sure that order is used from the get go,
rather than flipping it midway.
2023-06-07 10:11:13 +09:00
gibbz00
3a0892f793 Exclude config no_op bindings in command palette. 2023-06-07 10:11:13 +09:00
gibbz00
39773e48d3 Remove superfluous command description pruning for keymap infobox:
Exist under the wrong (possibly just outdated) assumption that command
descriptions are written with their `KeyTrie` name prefixed
2023-06-07 10:11:13 +09:00
gibbz00
d20c1632a7 helix_term::keymap: Remove one-liner solely used for a test. 2023-06-07 10:11:13 +09:00
gibbz00
f7df53c948 Make Keymap a tuple struct. 2023-06-07 10:11:13 +09:00
gibbz00
daea97a89f keymap: Rename KeyTrie::Leaf -> KeyTrie::MapppableCommand
The variant Sequence is technically also a leaf.
2023-06-07 10:11:13 +09:00
gibbz00
a56af221d7 keymap: Derive Default for KeyTrieNode 2023-06-07 10:11:13 +09:00
dependabot[bot]
6deb0e4ef7
build(deps): bump once_cell from 1.17.2 to 1.18.0 (#7248)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-06 11:14:36 +09:00
dependabot[bot]
cd01dc886a
build(deps): bump libc from 0.2.144 to 0.2.145 (#7244)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-06 11:13:28 +09:00
Alex Vinyals
a2b8cfdb8c
feat(core): add plaintext matching fallback to tree-sitter matching (#4288) 2023-06-05 23:13:00 +09:00
Michael Davis
428d33ab50
Exit gracefully on termination signals (#7236) 2023-06-05 22:27:57 +09:00
Alex Vinyals
d5707a4696
feat(commands): allows cycling option values at runtime (#4411) 2023-06-05 22:22:05 +09:00
Ethan Wilkes
3334e7e4b2
fixed repeat_last_motion extends selection (#7159) 2023-05-29 00:51:22 +09:00
Matthew Toohey
207829eefe
Fix off-by-one in select symbol references (#7132) 2023-05-25 14:01:56 +02:00
Poliorcetics
8e2660b5cc
Update diagnostics correctly on LSP exit (#7111)
* chore: avoid format! call with argument when useless

* feat: also clear diagnostics for unopened documents when exiting an LSP

* feat: we already worked on `self.editor.diagnostics` no need to redo the checks
2023-05-23 12:33:01 +02:00
Szabin
70e4cdbd8e
Add command to merge non-consecutive ranges (#7053)
* Add command for merging non-consecutive ranges

* Add `merge_selections` command to book

* Simplify `merge_ranges`

Heeded the advice of @the-mikedavis to stop iterating over all ranges and simply merge the first and the last range, as the invariants of `Selection` guarantee that the list of ranges is always sorted and never empty.

* Clarify doc comment of `merge_ranges`
2023-05-20 01:31:39 +02:00
Philipp Mildenberger
2a512f7c48 Rebase cleanup/fixes and use lsp::CompletionItem in item_to_transaction directly 2023-05-18 22:25:32 +02:00
Philipp Mildenberger
f45bbf165e Apply all review suggestions (doc_id -> id, error message, unnecessary if)
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
2023-05-18 22:04:49 +02:00
Philipp Mildenberger
2b746ea6fa Some minor clarity/cosmetic improvements
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
2023-05-18 22:04:49 +02:00
Philipp Mildenberger
39b9a4bba2 Add function Editor::language_server_by_id and refactor/simplify related code, also don't 'crash' in completion menu if language_server somehow disappeared 2023-05-18 22:04:47 +02:00
Philipp Mildenberger
3e4bac1d96 Fix lsp_restart across multiple different document scopes (language servers weren't restarted, if not of the same scope id), and fix some smaller rebase issues 2023-05-18 21:58:17 +02:00
Philipp Mildenberger
93fd79a949 Remove offset_encoding in CodeActionOrCommandItem, as it can be retrieved on demand 2023-05-18 21:58:17 +02:00
Philipp Mildenberger
ff26208427 Filter language servers also by capabilities in doc.language_servers_with_feature
* Add `helix_lsp::client::Client::supports_feature(&self, LanguageServerFeature)`
* Extend `doc.language_servers_with_feature` to use this method as filter as well
* Add macro `language_server_with_feature!` to reduce boilerplate for non-mergeable language server requests (like goto-definition)
* Refactored most of the `find_map` code to use the either the macro or filter directly via `doc.language_servers_with_feature`
2023-05-18 21:58:17 +02:00
Philipp Mildenberger
451fe528bb Filter out already seen language servers in requests that can be sent to multiple language servers (code-action, completion, symbol pickers) 2023-05-18 21:58:17 +02:00
Philipp Mildenberger
8ab6d7be5e Use let else instead of variable and fix some error messages
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
2023-05-18 21:58:17 +02:00
Philipp Mildenberger
1d5d5dab47 Remove offset_encoding in CompletionItem 2023-05-18 21:58:15 +02:00
Philipp Mildenberger
2eeac10755 Refactor doc language servers to a HashMap, and the config to use a Vec to retain order 2023-05-18 21:48:32 +02:00
Philipp Mildenberger
b1199c552b Remove symbol picker is_empty check 2023-05-18 21:48:32 +02:00
Philipp Mildenberger
58c913ce45 Simplify 'lsp_stop' command 2023-05-18 21:48:32 +02:00
Philipp Mildenberger
7d20740b5b Fix docgen and lsp-stop documentation 2023-05-18 21:48:32 +02:00
Philipp Mildenberger
60a6af1fea Remove boilerplate in the goto methods by generically composing functions 2023-05-18 21:48:32 +02:00
Philipp Mildenberger
1122928c2a Add method doc.supports_language_server for better readability 2023-05-18 21:48:32 +02:00
Philipp Mildenberger
76b5cab524 Refactored doc.language_servers and doc.language_servers_with_feature to return an iterator and refactor LanguageServerFeature handling to a HashMap (language server name maps to features)
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
2023-05-18 21:48:32 +02:00
Philipp Mildenberger
0637691eb1 Use DoubleEndedIterator instead of collect to Vec for reversing
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
2023-05-18 21:48:32 +02:00
Philipp Mildenberger
dd2f74794a Fix error messages when no language server is available
Co-authored-by: Skyler Hawthorne <skyler@dead10ck.com>
2023-05-18 21:48:32 +02:00
Philipp Mildenberger
f9b08656f4 Fix sorting issues of the editor wide diagnostics and apply diagnostics related review suggestions
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
2023-05-18 21:48:32 +02:00
Philipp Mildenberger
b6c60beb2d Remove unnecessary completion support check (likely an artifact) 2023-05-18 21:48:32 +02:00
Philipp Mildenberger
44b2b40190 Fix issue with ltex-ls, filtering params is not what we want here 2023-05-18 21:48:32 +02:00
Philipp Mildenberger
05583f8cc9 Fix hardcoded offset_encoding 2023-05-18 21:48:32 +02:00
Philipp Mildenberger
74e21e1b25 Fix some lints/docgen hints 2023-05-18 21:48:32 +02:00
Philipp Mildenberger
7d4f7eb4bd Fix 'WorkspaceConfiguration' request with empty configuration section strings 2023-05-18 21:48:32 +02:00
Philipp Mildenberger
71551d395b Adds support for multiple language servers per language.
Language Servers are now configured in a separate table in `languages.toml`:

```toml
[langauge-server.mylang-lsp]
command = "mylang-lsp"
args = ["--stdio"]
config = { provideFormatter = true }

[language-server.efm-lsp-prettier]
command = "efm-langserver"

[language-server.efm-lsp-prettier.config]
documentFormatting = true
languages = { typescript = [ { formatCommand ="prettier --stdin-filepath ${INPUT}", formatStdin = true } ] }
```

The language server for a language is configured like this (`typescript-language-server` is configured by default):

```toml
[[language]]
name = "typescript"
language-servers = [ { name = "efm-lsp-prettier", only-features = [ "format" ] }, "typescript-language-server" ]
```

or equivalent:

```toml
[[language]]
name = "typescript"
language-servers = [ { name = "typescript-language-server", except-features = [ "format" ] }, "efm-lsp-prettier" ]
```

Each requested LSP feature is priorized in the order of the `language-servers` array.
For example the first `goto-definition` supported language server (in this case `typescript-language-server`) will be taken for the relevant LSP request (command `goto_definition`).

If no `except-features` or `only-features` is given all features for the language server are enabled, as long as the language server supports these. If it doesn't the next language server which supports the feature is tried.

The list of supported features are:

- `format`
- `goto-definition`
- `goto-declaration`
- `goto-type-definition`
- `goto-reference`
- `goto-implementation`
- `signature-help`
- `hover`
- `document-highlight`
- `completion`
- `code-action`
- `workspace-command`
- `document-symbols`
- `workspace-symbols`
- `diagnostics`
- `rename-symbol`
- `inlay-hints`

Another side-effect/difference that comes with this PR, is that only one language server instance is started if different languages use the same language server.
2023-05-18 21:48:30 +02:00
Ivan Gulakov
2cccb3f09c
Fix completion on paths containing spaces (#6779)
There was an issue with autocompletion of a path with a space in it.

Before:

:o test\ dir -> <TAB> -> test\ dirfile1

After:

:o test\ dir -> <TAB> -> test\ dir\file1
2023-05-18 15:27:29 +09:00
Pascal Kuthe
b0705337be automatically disable TS when parsing takes longer than 500ms 2023-05-18 15:23:37 +09:00
Pascal Kuthe
2f2306475c async picker syntax highlighting 2023-05-18 15:23:37 +09:00
Pascal Kuthe
c6f169b1f8 cleanup integration tests 2023-05-18 15:20:55 +09:00
Pascal Kuthe
25d4ebe30d don't move cursor while forward deleting in append mode
Currently, when forward deleting (`delete_char_forward` bound to `del`,
`delete_word_forward`, `kill_to_line_end`) the cursor is moved to the
left in append mode (or generally when the cursor is at the end of the
selection). For example in a document `|abc|def`  (|indicates selection)
if enter append mode the cursor is moved to `c` and the selection
becomes: `|abcd|ef`. When deleting forward (`del`) `d` is deleted. The
expectation would be that the selection doesn't shrink so that `del`
again deletes `e` and then `f`. This would look as follows:

`|abcd|ef`
`|abce|f`
`|abcf|`
`|abc |`

This is inline with how other editors like kakoune work.
However, helix currently moves the selection backwards leading to the
following behavior:

`|abcd|ef`
`|abc|ef`
`|ab|ef`
`ef`

This means that `delete_char_forward` essentially acts like
`delete_char_backward` after deleting the first character in append
mode.

To fix the problem the cursor must be moved to the right while deleting
forward (first fix in this commit). Furthermore, when the EOF char is
reached a newline char must be inserted (just like when entering
appendmode) to prevent the cursor from moving to the right
2023-05-18 15:20:55 +09:00
Pascal Kuthe
2c3ccc3e8b cleanup delete_by_selection_insert_mode function 2023-05-18 15:20:55 +09:00
Pascal Kuthe
f8225ed921 fix panic when deleting overlapping ranges
Some deletion operations (especially those that use indentation)
can generate overlapping deletion ranges when using multiple cursors.
To fix that problem a new `Transaction::delete` and
`Transaction:delete_by_selection` function were added. These functions
merge overlapping deletion ranges instead of generating an invalid
transaction. This merging of changes is only possible for deletions
and not for other changes and therefore require its own function.

The function has been used in all commands that currently delete
text by using `Transaction::change_by_selection`.
2023-05-18 15:20:55 +09:00
Pascal Kuthe
6842fd4c36 clarify comments about completion savepoints
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2023-05-18 15:16:50 +09:00
Pascal Kuthe
28b730381c only resolve completion items once 2023-05-18 15:16:50 +09:00
Pascal Kuthe
9c558fc470 ensure correct trigger/start completion offset
When re requesting a completion that already has a selected item we
reuse that selections savepoint. However, the selection has likely
changed since that savepoint which requires us to use the selection
from that savepoint
2023-05-18 15:16:50 +09:00
Pascal Kuthe
30ff7f8db2 resolve completions before applying transactions 2023-05-18 15:16:50 +09:00
Pascal Kuthe
5406e9f629 correctly handle completion rerequest 2023-05-18 15:16:50 +09:00
A-Walrus
d5fe08ddb8
Replace DAP vars popup, instead of adding new (#7034) 2023-05-13 10:44:25 -05:00
ZJPzjp
3b8c15618f
Fix warnings from clippy (#7013)
* Fix warnings from clippy

* revert MAIN_SEPARATOR_STR
2023-05-11 14:44:52 +09:00
Kitsu
92c328c088
Add wbc and wbc! commands (#6947) 2023-05-09 22:21:29 +02:00
dependabot[bot]
9cca80bd53
build(deps): bump libc from 0.2.142 to 0.2.144 (#7000)
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.142 to 0.2.144.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.142...0.2.144)

---
updated-dependencies:
- dependency-name: libc
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-09 09:30:11 +09:00
Alexis-Lapierre
b0b3f45b80
Conserve BOM and properly support UTF16 (#6497) 2023-05-01 00:40:06 +02:00
Evgeniy Tatarkin
6a1bb81f10
Sort the buffer picker by most recent access (#2980) 2023-04-28 11:05:14 -05:00
Timothy DeHerrera
9c6c63a2be
inject language based on file extension & shebang (#3970)
* inject language based on file extension

Nodes can now be captured with "injection.filename". If this capture
contains a valid file extension known to Helix, then the content will
be highlighted as that language.

* inject language by shebang

Nodes can now be captured with "injection.shebang". If this capture
contains a valid shebang line known to Helix, then the content will
be highlighted as the language the shebang calls for.

* add documentation for language injection

* nix: fix highlights

The `@` is now highlighted properly on either side of the function arg.

Also, extending the phases with `buildPhase = prev.buildPhase + ''''`
is now highlighted properly.

Fix highlighting of `''$` style escapes (requires tree-sitter-nix bump)

Fix `inherit` highlighting.

* simplify injection_for_match

Split out injection pair logic into its own method to make the overall
flow easier to follow.

Also transform the top-level function into a method on a
HighlightConfiguration.

* markdown: add shebang injection query
2023-04-28 18:21:34 +09:00
jorge
204d1eba4b
feat(commands): add clear-register typable command (#5695)
Co-authored-by: Jorge <chorcheus@tutanota.com>
2023-04-27 21:57:05 +02:00
Vitalii Solodilov
2836ea2ac4
feat: add a config option to exclude declaration from LSP references (#6886)
* feat: added the config option to exclude declaration from reference query

Fixes: #5344

* fix: review

* fix: review
2023-04-27 16:30:15 +02:00
Pascal Kuthe
8f1671eaaa
fix panic in inlay hint computation when view anchor is out of bounds (#6883) 2023-04-27 09:38:20 +09:00
Dimitri Sabadie
096ed0ced4
Add extend_to_first_nonwhitespace (#6837)
Closes #6836
2023-04-25 19:14:06 +02:00
dependabot[bot]
d45af96fc4
build(deps): bump libc from 0.2.141 to 0.2.142 (#6872)
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.141 to 0.2.142.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.141...0.2.142)

---
updated-dependencies:
- dependency-name: libc
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-25 11:51:43 +09:00
Atticus Sebastiani
228a4af35f
make :u alias :update (#6835)
* Gave the command update the alias u

* Re added trailing newline

* generated docs
2023-04-23 04:07:34 +02:00
Michael Davis
ee7413a3fd
tui: Allow toggling mouse capture at runtime (#6675)
This picks up changes to the `editor.mouse` option at runtime - either
through `:set-option` or `:config-reload`. When the value changes, we
tell the terminal to enable or disable mouse capture sequences.
2023-04-21 12:53:27 +09:00
Pascal Kuthe
c3e2db77f7
flip symbol range in LSP goto commands (#6794) 2023-04-21 12:50:37 +09:00
shem
1b016a89d5
Fix crash on opening from suspend state (#6764)
* Fix crash on opening from suspend state (#6725)

* Fix code style

* revert using of the imperative code style. Add panic if couldn't set terminal raw mode

* remove redundant import of core::panic macros

* small refactoring
2023-04-16 23:07:00 +02:00
Aleksey Kuznetsov
7706ff77eb
make :toggle-option print the new value (#6774)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2023-04-16 20:44:12 +02:00
shem
9f680c69f4
Fix #6669: Theme preview doesn't return theme to normal (#6694)
* Fix #6669: Theme preview doesn't return theme to normal when delete name with Alt-Backspace

* Fix #6669: Return theme preview to normal theme for all remaining keybinds that change the promt text
2023-04-13 07:43:34 +08:00
EsfoNL
2f82bc13e8
Fix crash on opening jumplist (#6672)
Co-authored-by: Esra Fokker <esra.fokker@finalist.nl>
2023-04-11 17:59:08 -05:00
dependabot[bot]
ed67aa864d
build(deps): bump libc from 0.2.140 to 0.2.141 (#6700)
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.140 to 0.2.141.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.140...0.2.141)

---
updated-dependencies:
- dependency-name: libc
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-11 09:55:34 +09:00
Konstantin Keller
f8b7e95481
LSP: Gracefully handle 'workspace/configuration' from a stopped server (#6693) 2023-04-10 16:55:52 -05:00
Daniel Sedlak
e856906f76
Fix typos (#6643) 2023-04-07 23:10:38 +08:00
Dmitry Ulyanov
dd6e0cce3b
Fix line number display for LSP goto pickers (#6559)
Line numbers are 0-indexed in the LSP spec but 1-indexed for display
and jumping purposes in Helix.
2023-04-03 09:22:43 -05:00
Casper Rogild Storm
9420ba7484
Let..else refactor (#6562) 2023-04-03 13:41:41 +09:00
Pascal Kuthe
1073dd6329
robustly handle invalid LSP ranges (#6512) 2023-04-03 10:58:50 +09:00
Pascal Kuthe
9fe3adcff9
add option to enable/disable lsp snippets 2023-03-31 15:19:36 +09:00
Pascal Kuthe
7a69c40524
Hide signature help if it overlays completion menu (#5523) 2023-03-31 15:19:28 +09:00
Pascal Kuthe
ab819d80f1
Correctly reload theme on :config-reload
The current implementation didn't reload the theme if no no theme was
explicitly configured (so the default theme was used). This commit
brings `refresh_theme` in line with the initialization code.
2023-03-31 15:19:25 +09:00
mWalrus
e72be52996
Truncate paths in the file picker (#6410) 2023-03-31 15:19:17 +09:00
jazzfool
d04288e0f3
Canonicalize paths before stripping current dir as prefix (#6290)
Co-authored-by: jazzfool <shamoslover69@gmail.com>
2023-03-30 11:21:40 -05:00
Pascal Kuthe
5b3dd6a678 implement proper lsp-workspace support
fix typo

Co-authored-by: LeoniePhiline <22329650+LeoniePhiline@users.noreply.github.com>
2023-03-29 12:57:30 +09:00
Pascal Kuthe
2d10a429eb add workspace config and manual LSP root management
fixup documentation

Co-authored-by: LeoniePhiline <22329650+LeoniePhiline@users.noreply.github.com>

fixup typo

Co-authored-by: LeoniePhiline <22329650+LeoniePhiline@users.noreply.github.com>
2023-03-29 12:57:30 +09:00
Filip Dutescu
d59b80514e
feat(debug): highlight current line (#5957)
Add new theme highlight keys, for setting the colour of the breakpoint
character and the current line at which execution has been paused at.
The two new keys are `ui.highlight.frameline` and `ui.debug.breakpoint`.
Highlight according to those keys, both the line at which debugging
is paused at and the breakpoint indicator.

Add an indicator for the current line at which execution is paused
at, themed by the `ui.debug.active` theme scope. Update various themes
to showcase how the new functionality works.

Better icons are dependent on #2869, and as such will be handled in the
future, once it lands.

Closes: #5952

Signed-off-by: Filip Dutescu <filip.dutescu@gmail.com>
2023-03-29 12:52:19 +09:00
Philipp Mildenberger
198ff2c3f9
Fix clippy lints (#6454) 2023-03-27 18:33:55 -05:00
Pascal Kuthe
9fac574178 do not ignore mouse scrolling when on top of virtual text 2023-03-27 09:54:40 +09:00
Pascal Kuthe
15e751b9a2 make scrolloff calculation consistent
While scrolling (with the `scroll`) command scrolloff was calculated
slightly differently than in `ensure_cursor_in_view` which could cause
the cursor to get stuck while scrolling
2023-03-27 09:54:40 +09:00
Pascal Kuthe
d6c8e0c946 allow scrolling past virtual text line
Virtual text lines (either caused by softwrapped inlay hints that take
multiple or line annotations) currently block scrolling downwards.

if the visual offset passed to char_idx_at_visual_offset or
visual_offset_from_block is within a virtual text line then the char
position before the virtual text and a visual offset are returned.
We previously ignored that visual offset and as a result the cursor
would be stuck at the start of the virtual text. This commit fixes
that by simply moving the cursor to the next char (so past the virtual
text) if this visual offset is non-zero
2023-03-27 09:54:40 +09:00
Pascal Kuthe
0ab96cc257 remove incorrect assert
This assert was added during early development of #5420 and makes no
sense with the current code. We simply forgot to remove it.
2023-03-27 09:54:40 +09:00
Francesc Elies
05ee673197
Show diagnostic codes for LSP diagnostics (#6378)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2023-03-21 17:15:01 -05:00
sarah
28632c6cee
Run shell commands asynchronously (#6373) 2023-03-20 19:12:18 -05:00
Skyler Hawthorne
4bdeb9927b migrate test_with_config to use AppBuilder 2023-03-20 18:34:40 -05:00
Skyler Hawthorne
d3b051d28e fix test::plain
test::plain uses char indices when it should use byte indices
2023-03-20 18:34:40 -05:00
Skyler Hawthorne
58ea193054 Allow explicit newlines in test DSL
The current test DSL currently has no way to express being at the end of
a line, save for putting an explicit LF or CRLF inside the `#[|]#`. The
problem with this approach is that it can add unintended extra new lines
if used in conjunction with raw strings, which insert newlines for you.

This is a simple attempt to mitigate this problem. If there is an
explicit newline character at the end of the selection, and then it
is immediately followed by the same newline character at the right end
of the selection, this following newline is removed. This way, one can
express a cursor at the end of a line explicitly.
2023-03-20 18:34:40 -05:00
Skyler Hawthorne
a264faa98d refactor test editor config 2023-03-20 18:34:40 -05:00
Skyler Hawthorne
1db252913b print doc state during tests 2023-03-20 18:34:40 -05:00
Skyler Hawthorne
5b07ce76fc make TestCase::From more generic 2023-03-20 18:34:40 -05:00
Skyler Hawthorne
8c5ec95ac0 factor write command tests to own module 2023-03-20 18:34:40 -05:00
exp80
770496511c
Fix highlighting in picker with multiple columns (#6333) 2023-03-18 11:16:40 -05:00
Pascal Kuthe
b6a4927f00 discard outdated workspace edits recived from the LS 2023-03-16 15:45:49 +09:00
Pascal Kuthe
3c9d5d0215 discard outdated diagnostics recived by the LS 2023-03-16 15:45:49 +09:00
Thomas Schollenberger
2a27d1b505
Prevent whitespace from rendering inside inlay hints (#6312)
* fix spaces and nbsps showing in inlay hints

* remove origin

* virtual tab + fix unneeded clone

* update virtual tab determining location

* fix clippy lint
2023-03-16 15:45:16 +09:00
Blaž Hrastnik
75ebc1fcbc
fix compilation 2023-03-14 11:56:18 +09:00
Kyle Smith
27aa919f1c
Only complete appropriate arguments for typed commands. (#5966) 2023-03-14 11:54:46 +09:00
Jonatan Pettersson
d479adfdc6
Add undercurl config option #6196 (#6253)
If set to 'true' this option will force terminal undercurl support.
2023-03-14 11:53:38 +09:00
dependabot[bot]
b558ce7148
build(deps): bump indoc from 2.0.0 to 2.0.1 (#6302)
Bumps [indoc](https://github.com/dtolnay/indoc) from 2.0.0 to 2.0.1.
- [Release notes](https://github.com/dtolnay/indoc/releases)
- [Commits](https://github.com/dtolnay/indoc/compare/2.0.0...2.0.1)

---
updated-dependencies:
- dependency-name: indoc
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-13 19:26:41 -05:00
dependabot[bot]
4d4bb07419
build(deps): bump libc from 0.2.139 to 0.2.140 (#6304)
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.139 to 0.2.140.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.139...0.2.140)

---
updated-dependencies:
- dependency-name: libc
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-13 19:24:50 -05:00
Francesc Elies
d15f9721a5
LSP: Separate diagnostic picker message and code (#6095) 2023-03-13 12:01:21 -05:00
misiasty3
db8e9f5bb2
Check language server symbol renaming support before prompting (#6257)
Co-authored-by: Poliorcetics <poliorcetics@users.noreply.github.com>
2023-03-13 10:29:23 -05:00
Cole Helbling
34934733b3
helix-term: send the STOP signal to all processes in the process group (#3546)
* helix-term: send the STOP signal to all processes in the process group

From kill(3p):

    If pid is 0, sig shall be sent to all processes (excluding an unspecified set
    of  system processes) whose process group ID is equal to the process group ID
    of the sender, and for which the process has permission to send a signal.

This fixes the issue of running `git commit`, attempting to suspend
helix with ^Z, and then not regaining control over the terminal and
having to press ^Z again.

* helix-term: use libc directly to send STOP signal

* helix-term: document safety of libc::kill

* helix-term: properly handle libc::kill's failure

I misread the manpage for POSIX `kill` -- it returns `-1` in
the failure case, and sets `errno`, which is retrieved via
`std::io::Error::last_os_error()`, has its string representation printed
out, and then exits with the matching status code (or 1 if, for whatever
reason, there is no matching status code).

* helix-term: expand upon why we need to SIGSTOP the entire process group

Also add a link back to one of the upstream issues.
2023-03-13 20:08:57 +08:00
Michael Davis
4f066b1cc6
LSP: No-op client/registerCapability requests (#6258) 2023-03-13 09:29:58 +09:00
Pascal Kuthe
171d28d2bd
indent snippets to line indent instead of completion start (#6263) 2023-03-11 11:34:43 +09:00
Poliorcetics
bdcd4d9411
Feat: LSP Type Hints (#5934)
* misc: missing inline, outdated link

* doc: Add new theme keys and config option to book

* fix: don't panic in Tree::try_get(view_id)

Necessary for later, where we could be receiving an LSP response
for a closed window, in which case we don't want to crash while
checking for its existence

* fix: reset idle timer on all mouse events

* refacto: Introduce Overlay::new and InlineAnnotation::new

* refacto: extract make_job_callback from Context::callback

* feat: add LSP display_inlay_hint option to config

* feat: communicate inlay hints support capabilities of helix to LSP server

* feat: Add function to request range of inlay hint from LSP

* feat: Save inlay hints in document, per view

* feat: Update inlay hints on document changes

* feat: Compute inlay hints on idle timeout

* nit: Add todo's about inlay hints for later

* fix: compute text annotations for current view in view.rs, not document.rs

* doc: Improve Document::text_annotations() description

* nit: getters don't use 'get_' in front

* fix: Drop inlay hints annotations on config refresh if necessary

* fix: padding theming for LSP inlay hints

* fix: tracking of outdated inlay hints should not be dependant on document revision (because of undos and such)

* fix: follow LSP spec and don't highlight padding as virtual text

* config: add some LSP inlay hint configs
2023-03-11 11:32:14 +09:00
Dimitar Gyurov
1661e4b5e1
Add a version-control statusline element (#5682) 2023-03-10 16:42:42 -06:00
Pascal Kuthe
d63e570e0a treat replace/insertmode consistently, default to insert 2023-03-10 16:54:17 +09:00
Pascal Kuthe
b1f7528090 fix snippet bugs and multicursor completion edgecases
Multicursor completions may overlap and therefore overlapping
completions must be dropped to avoid crashes. Furthermore, multicursor
edits might simply be out of range if the word before/after the cursor
is shorter. This currently leads to crashes, instead these selections
are now also removed for completions.

This commit also significantly refactors snippet transaction generation
so that tabstops behave correctly with the above rules. Furthermore,
snippet tabstops need to be carefully mapped to ensure their position
is correct and consistent with our selection semantics. Finally,
we now keep a partially updated Rope while creating snippet
transactions so that we can fill information into snippets that
depends on the position in the document.
2023-03-10 16:54:17 +09:00
Taylor C. Richberger
9b4326b18b allow LSP insert text to replace non-matching prefixes (#5469)
Most LSPs will complete case-insensitive matches, particularly from
lowercase to uppercase.  In some cases, notably Pyright, this is given
as a simple insert text instead of TextEdit.  When this happens, the
prefix text was left unedited.
2023-03-10 16:54:17 +09:00
paul-scott
ce1fb9e64c
Generalised to multiple runtime directories with priorities (#5411)
* Generalised to multiple runtime directories with priorities

This is an implementation for #3346.

Previously, one of the following runtime directories were used:

1. `$HELIX_RUNTIME`
2. sibling directory to `$CARGO_MANIFEST_DIR`
3. subdirectory of user config directory
4. subdirectory of path to helix executable

The first directory provided / found to exist in this order was used as a
root for all runtime file searches (grammars, themes, queries).

This change lowers the priority of `$HELIX_RUNTIME` so that the user
config runtime has higher priority. More significantly, all of these
directories are now searched for runtime files, enabling a user to override
default or system-level runtime files. If the same file name appears
in multiple runtime directories, the following priority is now used:

1. sibling directory to `$CARGO_MANIFEST_DIR`
2. subdirectory of user config directory
3. `$HELIX_RUNTIME`
4. subdirectory of path to helix executable

One exception to this rule is that a user can have a `themes`
directory directly in the user config directory that has higher piority
to `themes` directories in runtime directories. That behaviour has been
preserved.

As part of implementing this feature `theme::Loader` was simplified
and the cycle detection logic of the theme inheritance was improved to
cover more cases and to be more explicit.

* Removed AsRef usage to avoid binary growth

* Health displaying ;-separated runtime dirs

* Changed HELIX_RUNTIME build from src instructions

* Updated doc for more detail on runtime directories

* Improved health symlink printing and theme cycle errors

The health display of runtime symlinks now prints both ends of the
link.

Separate errors are given when theme file is not found and when the
only theme file found would form an inheritence cycle.

* Satisfied clippy on passing Path

* Clarified highest priority runtime directory purpose

* Further clarified multiple runtime details in book

Also gave markdown headings to subsections.

Fixed a error with table indentation not building
table that also appears present on master.

---------

Co-authored-by: Paul Scott <paul.scott@anu.edu.au>
Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
2023-03-09 23:50:43 +09:00
gibbz00
2cf4ce2356
Fix shrink_selection with multiple cursors. (#6093)
* Fix #6092

Cause were some incorrect assumptions that missed an edge case in the
`Selection.contains()` calculation. Tests were added accordingly.

* Fix Selection.contains() edge-case handling.

Removing the len check short-circuit was the only thing needed as
pointed out by @dead10ck.
2023-03-09 13:08:28 +09:00
Pascal Kuthe
aabc8af95d correctly store snapshots when repeating insert-mode actions
Repeating completions currently crates a savepoint when a completion
popup was triggered (so after the request completed). Just like for
normal completions the savepoint must be created at the request.

The occurrence of the completion request was previously not saved in
`last_insert`. To that end a new `InsertEvent::RequestCompletion`
variant has been added. When replayed this event creates a snapshot
that is "actived" by the `TriggerCompletion` event and subsequently
used during any `InsertEvent::CompletiuonApply` events.
2023-03-09 13:01:02 +09:00
Pascal Kuthe
8cb7cdfd7a discard stale completion requests
Completion requests are computed asynchronously to avoid common micro
freezes while editing. This means that once a completion request
completes, the state of the editor might have changed. Currently,
there is a check to ensure we are still in insert mode. However,
we also need to ensure that the view and document hasn't changed
to avoid accidentally using a savepoint with the wrong view/document.

Furthermore, the editor might request a new completion while the
previous completion request hasn't complemented yet. This can
lead to weird flickering or an outdated completion request replacing
a newer completion that has already completed (the LSP server
is not required to process completion requests in order). This change
also needed to ensure determinism/linear ordering so that completion
popup always correspond to the last completion request.
2023-03-09 13:01:02 +09:00
Pascal Kuthe
e8898fd9a8 store multiple snapshots on the document at once
Fixing autocomplete required moving the document savepoint before the
asynchronous completion request. However, this in turn causes new bugs:

If the completion popup is open, the savepoint is restored when the
popup closes (or another entry is selected). However, at that point
a new completion request might already have been created which
would have replaced the new savepoint (therefore leading to incorrectly
applied complies).

This commit fixes that bug by allowing in arbitrary number of
savepoints to be tracked on the document. The savepoints are reference
counted and therefore remain valid as long as any reference to them
remains. Weak reference are stored on the document and any reference
that can not be upgraded anymore (hence no strong reference remain)
are automatically discarded.
2023-03-09 13:01:02 +09:00
Pascal Kuthe
2588fa3710 save selection before completion savepoint
Currently, the selection is not saved/restored when completion
checkpoints are applied. This is usually fine because undoing changes
usually restores maps selections back in insert mode. But this is not
always the case and especially problematic in the presence of
multi-cursor completions (since completions are applied relative to
the selection/cursor) and snippets (which can change the selection)
2023-03-09 13:01:02 +09:00
Pascal Kuthe
4300a3ad05 create savepoint before requesting completion 2023-03-09 13:01:02 +09:00
Kyle Smith
44ff8a1df1
LSP: Support textDocument/prepareRename (#6103)
* LSP: Support textDocument/prepareRename

'textDocument/prepareRename' can be used by the client to ask the
server the range of the symbol under the cursor which would be changed
by a subsequent call to 'textDocument/rename' with that position.

We can use this information to fill the prompt with an accurate prefill
which can improve the UX for renaming symbols when the symbol doesn't
align with the "word" textobject. (We currently use the "word"
textobject as a default value for the prompt.)

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

* clippy fixes

* rustfmt

* Update helix-term/src/commands/lsp.rs

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

* Update helix-term/src/commands/lsp.rs

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

* fix clippy from suggestions

* Update helix-term/src/commands/lsp.rs

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

---------

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2023-03-08 11:11:43 +09:00
Clément Delafargue
8dd1ab4899
Softwrapping improvements (#5893)
* use max_line_width + 1 during softwrap to account for newline char

Helix softwrap implementation always wraps lines so that the newline
character doesn't get cut off so he line wraps one chars earlier then
in other editors. This is necessary, because newline chars are always
selecatble in helix and must never be hidden.

However That means that `max_line_width` currently wraps one char
earlier than expected. The typical definition of line width does not
include the newline character and other helix commands like `:reflow`
also don't count the newline character here.

This commit makes softwrap use `max_line_width + 1` instead of
`max_line_width` to correct the impedance missmatch.

* fix typos

Co-authored-by: Jonathan Lebon <jonathan@jlebon.com>

* Add text-width to config.toml

* text-width: update setting documentation

* rename leftover config item

* remove leftover max-line-length occurrences

* Make `text-width` optional in editor config

When it was only used for `:reflow` it made sense to have a default
value set to `80`, but now that soft-wrapping uses this setting, keeping
a default set to `80` would make soft-wrapping behave more aggressively.

* Allow softwrapping to ignore `text-width`

Softwrapping wraps by default to the viewport width or a configured
`text-width` (whichever's smaller). In some cases we only want to set
`text-width` to use for hard-wrapping and let longer lines flow if they
have enough space. This setting allows that.

* Revert "Make `text-width` optional in editor config"

This reverts commit b247d526d69adf41434b6fd9c4983369c785aa22.

* soft-wrap: allow per-language overrides

* Update book/src/configuration.md

Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>

* Update book/src/languages.md

Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>

* Update book/src/configuration.md

Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>

---------

Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
Co-authored-by: Jonathan Lebon <jonathan@jlebon.com>
Co-authored-by: Alex Boehm <alexb@ozrunways.com>
Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
2023-03-08 11:02:11 +09:00
Kyle Smith
f4bdbe4674
Do not add intermediate lines to jumplist with :<linenum> command. (#5751)
* Do not add intermediate lines to jumplist with :<linenum> command.

* Revert jumplist index changes.

* Reduce calculations during update cycle.

* Use jumplist for undo, set jumplist before preview.

* remove some debug logging

* Revert "remove some debug logging"

This reverts commit 5772c4327e7121c53ea0726a4d7333ae1c413ffb.

* Revert "Use jumplist for undo, set jumplist before preview."

This reverts commit f73a1b29824feaf16477b9df547fb28d9db81923.

* Add last_selection, update implementation.

* @pascalkuthe initial feedback

* Ensure ":goto 123" keybinding works as expected.

* fix clippies, prefer expect() for expect last_selection state
2023-03-08 10:53:31 +09:00
Michael Davis
0c6d25acae
DynamicPicker: Recalculate column widths for new options (#6004)
This fixes blank row text in a DynamicPicker which is initially given
no options. This can happen for language servers which respond to
the workspace symbol request for an empty query with an empty list
of symbols, and that behavior is somewhat common since returning all
symbols as the spec suggests is very expensive.

For empty options, `Picker::new` calculated the widths of each column
as 0. We can recalculate the column widths when the new options are
set to fix this. This refactor is also a good opportunity to formalize
setting new options on a picker: besides setting the new options and
calculating column widths we also want to reset the cursor and rescore
the options.
2023-03-08 10:51:52 +09:00
Michael Davis
6dc017b9e2
Jump to symbol ranges in LSP goto commands (#5986)
This follows prior changes like 42ad1a9e: we select the range given
by the language server rather than the starting point.
2023-03-08 10:51:29 +09:00
Michael Davis
170593161c
LSP: Send replies for malformed and unhandled RPC requests (#6058)
Previously we did not respond to malformed or unhandled LSP requests.
The JSONRPC spec says that all non-notification requests must have
responses:

> When a rpc call is made, the Server MUST reply with a Response,
> except for in the case of Notifications

(Note that Helix is the "Server" in this case. Also from the spec:
"The Server is defined as the origin of Response objects and the
handler of Request objects.")

So this change sends error replies for requests which can't be parsed
or handled. Request IDs are also now added to the log messages for
unhandled requests.
2023-03-08 10:50:57 +09:00
Michael Davis
3d85024717 Move terminal claim/restore code to helix-tui
This moves the `Application::claim_term` and
`helix-term::application::restore_term` functions into the helix-tui
crate. How the terminal should be claimed and restored is a TUI concern
and is implemented differently through different TUI backends.

This cleans out a lot of crossterm and TUI code in Application and
makes it easier to modify claim/restore based on information we query
from the terminal host. The child commit will take advantage of this
to cache the check for whether the host terminal supports the keyboard
enhancement protocol. Without this change, caching that information
takes much more code which is not easily reusable for anything else.

The code to restore the terminal is somewhat duplicated by this patch:
we want to restore the terminal in cases of panics. Panic handler hooks
must live for `'static` and the Application's terminal does not.
2023-03-08 10:49:32 +09:00
Pascal Kuthe
48b6aa9a69
Add command for resetting diff hunks (#5736) 2023-03-08 10:49:14 +09:00
Andrii Grynenko
8c2e447b16 Handle snippets for LSPs not providing offsets for completion 2023-03-08 10:48:35 +09:00
Andrii Grynenko
1866b43cd3 Render every LSP snippets for every cursor
This refactors the snippet logic to be largely unaware of the rest of
the document. The completion application logic is moved into
generate_transaction_from_snippet which is extended to support
dynamically computing replacement text.
2023-03-08 10:48:35 +09:00
Pascal Kuthe
ba24cfe912 Delete snippet placeholders when accepting completion
When accepting a snippet completion we automatically delete the
placeholders for now as doing so manual is quite cumbersome. In the
future we should keep these as a mark + virtual text that is
automatically removed once the cursor moves there.
2023-03-08 10:48:35 +09:00
Michael Davis
b9b1ec2208 Apply snippets as transactions 2023-03-08 10:48:35 +09:00
Davide Galassi
f976c004e2
Allow LSP server to be stopped (#5964) 2023-03-07 18:34:31 -06:00