1
0
Fork 0
mirror of https://github.com/helix-editor/helix synced 2024-06-01 07:46:05 +02:00
Commit Graph

272 Commits

Author SHA1 Message Date
Michael Davis 3f2de21342
Handle partial failure when sending textDocument/didSave (#10168) 2024-04-06 13:38:51 +09:00
Kirawi 88d455afeb
Use a temporary file for writes (#9236)
Co-authored-by: Pascal Kuthe <pascalkuthe@pm.me>
2024-03-31 17:43:09 -05:00
Pascal Kuthe b46064b8c4 Add an Amp-like jump command
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2024-03-23 15:35:25 +09:00
Pascal Kuthe 69e07ab61e use slices instead of Rc for virtual text 2024-03-23 15:35:25 +09:00
Luis Useche 6a22d7d1ca
Do not stop reloading docs on error (#9870)
In the `reload-all` command, we should not stop reloading the documents
if one error is found. Instead, we should report the error and continue
trying to reload the current open documents. This is useful in cases
where a backing file does not exist temporarily (e.g. when editing a git
patch in the outstanding chain that doesn't have a file just yet).

This change also remove the error messages in the cases where the
backing is `None`, like in new docs or `tutor`.
2024-03-19 12:16:30 +01:00
mo8it e91ec8e880 Optimize getting a relative path 2024-03-19 14:39:46 +09:00
kyfanc fe869e5dc7
fix lsp config reload (#9415)
`syn_loader` was replaced rather than interior value being replace,
old value was still being referenced and not updated after `:config-refresh`.
By using `ArcSwap` like for `config`, each `.load()` call will return the most
updated value.

Co-authored-by: kyfan <kyfan@email>
2024-02-13 11:58:53 +01:00
Pascal Kuthe 87a720c3a1
make path changes LSP spec conform (#8949)
Currently, helix implements operations which change the paths of files
incorrectly and inconsistently. This PR ensures that we do the following
whenever a buffer is renamed (`:move` and workspace edits)

* always send did_open/did_close notifications
* send will_rename/did_rename requests correctly
  * send them to all LSP servers not just those that are active for a
    buffer
  * also send these requests for paths that are not yet open in a buffer (if
    triggered from workspace edit).
  * only send these if the server registered interests in the path
* autodetect language, indent, line ending, ..

This PR also centralizes the infrastructure for path setting and
therefore `:w <path>` benefits from similar fixed (but without didRename)
2024-01-29 01:34:45 +09:00
Michael Davis 6d724a8f33 Re-export `which` from `helix-stdx::env`
We use `which::which` in many crates, so `which` was a separate
dependency across all of them. We can centralize `which` into the
stdx crate so it's easy for all crates to depend on it.

I also moved the rest of `helix-view/src/env.rs` into helix-stdx's
`env` module since it only contained a thin wrapper around `which`
and `std::env`.
2024-01-24 15:47:49 +09:00
Pascal Kuthe 8e592a151f refactor completion and signature help using hooks 2024-01-23 11:20:19 +09:00
Pascal Kuthe 13ed4f6c47 Add hook/event system 2024-01-23 11:20:19 +09:00
Michael Davis 1f916e65cf Create helix-stdx crate for stdlib extensions
helix-stdx is meant to carry extensions to the stdlib or low-level
dependencies that are useful in all other crates. This commit starts
with all of the path functions from helix-core and the CWD tracking that
lived in helix-loader.

The CWD tracking in helix-loader was previously unable to call the
canonicalization functions in helix-core. Switching to our custom
canonicalization code should make no noticeable difference though
since `std::env::current_dir` returns a canonicalized path with
symlinks resolved (at least on unix).
2024-01-18 10:57:53 +09:00
Philipp Mildenberger 41ca46cf8c
Initialize diagnostics when opening a document (#8873) 2024-01-09 10:01:04 +09:00
Pascal Kuthe 4da6191a1c
don't automatically dismiss zero width diagnostics (#9280) 2024-01-09 09:54:55 +09:00
Pascal Kuthe 783ff27b1b consistent diagnostic sorting 2023-12-27 15:28:14 +09:00
Pascal Kuthe 515ef17207 make diagnostics stick to word boundaries
Diagnostics are currently extended if text is inserted at their end. This is
desirable when inserting text after an identifier. For example consider:

let foo = 2;
    --- unused variable

Renaming the identifier should extend the diagnostic:

let foobar = 2;
    ------ unused variable

This is currently implemented in helix but as a consequence adding whitespaces
or a type hint also extends the diagnostic:

let foo      = 2;
    -------- unused variable
let foo: Bar = 2;
    -------- unused variable

In these cases the diagnostic should remain unchanged:

let foo      = 2;
    --- unused variable
let foo: Bar = 2;
    --- unused variable

As a heuristic helix will now only extend diagnostics that end on a word char
if new chars are appended to the word (so not for punctuation/ whitespace).
The idea for this mapping was inspired for the word level tracking vscode uses
for many positions. While VSCode doesn't currently update diagnostics after
receiving publishDiagnostic it does use this system for inlay hints for example.
Similarly, the new association mechanism implemented here can be used for word
level tracking of inlay hints.

A similar mapping function is implemented for word starts. Together
these can be used to make a diagnostic stick to a word. If that word
is removed that diagnostic is automatically removed too. This is the exact
same behavior VSCode inlay hints eixibit.
2023-12-27 15:28:14 +09:00
Pascal Kuthe 8653e1b02f Add config to mark diagnostic sources as persistent 2023-12-27 15:28:14 +09:00
Alexis Mousset 83ac53a109
Fix various typos (#8233) 2023-09-10 15:31:12 -05:00
Ezekiel Warren 6bef982f2d
use which on formatter command (#8064) 2023-08-30 16:51:03 +02:00
Pascal Kuthe 0cb595e226
transition to nucleo for fuzzy matching (#7814)
* transition to nucleo for fuzzy matching

* drop flakey test case

since the picker streams in results now any test that relies
on the picker containing results is potentially flakely

* use crates.io version of nucleo

* Fix typo in commands.rs

Co-authored-by: Skyler Hawthorne <skyler@dead10ck.com>

---------

Co-authored-by: Skyler Hawthorne <skyler@dead10ck.com>
2023-08-30 13:26:21 +09:00
nkitsaini 22f4f313f1
Remove unnecessary `Err` from `get_canonicalized_path` (#8009)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2023-08-20 21:11:32 +02:00
Michael Davis f01ca107fb
Detect non-existent files as non-readonly (#7875) 2023-08-09 03:28:53 +09:00
Connortsui20 fcbac485f8
Show whether file readonly in statusline (#7740) 2023-08-08 14:51:34 +02: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
Pascal Kuthe 4a2337d828
correctly map unsorted positions (#7471)
* correctly map unsorted positions

* Fix typo

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

---------

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2023-06-28 23:35:31 +09:00
Michael Davis 636c91c76b
Mark buffers created from stdin as modified (#7431)
This resolves some confusing behavior where a scratch document created
by piping into hx is discarded when navigating away from that document.

We discard any scratch documents that are not modified and the original
`Editor::new_file_from_stdin` would create unmodified documents. We
refactor this function to create an empty document first and then to
apply the text from stdin as a change.
2023-06-26 11:17:04 -04:00
Blaž Hrastnik 8d39a81aa8 fix: Regression from d491e234f4 2023-06-26 22:20:20 +09:00
Pascal Kuthe d491e234f4 map positions through changes in O(N) 2023-06-26 01:32:31 +09:00
Alex d5af6031f6
Use default line ending in open command (#7357) 2023-06-17 14:36:36 -05:00
Alex 3fb9fafb2a
Add config for default line ending (#5621) 2023-06-16 12:02:15 -05:00
Philipp Mildenberger 073000e54d Maintain language servers TOML array order in `doc.language_servers` 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 8ee599942a Optimize gutter diagnostics and simplify shown_diagnostics 2023-05-18 21:58:17 +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 58c913ce45 Simplify 'lsp_stop' command 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 9639f42766 Refactor doc.shown_diagnostics to avoid an extra HashSet
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
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 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
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 6842fd4c36 clarify comments about completion savepoints
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2023-05-18 15:16:50 +09:00
Pascal Kuthe bcb8c3d34d deduplicate savepoints 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 5406e9f629 correctly handle completion rerequest 2023-05-18 15:16:50 +09:00
John Kelly 87da58578f
Add better error message for file save failure due to parent not existing (#7014)
Fixes #5229
2023-05-11 04:35:43 +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