With a directory with spaces in the name (for example
`mkdir -p 'Temp/Abc Def'`), completing `Temp/Ab` would create a
completion item `'Temp/AbAbc Def'`. Now it correctly completes
`'Temp/Abc Def'`
On Windows for example the behavior of this function typically diverges
from the usual behavior on Unix. Instead of checking that the inserted
string starts with `'\n'` (untrue for for CRLF line endings) we need to
check that the first grapheme cluster in the string is a line ending.
(All line endings are single grapheme clusters.)
This fixes a regression from the refactor of the highlighters when
switching to tree-house. The old `StyleIter` used `renderer.text_style`
as the base style rather than `Style::default()` for syntax highlights.
The result was that any text not captured by a syntax highlight query
was styled with no foreground or background, defaulting to the
terminal's foreground/background. This could cause text in markdown
files to look off-colored depending on your terminal configuration.
(Though you wouldn't notice if your 'ui.text' theming matches your
terminal's theming.)
Previously the statusline `write` function only accepted a string
and optional Style, so all rendering functions converted text to
strings. Some elements write spans with `&'static str`s, however, making
this unnecessary since `Span<'a>` is a wrapper around `Cow<'a, str>` and
style, and a `Span<'static>` would outlive all required lifetimes.
Moreover many elements could produce `Span<'a>` according to the
lifetime in `RenderContext` in the future, potentially re-borrowing from
the Editor borrow, so this change could save allocations for many
file-type elements (with more future changes). This is not explored in
this patch since the statusline functions currently add bespoke padding
per-element, but with a future refactor to make spacing consistent this
could be possible.
This change refactors the write function to accept a `Span<'a>` and
rewrites some related code to fit the codebase better (preferring `for`
to iterator's `for_each` for example). The new code is more complicated
lifetime-wise but avoids allocations in these cases:
* spacer for mode name when a pane is not focused
* LSP spinner frames
* '●' (workspace) diagnostic indicators
* " W " workspace diagnostic prefix
* file modification indicators
* read-only indicators
* spacer element
... and opens the door to avoid allocation for file name elements in the
future.
If you configure a subset of severities to show in the workspace
diagnostics statusline element you can see the 'W' (and surrounding
space) without any diagnostic indicators. This is the case by default
as it's configured to show warnings and errors only - if you have only
hints in your workspace like if you open `application.rs` in Helix for
example then you would see the 'W' and no indicators.
This change checks that any of the configured diagnostics are non-zero
and bails early if there are none.
This type also exists on `Editor`. This change brings it to the
`Document` as well because the replacement for `Syntax` in the child
commits will eliminate `Syntax`'s copy of `syn_loader`. `Syntax` will
also be responsible for returning the highlighter and query iterators
(which will borrow the loader), so the loader must be separated from
that type.
In the long run, when we make a larger refactor to have
`Document::apply` be a function of the `Editor` instead of the
`Document`, we will be able to drop this field on `Document` - it is
currently only necessary for `Document::apply`. Once we make that
refactor, we will be able to eliminate the surrounding `Arc` in
`Arc<ArcSwap<syntax::Loader>>` and use the `ArcSwap` directly instead.
The point of ghost transactions is to avoid notifying language servers
about changes since the change is meant to be temporary. This is used
for completion while selecting items in the menu: updating the language
server would mess up incomplete completions.
When a document is changed by a ghost transaction the language server
will not be notified so its understanding of the document will not be
synchronized and any positions it sends may be out-of-date. So we should
avoid triggering a request for new document color information when a
document is changed by a ghost transaction.
Previously the `call` helper (and its related functions) returned a
`serde_json::Value` which was then decoded either later in the client
(see signature help and hover) or by the client's caller. This led to
some unnecessary boilerplate in the client:
let resp = self.call::<MyRequest>(params);
Some(async move { Ok(serde_json::from_value(resp.await?)?) })
and in the caller. It also allowed for mistakes with the types. The
workspace symbol request's calling code for example mistakenly decoded a
`lsp::WorkspaceSymbolResponse` as `Vec<lsp::SymbolInformation>` - one of
the untagged enum members (so it parsed successfully) but not the
correct type.
With this change, the `call` helper eagerly decodes the response to a
request as the `lsp::request::Request::Result` trait item. This is
similar to the old helper `request` (which has become redundant and has
been eliminated) but all work is done within the same async block which
avoids some awkward lifetimes. The return types of functions like
`Client::text_document_range_inlay_hints` are now more verbose but it is
no longer possible to accidentally decode as an incorrect type.
Additionally `Client::resolve_code_action` now uses the `call_with_ref`
helper to avoid an unnecessary clone.
This adds events for:
* a document being opened
* a document being closed
* a language server sending the initialized notification
* a language server exiting
and also moves some handling done for these scenarios into hooks,
generally moving more into helix-view. A hook is also added on
`DocumentDidChange` which sends the `text_document_did_change`
notification - this resolves a TODO in `document`.
This resolves a TODO in the core diagnostic module to refactor this
type. It was originally an alias of `LanguageServerId` for simplicity.
Refactoring as an enum is a necessary step towards introducing
"internal" diagnostics - diagnostics emitted by core features such as
a spell checker. Fully supporting this use-case will require further
larger changes to the diagnostic type, but the change to the provider
can be made first.
Note that `Copy` is not derived for `DiagnosticProvider` (as it was
previously because `LanguageServerId` is `Copy`). In the child commits
we will add the `identifier` used in LSP pull diagnostics which is a
string - not `Copy`.
This is the same change as 1c9a5bd366 but for:
* document symbols
* workspace symbols
* goto definition/declaration/.../references
* hover
Instead of bailing when one server fails, we log an error and continue
gathering items from the other responses.
When requesting code actions from multiple LSP servers,
rather than bailing as soon as an error is encountered,
instead log the error and then keep going so that successful
requests can be presented to the user.
This is a minor move that will make future refactors of code actions
simpler. We should be able to move nearly all code action functionality
into `helix-view`, save UI stuff like the `menu::Item` implementation
and dealings with the compositor.
if `config.toml` either does not have `editor.true-color` or sets
it to false, many (most?) themes stop being usable. when loading such a
theme, Helix falls back to the default theme, but didn't mention this
anywhere - even in `~/.cache/helix/helix.log` when run with `-v`.
if this occurs when reloading a theme at runtime with `:theme`, there's
a fairly helpful error about
> `theme requires true color support`
seems worth logging about this if it happens during startup too.
This matches the behavior described by the EditorConfig spec for its
`insert_final_newline` option:
> Editors must not insert newlines in empty files when saving those
> files, even if `insert_final_newline = true`.
Co-authored-by: Axlefublr <101342105+Axlefublr@users.noreply.github.com>
These match the equivalent options in VSCode. `trim_trailing_whitespace`
is also the name used by EditorConfig.
* `trim-final-newlines` trims any extra line endings after the final one
* `trim-trailing-whitespace` trims any trailing whitespace (but not
empty lines)
Render rulers before the cursor to ensure that the cursor, when over
a ruler, is not hidden from view. Without this, you typically end up
with 1) foreground text that is the same as the background if the
ruler doesn't already have a foreground and 2) no visible cursor,
because the ruler's background color took precedence. By moving the
rulers before the cursor, this ensures that the theme is still rendered
more or less the way one would visually expect things to turn out.
This follows a pattern used in the signature help request for example.
Moving the json deserialization into the return future of
`text_document_hover` makes the types easier for callers to work with.