João Távora [Tue, 15 Dec 2020 12:24:13 +0000 (12:24 +0000)]
Robustify previous fix of onchange breakage
From the in-code comments:
;; githubhttps://github.com/joaotavora/eglot/issues/259 and githubhttps://github.com/joaotavora/eglot/issues/367: With `capitalize-word' or somesuch,
;; `before-change-functions' always records the whole word's `b-beg'
;; and `b-end'. Similarly, when coalescing two lines into one,
;; `fill-paragraph' they mark the end of the first line up to the end
;; of the second line. In both situations, args received here
;; contradict that information: `beg' and `end' will differ by 1 and
;; will likely only encompass the letter that was capitalized or, in
;; the sentence-joining situation, the replacement of the newline with
;; a space. That's we keep markers _and_ positions so we're able to
;; detect and correct this. We ignore `beg', `len' and
;; `pre-change-len' and send "fuller" information about the region
;; from the markers. I've also experimented with doing this
;; unconditionally but it seems to break when newlines are added.
João Távora [Mon, 14 Dec 2020 17:08:26 +0000 (17:08 +0000)]
Don't let m-x fill-paragraph break didchange
M-x fill-paragraph represents some paragraph-fillling changes very
summarily. Filling
1 // foo
2 bar
Into
1 // foo bar
Only makes two changes: a deletion of the "// " and a replacement of a
newline with a space character. The second change fooled Eglot's fix
for https://github.com/joaotavora/eglot/issues/259, by making a change similar to the one it is made to detect
and correct. That fix should taget things that happen on the same
line, this not being one of those things.
* eglot.el (eglot--after-change): Only apply fix to https://github.com/joaotavora/eglot/issues/259 if
case-fiddling happens on same line.
João Távora [Tue, 3 Nov 2020 10:26:03 +0000 (10:26 +0000)]
Don't force eglot-strict-mode completely in eglot--dcase
Doing so was by design, since there's much ambiguity between the
CodeAction and Command objects. But 'disallow-non-standard-keys is
not necessary to disambiguate, and proved harmful in this bug.
To design a completion-in-region-function replacement that leverages
the elements in completion-at-point-functions, we must ensure that
their :exit-function parts execute in the correct buffer. That is the
buffer where the text to be completed lives, not necessarily the
buffer being used for user interaction.
Later on, this guarantee should be provided by Emacs itself, perhaps
by putting the correct with-current-buffer call in completion--done.
Copyright-paperwork-exempt: yes Co-authored-by: João Távora <joaotavora@gmail.com>
* eglot.el (eglot-completion-at-point): Ensure :exit-function's
buffer is where the source is.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/505
João Távora [Mon, 13 Jul 2020 22:43:35 +0000 (23:43 +0100)]
Reload eldoc if needed on emacs < 28
ElDoc is preloaded in Emacs, so `require`-ing won't guarantee we are
using the latest version from GNU Elpa when we load eglot.el. Use an
heuristic to see if we need to `load` it in Emacs < 28.
* eglot.el (Package-Requires): Require eldoc 1.5.0
(top): Sometimes load eldoc
João Távora [Wed, 3 Jun 2020 17:40:58 +0000 (18:40 +0100)]
Delegate "hover" and "signature" doc synchronization efforts to eldoc
Uses Eldoc's eldoc-documentation-functions variable. In Eldoc v1.0.0
that variable was already available as a way of handling/composing
multiple docstrings from different sources, but it didn't work
practically with mutiple concurrent async sources. This was fixed in
1.1.0, which Eglot now requires.
This fixes the synchronization problems reported in https://github.com/joaotavora/eglot/issues/494 and also
issue https://github.com/joaotavora/eglot/issues/439. It is likely that some of the exact doc-composing
functionality in Eglot, (developed during those issues) was lost, and
has to be remade, quite likely in Eldoc itself.
Flymake is now also an Eldoc producer, and therefore the problems of
github issues https://github.com/joaotavora/eglot/issues/481 and https://github.com/joaotavora/eglot/issues/454 will also soon be fixed as soon as Eglot
starts using the upcoming Flymake 1.0.9.
* NEWS.md: New entry.
* README.md (eglot-put-doc-in-help-buffer)
(eglot-auto-display-help-buffer): Remove mention to these options.
* eglot.el
(Package-Requires:) Require eldoc.el 1.1.0.
(eglot--when-live-buffer): Rename from eglot--with-live-buffer.
(eglot--when-buffer-window): New macro.
(eglot--after-change, eglot--on-shutdown, eglot-ensure): Use eglot--when-live-buffer.
(eglot--managed-mode): Use eglot-documentation-functions and eldoc-documentation-strategy.
(eglot--highlights): Move down.
(eglot-signature-eldoc-function, eglot-hover-eldoc-function)
(eglot--highlight-piggyback): New eldoc functions.
(eglot--help-buffer, eglot--update-doc)
(eglot-auto-display-help-buffer, eglot-put-doc-in-help-buffer)
(eglot--truncate-string, eglot-doc-too-large-for-echo-area)
(eglot-help-at-point): Remove all of this.
(eglot--apply-workspace-edit): Call eldoc manually after an edit.
(eglot-mode-map): Remap display-local-help to eldoc-doc-buffer
João Távora [Sun, 31 May 2020 10:49:51 +0000 (11:49 +0100)]
Fix small problems around eglot's help buffer
Specifically:
- correctly format the message shown to the user about doc being truncated
- don't show message if the buffer is showing in some frame's window
- correctly name the help buffer switched to with `C-h .'.
This is still not ideal:
- When the `C-h .' suggestion is shown to the user, typing that keybinding
shouldn't result in a new LSP request to fetch probably the same info;
- All this functionality belongs in eldoc.el.
* eglot.el (eglot-help-at-point): Fix buffer name.
(eglot--update-doc): Provide more help.
This way modes used to represent hover info text, such as
gfm-view-mode can e.g. filter out invisible text by providing own
`filter-buffer-substring-function'.
* eglot.el (eglot--format-markup): Use `filter-buffer-substring'.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/482
Rework computation of string given to eldoc (again)
Co-authored-by: Andreii Kolomoiets <andreyk.mad@gmail.com>
Also do some refactoring to join similar logic in
eglot-doc-too-large-for-echo-area and eglot--truncate-string.
* eglot.el (eglot-doc-too-large-for-echo-area): Now returns the
number of lines available.
(eglot--truncate-string): New helper.
(eglot--first-line-of-doc, eglot--top-lines-of-doc): Remove.
(eglot--update-doc): Use new helpers.
* eglot-tests.el (hover-multiline-doc-locus): New test
GitHub-reference: close https://github.com/joaotavora/eglot/issues/459
João Távora [Sat, 2 May 2020 23:43:00 +0000 (00:43 +0100)]
Kind of honour eldoc-echo-area-use-multiline-p
A reworking of an idea and original implementation by Andrii
Kolomoiets <andreyk.mad@gmail.com>. It doesn't honor it completely
because the semantics for a non-t, non-nil value are tricky. And we
don't always exactly know what the symbol prefix reliably.
* eglot.el (eglot--update-doc): Kind of honour
eldoc-echo-area-use-multiline-p.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/443
João Távora [Sat, 2 May 2020 09:30:28 +0000 (10:30 +0100)]
Also check types when destructuring lsp objects
The problem in this issue is that the disambiguation between Command
and CodeAction objects can only be performed by checking the types of
the keys involved. So we added that to the spec and check it at
runtime.
* eglot.el (eglot--lsp-interface-alist): Add types to
Command. Tweak docstring.
(eglot--check-object): Renamed from eglot--call-with-interface.
(eglot--ensure-type): New helper.
(eglot--interface): New helper.
(eglot--check-dspec): Renamed from eglot--check-interface.
(eglot--dbind): Simplify.
(eglot-code-actions): Adjust indentation.
* eglot-tests.el (eglot-dcase-issue-452): New test.
Co-authored-by: João Távora <joaotavora@gmail.com>
* eglot.el (eglot-eldoc-function): Pass nil to eglot--update-doc
on empty hover info.
(eglot--update-doc): Skip update eglot help buffer if string
is nil.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/439
Tests: print contents of *eglot ...* buffers in batch mode.
Useful for the CI on github. To be able to see more of the context of
a failure.
* eglot.el (eglot-server-initialized-hook): Changed semantics. Now
called when an instance of `eglot-lsp-server' is created as part of
the "connect to server" flow. Previously, there was no difference
between this hook and `eglot-connect-hook' which continues to be run
once a connection was successfully established. The
`eglot-server-initialized-hook' will now capture ALL server instances
including those that failed to be started. This change was necessary
to make the test suite be able to dump the output of processes that
fail to start when running the test suite in batch mode ("make check"
and the CI.) In PR https://github.com/joaotavora/eglot/issues/448 it was decided that it is ok to change the
semantics of this hook rather than introducing a new hook.
(eglot--connect): Change place of where the hook is run.
(eglot-connect-hook): Initialized now with
`eglot-signal-didChangeConfiguration' which was kept in
`eglot-server-initialized-hook' before.
* eglot-tests.el (eglot--call-with-fixture): Use
`eglot-server-initialized-hook' rather than `eglot-connect-hook'. And
dump the contents of the *EGLOT ...* buffers when run in
`noninteractive' (i.e. batch) mode.
(eglot--cleanup-after-test): New auxiliary function. Extracted
verbatim out of `eglot--call-with-fixture` in order to lower the
latter's LOC.
Co-authored-by: João Távora <joaotavora@gmail.com>
* eglot.el (eglot-move-to-lsp-abiding-column): use
already existing function to refer to lsp-abiding-column
GitHub-reference: close https://github.com/joaotavora/eglot/issues/397
João Távora [Sun, 19 Jan 2020 10:02:55 +0000 (11:02 +0100)]
Fix eglot-move-to-lsp-abiding-column ()
Ensure conformance with the this part of the specification: "if the
character value is greater than the line length it defaults back to
the line length."
Fix regression introduced in 70e6157b (https://github.com/joaotavora/eglot/issues/315). According to the
LSP specification the exit notification and the shutdown request
shouldn't have arguments ("params: void"). Note that jsonrpc.el
send nil as null on the wire.
* eglot.el (eglot-shutdown): Change back the arguments of
:shutdown and :exit to nil.
Felicián Németh [Fri, 22 Nov 2019 17:35:01 +0000 (18:35 +0100)]
Make a public reader for project-nickname
Close https://github.com/joaotavora/eglot/issues/399.
* eglot.el (eglot-lsp-server): Add a public reader for
project-nickname as eglot-project-nickname.
(eglot--connect, eglot--read-server, eglot--mode-line-format): Use
the public variant.
GitHub-reference: per https://github.com/joaotavora/eglot/issues/354
Felicián Németh [Fri, 22 Nov 2019 15:55:04 +0000 (16:55 +0100)]
Add public hook eglot-managed-mode-hook
Per https://github.com/joaotavora/eglot/issues/354.
* eglot.el (eglot-managed-p): New function.
(eglot--managed-mode-hook): Obsolete it.
(eglot-managed-mode-hook): New hook variable.
(eglot--managed-mode): Run the new hook.
* README.md (Customization): Mention the new hook.
João Távora [Wed, 1 Jan 2020 22:05:29 +0000 (22:05 +0000)]
Avoid double shutdowns and simplify shutdown logic
* eglot.el (eglot-shutdown): Don't turn off eglot--managed-mode here.
(eglot--on-shutdown): Rather here, but without autoshutdown.
(eglot--managed-mode): Don't check eglot--shutdown-requested.
See also https://github.com/joaotavora/eglot/issues/386.
* eglot.el (eglot-code-actions): Replace tmm with completing-read
Copyright-paperwork-exempt: yes Co-authored-by: João Távora <joaotavora@gmail.com>
GitHub-reference: close https://github.com/joaotavora/eglot/issues/393
New eglot-confirm-server-initiated-edits defcustom
* eglot.el (eglot-confirm-server-initiated-edits): New defcustom.
Copyright-paperwork-exempt: yes Co-authored-by: João Távora <joaotavora@gmail.com>
GitHub-reference: close https://github.com/joaotavora/eglot/issues/382
Augusto Stoffel [Wed, 18 Dec 2019 12:44:28 +0000 (13:44 +0100)]
Add built-in support for tex and friends
plain-tex-mode and latex-mode are derived from tex-mode. Some other
TeX-related modes are not, so they require an explicit mention in
eglot-server-programs.
* README.md (Connecting to a server): Add Digestif to the list
* eglot.el (eglot-server-programs): Add Digestif for TeX-related modes
Copyright-paperwork-exempt: yes
GitHub-reference: close https://github.com/joaotavora/eglot/issues/379
João Távora [Wed, 20 Nov 2019 22:55:29 +0000 (22:55 +0000)]
Resolve compilation warnings
* eglot.el (company-tooltip-align-annotations): Forward declare.
(eglot--cached-server): Renamed from eglot--cached-current-server.
(eglot--managed-mode, eglot-current-server)
(eglot--current-server-or-lose)
(eglot--maybe-activate-editing-mode): use it.
(eglot-completion-at-point): Don't use insertTextFormat.
João Távora [Tue, 12 Nov 2019 08:51:09 +0000 (08:51 +0000)]
Let other imenu functions work if lsp server's doesn't
* eglot.el (eglot--stay-out-of-p): New helper.
(eglot--setq-saving): Use it.
(eglot--managed-mode): Use add-function :before-until for
imenu-create-index-function.
(eglot-imenu): Don't error. Fix indentation.
Felicián Németh [Tue, 12 Nov 2019 12:50:11 +0000 (13:50 +0100)]
Support serverinfo of lsp 3.15.0
Add support for serverInfo from the upcoming specification. This
changeset just stores the info sent by the server and slightly changes
a greeting message. But it opens up the possibility to identify
servers even when eglot uses a TCP connection and therefore makes
possible to implement server specific features (in eglot-x).
Old message:
```
Connected! Server `EGLOT (test-ccls/c++-mode)' now managing `c++-mode' buffers in project `test-ccls'.
```
New message:
```
Connected! Server `ccls' now managing `c++-mode' buffers in project `test-ccls'.
```
* eglot.el (eglot--lsp-interface-alist): Extend it with serverInfo.
(eglot-lsp-server): Add member variable server-info.
(eglot--connect): Store server-info and display server's name
when connected.
João Távora [Sat, 9 Nov 2019 22:58:08 +0000 (22:58 +0000)]
Provide stable eglot-current-server helper
It's better if eglot--current-server is removed, since it was being
abused by other packages, and has side effects. The only place where
it was really needed was eglot--maybe-activate-editing-mode, so the
find-and-cache logic has been moved there. All other places that can
handle a nil server now use eglot-current-server, the external
version.
* eglot.el (eglot-shutdown, eglot, eglot--read-server)
(eglot--mode-line-format): Use eglot-current-server.
(eglot--connect): Update comment.
(eglot--current-server): Remove.
(eglot-current-server): New helper.
(eglot--maybe-activate-editing-mode): find and cache the server here.
* eglot-tests.el (auto-detect-running-server)
(auto-shutdown, auto-reconnect, eglot-ensure)
(slow-async-connection): Use eglot-current-server.
João Távora [Wed, 30 Oct 2019 01:24:10 +0000 (01:24 +0000)]
Use completionitem/resolve more abundantly
It was already used to resolve documentation bits of completions, but
it can also be useful to resolve snippet templates and such.
To resolve a completion, you need some part of a completion to start
with. If it has a :data field exists and the server supports
:resolveProvider, fetch the new object, otherwise use whatever we had
already.
* eglot.el (eglot-completion-at-point): Add another local
function for resolving completions.
GitHub-reference: per https://github.com/joaotavora/eglot/issues/50
João Távora [Mon, 21 Oct 2019 21:25:13 +0000 (22:25 +0100)]
Fix race condition when company-completing quickly
For some reason, probably related to the way that Eglot tries to
maintain the responsiveness of Company completion tooltips (see
below), the user's explicit input will sometimes be surprisingly
deleted by Company, leading to a horrible completion experience.
This is sometimes hard to reproduce, but appears to match this
description perfectly:
https://github.com/joaotavora/eglot/issues/319#issuecomment-542955432
Fortunately, Company has a good fix for this, which is to pass
`:company-require-match 'never` in the completion-at-point function.
This is the fix applied in this commit.
However, this line shouldn't be required since the default value for
`company-require-match` is `company-explicit-action-p`, presumably
meaning that the auto-deletion should never take place for characters
typed by the user.
This points to a bug in Company, or at least something which may have
been exacerbated by the way that Eglot aggressively fetches
completions from the server by passing :cancel-on-input to
`jsonrpc-request`, discarding out-of-date replies. Perhaps that
discarding step bears with it some side-effects that make the
`company-explicit-action-p` test return `nil` instead of the correct
`t`. Company interprets this as carte blanche to delete the last
inserted character.
* eglot.el (eglot-completion-at-point): Use :company-require-match
'never.
GitHub-reference: per https://github.com/joaotavora/eglot/issues/319
João Távora [Mon, 21 Oct 2019 15:07:38 +0000 (16:07 +0100)]
Unbreak m-x vc-revert, which reverts preserving modes
Unlike the normal revert-buffer command, vc-revert, doesn't re-apply
the major mode, meaning it was missing a didOpen to pair with the
didClose that is unconditionally sent on both commands.
Needed to use the dynamic variable revert-buffer-preserve-modes, and,
curiously, also forward-declare it to appease the byte compiler.
* eglot.el (eglot--managed-mode): Use after-revert-hook.
(revert-buffer-preserve-modes): Forward declare.
(eglot--after-revert-hook): Signal didOpen when preserving-modes.
(eglot--maybe-activate-editing-mode): Tweak comment.