João Távora [Fri, 10 Aug 2018 01:29:26 +0000 (02:29 +0100)]
Support snippet completions
* eglot.el (eglot-client-capabilities): Declare support for
snippet-based completions.
(eglot-completion-at-point): Expand snippet completions with
YASnippet if that is found.
(eglot-note, eglot-warning, eglot-error): Diagnostic
overlay priorities have to be slightly lower than yasnippet's,
which must be reasonably high.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/50
João Távora [Mon, 13 Aug 2018 00:45:40 +0000 (01:45 +0100)]
Handle edits to same position in the correct order
In eglot--apply-text-edits, the markers returned by
eglot--lsp-position-to-point are of the "stay" type, i.e. have an
insertion-type of nil. This causes multiple insertion edits to the
same location to happen in the reverse order in which they appear in
the LSP message, which is a violation of the spec and a bug.
There are more ways to solve this (see related discuttion in
https://github.com/joaotavora/eglot/pull/64), but the easiest way is
to revert the order in which the edits are processed. This is because
the spec tells us that the order is only relevant in precisely this
"same position" case. So if we reverse the order we fix this bug and
don't break anything else.
* eglot.el (eglot--apply-text-edits): Apply edits in reverse..
GitHub-reference: close https://github.com/joaotavora/eglot/issues/64
João Távora [Sat, 11 Aug 2018 13:52:33 +0000 (14:52 +0100)]
Implement asynchronous server connection
A new defcustom eglot-sync-connect controls this feature. If it is t,
eglot should behave like previously, waiting synchronously for a
connection to be established, with the exception that there is now a
non-nil timeout set to eglot-connect-timeout, which defaults to 30
seconds.
eglot-connect is now considerably more complicated as it replicates
most of the work that jsonrpc-request does vis-a-vis handling errors,
timeouts and user quits..
Kill server's output and events buffers from eglot-shutdown ()
* eglot.el
(Package-Requires): Require jsonrpc 1.0.5
(eglot-shutdown): Kill events and stderr buffers of the
server, unless new PRESERVE-BUFFERS argument is non-nil.
eglot-reconnect): Preserve buffers on shutdown.
* eglot-tests.el (eglot--call-with-dirs-and-files): Call
eglot-shutdown with non-nil PRESERVE-BUFFERS arg.
João Távora [Mon, 6 Aug 2018 16:53:09 +0000 (17:53 +0100)]
Accept functions as entries in eglot-server-programs
CONTACT in the (MAJOR-MODE . CONTACT) association in
eglot-server-programs can now be a function of no arguments producing
any value previously valid for contact. The function is called at
time of `M-x eglot` or `eglot-ensure`. This is useful for servers
requiring command-line invocations that depend on the specific
momentary environment.
* eglot.el (eglot-server-programs): CONTACT can be a fucntion of no
arguments.
(eglot--guess-contact, eglot--connect): Accept function
CONTACTs.
GitHub-reference: per https://github.com/joaotavora/eglot/issues/63
Fix placement of diagnostics with same start and end positions
Some servers such as cquery and clangd publish diagnostic with
identical start and end positions.
* eglot.el (eglot-handle-notification
:textDocument/publishDiagnostics): Add 1 to :line since LSP lines
are 0-based. Don't subtract 1 from :character, since both emacs and
LSP have 0-based columns.
* eglot.el (eglot-format): New command.
(eglot-format-buffer): Use it as implementation.
(eglot-client-capabilities): Add :rangeFormatting.
* eglot-tests.el (formatting): Also test range formatting.
* README.md (Commands and keybindings): Mention eglot-format.
(Language features): Tick textDocument/rangeFormatting.
João Távora [Sun, 22 Jul 2018 18:07:43 +0000 (19:07 +0100)]
Don't turn on flymake-mode any more than is needed
If flymake-mode is in eglot--managed-mode-hook, it will be called even
if eglot--managed-mode is being turned off, which could be problematic
because it triggers a check if flymake-start-on-flymake-mode is t.
* eglot.el (eglot--managed-mode): Turn on flymake-mode and
eldoc-mode here.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/44
João Távora [Fri, 20 Jul 2018 16:45:47 +0000 (17:45 +0100)]
Robustify in the face of manual mode changes
When manually changing the major-mode of a managed buffer, this sends
a didClose and tears down Eglot-related stuff like if were killing the
buffer. After changing the mode, we have to recheck that we are now
not managed by another server (or by the same server, in case we
changed the mode to be the same mode).
* eglot.el (eglot-shutdown): Use eglot--with-live-buffer
(eglot--on-shutdown): Use eglot--with-live-buffer
(eglot--managed-mode): Use change-major-mode-hook.
(eglot--managed-mode-onoff): Change protocol. Turn off when called
with no arguments.
(eglot--maybe-activate-editing-mode): Don't do anything if mode is
already active. Suitable for calling from
after-change-major-mode-hook.
(after-change-major-mode-hook): Add
eglot--maybe-activate-editing-mode.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/44
João Távora [Wed, 11 Jul 2018 23:30:32 +0000 (00:30 +0100)]
Implement workspace/didchangeconfiguration ()
* README.md (Supported Protocol Features, Commands and
keybindings): mention workspace/didChangeConfiguration.
* eglot.el (eglot-server-initialized-hook): New hook.
(eglot--connect): Run it.
(eglot-workspace-configuration): New variable.
(eglot-signal-didChangeConfiguration): New command.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/29
GitHub-reference: close https://github.com/joaotavora/eglot/issues/40
Fixes an issue with the latest RLS, where the server returns a plist
instead of a plain string as documentation for completion candidates,
which broke the `annotation-function`. This change was introduced by
https://github.com/rust-lang-nursery/rls/commit/206a9fb41e837333d0e67187a6a9fe24868b77a4
Copyright-paperwork-exempt: yes
* eglot.el (eglot-completion-at-point): Use eglot--format-markup
João Távora [Mon, 25 Jun 2018 16:37:43 +0000 (17:37 +0100)]
Cache buffer's managing server
* eglot.el (eglot--cached-current-server): New variable.
(eglot--managed-mode-onoff): Set it.
(eglot--current-server): Read it.
(eglot--maybe-activate-editing-mode): Add assertion.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/32
João Távora [Thu, 21 Jun 2018 22:32:14 +0000 (23:32 +0100)]
Empty ranges are valid in lsp
The previous hack in eglot--range-region, designed to appease cquery's
occasional practice of publishing diagnostics with empty regions, was
moved to the proper notification handler.
Reported by mkcms <k.michal@zoho.com>.
* eglot.el (eglot--range-region): Allow empty ranges, which are
allowed in LSP.
(eglot-handle-notification :textDocument/publishDiagnostics): Maybe
fallback to flymake-diag-region here.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/27
João Távora [Wed, 20 Jun 2018 18:05:25 +0000 (19:05 +0100)]
Guess server for js2-mode and rjsx-mode
* eglot.el (eglot-server-programs): Add entries for js2-mode and
rjsx-mode. Coalesce entries for c++ and c-mode. Improve
docstring.
(eglot--guess-contact): Allow lists are keys in
eglot-server-programs.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/26
João Távora [Wed, 20 Jun 2018 17:47:45 +0000 (18:47 +0100)]
Improve eglot-ensure and mention it in readme.md
* README.md (Installation and Usage): Mention eglot-ensure.
* eglot.el (eglot-ensure): No-op for non-file buffers.
(eglot--connect): Don't fallback to 'eglot-lsp-server here.
(eglot--guess-contact): Error if something can't be guessed.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/25
João Távora [Sun, 10 Jun 2018 12:41:10 +0000 (13:41 +0100)]
New eglot-ensure to put in a major-mode's hook
* eglot.el (Commentary): Mention eglo-ensure.
(eglot--connect): Rearrange args.
(eglot--guess-contact): Rename from eglot--interactive.
(eglot): Use eglot--guess-contact.
(eglot, eglot-reconnect): Rearrange call to eglot--connect.
(eglot-ensure): New command to put in mode hook.
* eglot-tests.el (eglot--tests-connect): New helper.
(auto-detect-running-server, auto-reconnect, rls-watches-files)
(rls-basic-diagnostics, rls-hover-after-edit, rls-rename)
(basic-completions, hover-after-completions): Use it.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/17
João Távora [Sun, 10 Jun 2018 06:16:41 +0000 (07:16 +0100)]
Simplify jsonrpc status setting
* eglot.el (eglot--connect): Don't set jsonrpc-status.
(eglot-clear-status): New interactive command.
(eglot--mode-line-format): Simplify.
* jsonrpc.el (jsonrpc--async-request-1): Simplify.
(jsonrpc-connection): Replace status with last-error.
(jsonrpc-clear-status): Delete.
(jsonrpc--connection-receive): Set last-error.
João Távora [Fri, 8 Jun 2018 15:05:02 +0000 (16:05 +0100)]
Support json.c. api purely based on classes
No more jsonrpc-connect.
This is a big commit because of a data loss problem. It should be at
least two separate commits (json.c-support and new API)
* eglot.el (eglot-server-programs): Rework docstring.
(eglot-handle-request): Don't take ID param
(eglot-lsp-server): No more initargs.
(eglot--interactive): Return 5 args.
(eglot): Take 5 args.
(eglot-reconnect): Pass 6 args to eglot--connect.
(eglot--dispatch): Remove.
(eglot--connect): Take 6 args. Rework.
(eglot-handle-notification): Change all specializations
to use a non-keyword symbol spec.
(eglot-handle-request): Remove ID param from all
specializations. Don't pass ID to jsonrpc-reply.
(eglot--register-unregister): Don't take JSONRPC-ID arg.
Don't pass ID to jsonrpc-reply.
* jsonrpc-tests.el (returns-3, signals-an--32603-JSONRPC-error)
(times-out, stretching-it-but-works)
(json-el-cant-serialize-this, jsonrpc-connection-ready-p)
(deferred-action-intime, deferred-action-toolate)
(deferred-action-timeout): Pass JSON objects compatible with
json.c
(jsonrpc--test-client, jsonrpc--test-endpoint): New classes
(jsonrpc--with-emacsrpc-fixture): Don't use jsonrpc-connect.
(jsonrpc-connection-ready-p): Update signature.
* jsonrpc.el: Rewrite commentary.
(jsonrpc-connection): Rework class.
(jsonrpc-process-connection): Rework class.
(initialize-instance): New methods..
(jsonrpc--json-read, jsonrpc--json-encode): Reindent.
(jsonrpc-connect): Delete.
(jsonrpc--json-read, jsonrpc--json-encode):
New functions for working with json.c
(jsonrpc--process-filter): Call them.
(jsonrpc--unanswered-request-id): New variable.
(jsonrpc--connection-receive): Use jsonrpc--unanswered-request-id
(jsonrpc-connection-send): Take keyword params to build message
instead of message.
(jsonrpc-notify, jsonrpc--async-request-1): Use new
jsonrpc-connection-send.
(jsonrpc-reply): Simplify.
* eglot-tests.el (rls-watches-files, rls-basic-diagnostics)
(rls-hover-after-edit): Correctly compare using string= and
non-keyword symbols.
João Távora [Wed, 6 Jun 2018 11:04:39 +0000 (12:04 +0100)]
Slightly polish the flymake integration
For backends, like RLS, that don't textDocument/publishDiagnostics
right away, assume that the file is clean. Since Flymake allows
multiple reportings, it should be OK.
* eglot.el (eglot--unreported-diagnostics): Move variable up here.
(eglot--maybe-activate-editing-mode): Assume no diagnostics on
open.