João Távora [Tue, 5 Jun 2018 16:26:38 +0000 (17:26 +0100)]
Cleanup the flymake 26.1 hack slightly
* eglot.el (eglot-handle-notification): Use proper flymake
diagnostic types.
(eglot-code-actions): Use eglot--diag-data.
(eglot--make-diag, eglot--diag-data): New aliases to
`flymake-diagnostic-data' and `flymake-make-diagnostic'.
(eglot-error eglot-warning eglot-note)
(dolist eglot-error eglot-warning eglot-note): put
flymake-overlay-control in these.
(eglot-error eglot-warning eglot-note): put corresponding
flymake-category.
(horrible hack at the end): Move the Flymake 26.1 hack here.
João Távora [Fri, 1 Jun 2018 15:59:00 +0000 (16:59 +0100)]
New command m-x eglot-code-actions
Also available when left-clicking diagnostics.
* README.md: Mention eglot-code-actions. Slightly rewrite
differences to lsp-mode.
* eglot.el (eglot-code-actions): New command.
(eglot-handle-notification :textDocument/publishDiagnostics): Use
eglot--make-diag and eglot--overlay-diag-props.
(eglot--mode-line-props): Use eglot--mouse-call.
(eglot--mouse-call): Renamed from eglot--mode-line-call.
(eglot-client-capabilities): List :executeCommand and :codeAction
as capabilities.
(eglot--diag, advice-add flymake--highlight-line): Horrible hack.
(eglot--overlay-diag-props): Horrible hack.
João Távora [Mon, 28 May 2018 22:07:56 +0000 (23:07 +0100)]
More yak shaving
* eglot.el (eglot--with-live-buffer, eglot--widening): New macros.
(eglot--lambda): Move up here.
(eglot--process-filter): Simplify with eglot--with-live-buffer.
(eglot--async-request): Simplify with eglot--with-live-buffer.
(eglot--TextDocumentItem): Simplify with eglot--widening.
(eglot--signal-textDocument/didChange, eglot--apply-text-edits):
Simplify with eglot--widening.
João Távora [Mon, 28 May 2018 21:30:01 +0000 (22:30 +0100)]
New m-x eglot-stderr-buffer useful for debugging
* eglot.el (eglot--make-process): Save stderr buffer in process.
(eglot-stderr-buffer): New interactive command.
(eglot--mode-line-format): Bind C-mouse-1 to new
eglot-stderr-buffer.
João Távora [Sun, 27 May 2018 14:34:50 +0000 (15:34 +0100)]
Make eglot--recent-changes a simpler list
* eglot.el (eglot-server-ready-p): Don't add default method here.
(eglot-server-ready-p): Do it here.
(eglot--outstanding-edits-p): Remove.
(eglot--before-change, eglot--after-change)
(eglot--signal-textDocument/didChange): Use eglot--recent-changes
as a list. Simplify.
(eglot--signal-textDocument/didOpen): Use eglot--recent-changes as
a list.
João Távora [Sun, 27 May 2018 11:58:49 +0000 (12:58 +0100)]
Hopefully fix the flymake bootstrap problem
Immediately after M-x eglot, eglot's use of flymake was having trouble
detecting the first diagnostics sent from the server, resulting in an
annoying "Wait" in the mode-line.
* eglot.el (eglot--current-flymake-report-fn): Move up here.
(eglot--managed-mode): Set eglot--current-flymake-report-fn to nil
on teardown.
(eglot--maybe-activate-editing-mode): Simplify.
(eglot-handle-notification textDocument/publishDiagnostics): Set unreported-diagnostics to a cons.
(eglot-handle-notification eglot-rls window/progress): Simplify.
João Távora [Sun, 27 May 2018 10:58:41 +0000 (11:58 +0100)]
Set spinner in textdocument/didchange as it matters to rls
Otherwise, the asynch eldoc action will immediately send the
textDocument/documentHighlight requests, without understanding that
they need to be deferred a bit more.
* eglot.el (eglot--signal-textDocument/didChange): Set the spinner
here.
João Távora [Sun, 27 May 2018 10:41:24 +0000 (11:41 +0100)]
Fix assorted cquery-related bugs
Some versions of cquery send a :role key as part of the response to
textDocument/documentHighlight. Ignore it for now.
Also cquery sometimes send 0-length ranges upon which we now fallback
to flymake-diag-region.
Finally, in eglot-eldoc-funciton, the previous hack of calling the
eglot--hover-info outside of the when-buffer-window macrolet contained
a bug. It must be called in the correct buffer. Revert the hack and do
it by querying from eglot.el if ert is running tests.
* eglot.el (eglot--range-region): Return a cons and fallback to
flymake-diag-region if server returned a useless range.
(eglot-handle-notification, eglot--hover-info): Update call to
eglot--range-region.
(eglot-help-at-point): Ensure `eglot--hover-info` runs in right
buffer.
(eglot-eldoc-function): Don't abuse eldoc-last-message like this.
Also update call to eglot--range-region. Consider ert-running-test
(eglot--apply-text-edits): Use pcase-lambda.
(ert): require it.
João Távora [Sat, 26 May 2018 18:10:45 +0000 (19:10 +0100)]
Merge branch 'cquery-support' into master
The conflicts in eglot.el where fixed by calling the new eglot--debug
helper coming from 'cquery-support'. This helper was converted to
allow a non-string format passed directly to eglot--log-event.
Also fixed some compilation warnings.
* eglot.el (eglot--debug): Allow non-string FORMAT to be a JSON
object. (eglot-handle-notification :$cquery/progress)
(eglot-handle-notification :$cquery/setInactiveRegions)
(eglot-handle-notification :$cquery/publishSemanticHighlighting):
Solve compilation warnings.
João Távora [Sat, 26 May 2018 17:52:17 +0000 (18:52 +0100)]
Really ensure eglot--shutdown deletes a process completely
* eglot.el (eglot-lsp-server): rename slot "moribund" to
"shutdown-requested"
(eglot--connect): Don't check if shutdown was requested here.
(eglot--process-sentinel): Set shutdown-requested to
:sentinel-done here.
(eglot-shutdown): use eglot--shutdown-requested. Improve check
for process liveness.
João Távora [Sat, 26 May 2018 15:11:11 +0000 (16:11 +0100)]
Don't rely on flymake's idle timer for textdocument/didchange
* eglot.el (eglot--after-change): Set idle timer here.
(eglot--change-idle-timer): New var.
(eglot--signal-textDocument/didChange): No seed to set spinner here.
(eglot-flymake-backend) Don't send didChange here.
Josh Elsasser [Fri, 25 May 2018 03:10:15 +0000 (20:10 -0700)]
Log debug messages through eglot--debug
* eglot.el (eglot--async-request, eglot--process-sentinel):
(eglot--call-deferred): Use eglot--debug to log messages to
the server events buffer.
(eglot--server-receive): Demote "Notification unimplemented"
message on missing handlers to a pure debug message.
Josh Elsasser [Tue, 22 May 2018 00:15:12 +0000 (17:15 -0700)]
Demote unvisited diagnostics logging to debug level
The PublishDiagnostic spec (LSP Specification, 3.0) does not
strictly forbid the server from publishing diagnostics before
a file has been visited.
* eglot.el (eglot--server-textDocument/publishDiagnostics): Log
the "received diagnostics for unvisited file" warning as debug
to avoid spamming users of compliant language servers.
Josh Elsasser [Mon, 21 May 2018 19:27:05 +0000 (12:27 -0700)]
Add cquery support for c/c++ projects
Implements minimal support for the core cquery language
server. None of its extensions are implemented yet.
* eglot.el (eglot-server-programs): Add cquery to list
of guessed programs for c-mode and c++-mode.
(eglot-initialization-options eglot-cquery): Specialize init
options to pass cquery a cache directory and disable a flood
of $cquery/progress messages.
(eglot-handle-notification $cquery/publishSemanticHighlighting):
(eglot-handle-notification $cquery/setInactiveRegions):
(eglot-handle-notification $cquery/progress): New no-op functions
to avoid filling logs with "unknown message" warnings.
(eglot-cquery): New eglot-lsp-server subclass.
João Távora [Tue, 22 May 2018 10:41:02 +0000 (11:41 +0100)]
Introduce new api methods for experimental clients to use
Should help Josh Elsasser implement pull request https://github.com/joaotavora/eglot/issues/6.
* eglot.el (eglot--obj): Move upwards in file.
(eglot-server-ready-p): Tweak comment.
(eglot-initialization-options): New API defgeneric..
(eglot-client-capabilities): New API defgeneric.
(eglot--client-capabilities): Remove.
(eglot--connect): Call new API methods here.
João Távora [Tue, 22 May 2018 01:00:49 +0000 (02:00 +0100)]
Use an eieio class to represent a server.
Allow clients of eglot.el to use specific server classes to represent
experimental servers.
Wherever you used to read "proc" you now probably read "server",
unless it's really the process properties that are sought after.
Should help Josh Elsasser implement pull request https://github.com/joaotavora/eglot/issues/6.
* eglot-tests.el (eglot--call-with-dirs-and-files)
(auto-detect-running-server, auto-reconnect, basic-completions)
(hover-after-completions): Adapt to server defclass instead of
proc.
João Távora [Sat, 19 May 2018 15:50:09 +0000 (16:50 +0100)]
Handle managed buffers in own process var
This should save some trouble when testing noninteractively. Because
eglot--shutdown didn't turn off the minor mode, test code running
immediately after it could still make didClose requests, for example.
The sentinel was the previous responsible for turning off the minor
mode and didn't get a chance to run in that case. Now eglot--shutdown
is also responsible for turning off the minor mode.
All this should be hidden behind eglot--managed-mode-onoff.
* eglot.el (eglot--managed-buffers): New process-local variable.
(eglot--process-sentinel): Turn off managed mode.
(eglot--managed-mode-onoff): New function.
(eglot--managed-mode): Don't offer to kill server here.
(eglot--buffer-managed-p): Remove.
(eglot--maybe-activate-editing-mode): Activate mode here.
(eglot-shutdown): Turn off minor mode here.
(eglot--server-window/progress): Simplify slightly.
João Távora [Sat, 19 May 2018 10:12:41 +0000 (11:12 +0100)]
Collect regions to change as markers, then edit
* eglot.el (eglot--lsp-position-to-point): Accept MARKER optional
arg.
(eglot--range-region): Accept MARKERS optional arg. Return a list.
(eglot--server-textDocument/publishDiagnostics)
(eglot--hover-info, eglot-eldoc-function): eglot--range-region
returns a list, not a cons.
(eglot--apply-text-edits): First collect regions as markers, then
edit.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/4
João Távora [Sat, 19 May 2018 09:06:12 +0000 (10:06 +0100)]
Robustify timer handling for eglot--async-request
This basically cherry-picks an ealier commit for the jsonrpc-refactor
branch: a2aa1ed..: João Távora 2018-05-18 Robustify timer handling for jrpc-async-request
* jrpc.el (jrpc--async-request): Improve timeout handling. Return a list (ID TIMER)
(jrpc--request): Protect against user-quits, cancelling timer
João Távora [Thu, 17 May 2018 13:03:20 +0000 (14:03 +0100)]
Make it work on windows
Apparently passing :coding 'no-conversion to make-process on windows
is essential to receive any text at all in the process filter.
Also needed to tweak uri-to-path and path-to-uri.
Thanks to lsp-mode.el for these hints
* eglot.el (eglot--make-process): Pass :coding 'no-conversion to
make-process.
(eglot--path-to-uri): Add a forward slash if windows-nt.
(eglot--uri-to-path): Remove a forward slash if windows-nt.
(eglot--server-textDocument/publishDiagnostics): Simplify and use
eglot--uri-to-path.
João Távora [Wed, 16 May 2018 23:30:53 +0000 (00:30 +0100)]
Simplify some function calling infrastructure
eglot--mapply is a confusing abstraction. Hide some of that confusion
behind eglot--lambda. More stably dispatch server notifications and
requests without introspecting their contents.
* eglot.el (eglot--process-receive): Simplify.
(eglot--async-request): Improve doc.
(eglot--request): Simplify.
(eglot--mapply): Remove.
(xref-backend-identifier-completion-table)
(xref-backend-definitions, xref-backend-references)
(xref-backend-apropos, eglot-completion-at-point)
(eglot-eldoc-function, eglot-imenu, eglot--apply-text-edits):
Don't use eglot--mapply, use normal mapcar/mapc.
João Távora [Wed, 16 May 2018 22:45:35 +0000 (23:45 +0100)]
Replace eglot--with-lsp-range with a function and pcase-let
* eglot.el (eglot--with-lsp-range): Remove.
(eglot--range-region): New function.
(eglot--server-textDocument/publishDiagnostics)
(eglot--hover-info, eglot-eldoc-function)
(eglot--apply-text-edits): Use it.
João Távora [Tue, 15 May 2018 12:24:08 +0000 (13:24 +0100)]
Add php's php-language-server to built-in guessed servers
Closes https://github.com/joaotavora/eglot/issues/1. The problem in that issue is that php-language-server has a
bug when it's not passed it the deprecated ":rootPath" field. The bug
doesn't happen if the ":processId" field is also absent. Eglot was
triggering the bug, because it didn't pass ":rootPath", but there's
nothing wrong in doing so.
* README.md: Add php-language-server to the built-in list.
* eglot.el (eglot-server-programs): Add php-language-server.
(eglot--connect): Also pass (deprecated) rootPath.
João Távora [Mon, 14 May 2018 13:18:18 +0000 (14:18 +0100)]
Support didchangewatchedfiles with dynamic registration
RLS uses this, presumaly for knowing about Cargo.toml changes and stuff.
* README.md: Update protocol compliance.
* eglot.el (filenotify): Require it.
(eglot--file-watches): New process-local var.
(eglot--process-sentinel): Kill all watches
(eglot--register-unregister): New helper.
(eglot--server-client/registerCapability): Simplify.
(eglot--server-client/unregisterCapability): New method.
(eglot--register-workspace/didChangeWatchedFiles)
(eglot--unregister-workspace/didChangeWatchedFiles): New
capability.
(eglot--client-capabilities): Update.
João Távora [Sun, 13 May 2018 22:25:15 +0000 (23:25 +0100)]
Use rls in travis ci and add actual tests
Also run a hook when connected
* eglot-tests.el (eglot--with-dirs-and-files)
(eglot--make-file-or-dirs, eglot--call-with-dirs-and-files)
(eglot--find-file-noselect): New helpers.
(auto-detect-running-server, auto-reconnect): New actual tests.
* eglot.el (eglot-connect): Run hook when connected
(eglot-connect-hook): New variable
Unfortunately, this may cause problems when calling the error
callbacks directly as in the process sentinel. In that particular
scenario the accept-process-output won't have return, because no
output has is being handled. Consequently, if we're unlucky, we have
another 30 seconds to way before the flag is tested and the loop
exits.
* eglot.el (eglot-request): Use catch/loop/throw again
João Távora [Sat, 12 May 2018 14:59:53 +0000 (15:59 +0100)]
New command eglot-help-at-point and a readme update
* README.md (Commands and keybindings): New section.
* eglot.el (eglot-eldoc-function): Use eglot--hover-info.
Don't care about kind in highlightSymbol
(eglot--hover-info): New helper.
(eglot-help-at-point): New command.
João Távora [Thu, 10 May 2018 18:23:56 +0000 (19:23 +0100)]
Improve eglot-eldoc-function
Use the :range key if the server provided it. Also simplify code with
a new eglot--with-lsp-range macro.
* eglot.el (eglot--format-markup): Tweak comment.
(eglot--with-lsp-range): New helper macro.
(eglot--server-textDocument/publishDiagnostics)
(eglot--apply-text-edits): Use it.
(eglot-eldoc-function): Use range if server provides it.
João Távora [Thu, 10 May 2018 17:44:47 +0000 (18:44 +0100)]
Reduce log chatter
* eglot.el (eglot--process-sentinel, eglot--request): Use
eglot--log-event.
(eglot--log-event): Print "message" if type unknown.
(eglot--debug, eglot--log): Remove.
(eglot--server-window/logMessage, eglot--server-telemetry/event):
Make noops.
(eglot--call-deferred): Also reduce chatter here.
João Távora [Thu, 10 May 2018 12:14:19 +0000 (13:14 +0100)]
Resist server failure during synchronous requests
Calling the error handler unprotected could lead to the rest of the
sentinel not running at all. This defeated the auto-reconnection in
Rust, for example.
João Távora [Thu, 10 May 2018 11:51:21 +0000 (12:51 +0100)]
More rls-specifics: update flymake diags when indexing done
RLS could/should report diagnostics for every opened file, even if
there aren't any problems. Because it doesn't, loop for every buffer
managed by the process and call eglot--current-flymake-report-fn
João Távora [Thu, 10 May 2018 11:21:29 +0000 (12:21 +0100)]
Adjust flymake integration
When opening a new file (signalling textDocument/didOpen) it makes
sense to call the flymake callback (if it exists) with no diagnostics,
just to get rid of that "Wait", since we don't know if later in this
callback cycle the server will ever report new diagnostics.
* eglot.el (eglot--managed-mode): Don't call flymake-mode or eldoc-mode
(eglot--managed-mode-hook): Add them here.
(eglot--maybe-activate-editing-mode): Call flymake callback.
(eglot--server-textDocument/publishDiagnostics): Set unreported
diagnostics to nil if invoking callback.
João Távora [Thu, 10 May 2018 11:07:11 +0000 (12:07 +0100)]
More correctly setup rust-mode-related autoloads
By autoloading the add-hook form and the eglot--setup-rls-idiosyncrasies
definition, a user can start rust-mode without loading eglot.el along
with it.
* eglot.el (rust-mode-hook)
(eglot--setup-rls-idiosyncrasies): Wrap in autoloaded progn.
João Távora [Wed, 9 May 2018 21:41:37 +0000 (22:41 +0100)]
New "deferred requests" that wait until server is ready
Calling textDocument/hover or textDocument/documentHighlight before
the server has had a chance to process a textDocument/didChange is
normally useless. The matter is worse for servers like RLS which only
become ready much later and send a special notif for it (see
https://github.com/rust-lang-nursery/rls/issues/725).
So, keeping the same coding style add a DEFERRED arg to eglot--request
that makes it maybe not run the function immediately. Add a bunch of
logic for probing readiness of servers.
* README.md: Update
* eglot.el (eglot--deferred-actions): New process-local var.
(eglot--process-filter): Call deferred actions.
(eglot--request): Rewrite.
(eglot--sync-request): Rewrite.
(eglot--call-deferred, eglot--ready-predicates)
(eglot--server-ready-p): New helpers.
(eglot--signal-textDocument/didChange): Set spinner and call
deferred actions.
(eglot-completion-at-point): Pass DEFERRED to eglot-sync-request.
(eglot-eldoc-function): Pass DEFERRED to eglot-request
(eglot--rls-probably-ready-for-p): New helper.
(rust-mode-hook): Add eglot--setup-rls-idiosyncrasies
(eglot--setup-rls-idiosyncrasies): New helper.
João Távora [Wed, 9 May 2018 11:24:10 +0000 (12:24 +0100)]
Get rid of eglot-mode
* eglot.el (eglot--managed-mode): Don't call eglot-mode. When
shutting down, offer to kill server.
(mode-line-misc-info): Update to use eglot--managed-mode
João Távora [Tue, 8 May 2018 15:07:07 +0000 (16:07 +0100)]
Support workspace/applyedit
* eglot.el (eglot--reply): Don't send result or error if not
provided.
(eglot--server-workspace/applyEdit): New server method.
(eglot--apply-text-edits): Rework.
(eglot--apply-workspace-edit): New helper.
(eglot-rename): Simplify.