Eglot's eglot-imenu returned a structure compliant with the rules
outlined in imenu--index-alist. In particular, it returned some
elements of the form
(INDEX-NAME POSITION GOTO-FN ARGUMENTS...)
The original intention (mine) must have been to allow fancy
highlighting of the position navigated to with a custom GOTO-FN.
Not only was access to that fanciness never implemented, but many
other imenu frontends do not support such elements.
See for example https://github.com/joaotavora/eglot/issues/758, https://github.com/joaotavora/eglot/issues/536, https://github.com/joaotavora/eglot/issues/535. And also related issues in other
packages:
João Távora [Fri, 15 Jul 2022 11:58:47 +0000 (12:58 +0100)]
Be more conservative with the lsp identifier guess
If the user is not requesting a prompt, opt for the safer approach
which is to get the location from textDocument/definition, not from
workspace/symbol. Because of things like function overloading, the
latter is not always successful in finding exactly the definition of
the thing one is invoking M-. on.
This requires using an xref-internal symbol, which is kind of
unfortunate.
João Távora [Fri, 15 Jul 2022 09:25:55 +0000 (10:25 +0100)]
Tweak some details, fix some bugs
eglot--recover-workspace-symbol-meta had a bug that still made it
choke on improper lists.
Also, when simply M-. to the thing at point, let's not lose time on
iterating a potentially out-of-date eglot--workspace-symbols-cache.
So clear it early in the pre-command-hook.
João Távora [Thu, 14 Jul 2022 09:09:27 +0000 (10:09 +0100)]
Cosmetic decisions guaranteed to tick off someone somewhere (tm)
The symbols returned by the LSP server must be converted to unique
strings if Emacs is to present them in a list. On the other hand, the
search operates on the pattern and is completely controlled by the
backend. There is not much Eglot, the LSP client, can do about this.
Decided to present the unique string to the user, even though it could
be hidden. All the manner of :annotation-function,
:affixation-function, :group-funcion etc didn't seem to add much
value.
Grouping was especially useless, since it makes sense to respect the
LSP server's account of sorting score, so that better results bubble
up to the top.
* eglot.el (xref-backend-identifier-completion-table): Uniquify
symbols with containerName and kind.
GitHub-reference: per https://github.com/joaotavora/eglot/issues/131
João Távora [Tue, 12 Jul 2022 23:44:32 +0000 (00:44 +0100)]
Make c-u m-. work half decently
* NEWS.md: Mention change.
* eglot.el (eglot--lsp-interface-alist): Add WorkspaceSymbol
(eglot--workspace-symbols-cache): New variable.
(eglot--recover-workspace-meta): New helper.
(xref-backend-identifier-completion-table): Complicate.
(xref-backend-definitions): Complicate.
(completion-category-overrides): Register a category and a style here.
(completion-styles-alist): Add eglot--lsp-backend-style style
(eglot--lsp-backend-style-call): New funtion.
(eglot--lsp-backend-style-all-completions): New function.
(eglot--lsp-backend-style-try-completion): New function.
João Távora [Thu, 7 Jul 2022 11:30:03 +0000 (12:30 +0100)]
Prevent desktop.el from saving/restoring eglot--managed-mode
Although desktop.el compatibility is Emacs bughttps://github.com/joaotavora/eglot/issues/56407, the optimal
solution agreed to there is a bit more work than what I have time to
right now. See e.g.
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=bug%2356407https://github.com/joaotavora/eglot/issues/68. For
now, just use `with-eval-after-load'
* eglot.el (Hacks desktop): Add eglot--managed-mode to
desktop-minor-mode-handlers
João Távora [Thu, 19 May 2022 08:59:55 +0000 (09:59 +0100)]
Don't ignore flymake-no-changes-timeout
Also per https://github.com/joaotavora/eglot/issues/957.
Only actually and eagerly report LSP diagnotics if the user has
Flymake starting automatically on a timer (flymake-no-changes-timeout
is a number).
By contrast, if flymake-no-changes-timeout is nil, the user starts the
diagnostic collection process on-demand via 'M-x flymake-start'.
Since the control of such collection is impossible with LSP, we should
just hold on to whatever diagnostics we have (which are presumably
up-to-date) until the next invocation of 'eglot-flymake-backend'.
For now, this doesn't affect Flymake "list-only" diagnostics. Those
are reported via the 'flymake-list-only-diagonstics' variable and
are always communicated immediately to it.
* eglot.el (eglot-handle-notification): Because diagnostics code can
be integer or string, and integer fails the sequencep test, use format
to create this string.
João Távora [Mon, 9 May 2022 00:17:58 +0000 (01:17 +0100)]
Fix egregious thinko in eglot--uri-to-path
One shouldn't unhex the URI before parsing it. Just consider a
filename with a # character in it. The character is encoded as C%23,
after unhexing the file name becomes.
/tmp/C#/Program.cs
Now, parsing this as the URL will fail completely as the # mean
"anchor" in URLs.
João Távora [Wed, 4 May 2022 20:47:21 +0000 (21:47 +0100)]
Consider diagnostic.code when generating flymake diagnostics
Not sure this will please everybody, can almost guess someone is going
to ask for a custom switch.
Instead this info (and the source) should be passed on to Flymake.
That's where the custom switch for controlling formatting of
diagnostic messages should exist. But that's too much work right now.
rbrtb [Tue, 3 May 2022 09:53:17 +0000 (09:53 +0000)]
Ensure exit-function of eglot-c-at-point runs on exact match
When the completion is exact match, exit-function should still run.
Say one is using auto-imports feature of pyright. One types foo, and
triggers the completion. There are two candidates: foo and foo_bar. If
one chooses foo, the status would be 'exact' instead of 'finished', thus
exit-function is not executed, foo is not auto-imported.
A diagnostics-lazy server is one who doesn't re-report already
reported diagnostics when it received textDocument/didSave.
Such is the case of Clangd, for example. Before this change, saving
an Eglot/Clang-managed buffer with some diagnostics caused the Flymake
indicator to display Wait[0 0] until some change was actually done to
the buffer.
That is because Flymake, by default, wants diagnostics on buffer save,
per flymake-start-on-save-buffer. But it doesn't work to simply turn
that off. That's because if one types something and quickly saves,
and the LSP diagnostics do come in after the save (for some reason,
like server latency), then Flymake sometimes doesn't request any
diagnostics at all.
The reason for the Flymake behaviour wasn't investigated, but that
wasn't a very good solution either
Rather this change makes it so that when such a Flymake request comes
in, it always gets served immediately with the latest information.
The latest information is now always stored in eglot--diagnostics,
with eglot--unreported-diagnotics being removed. The up-to-date list
is reported to Flymake whenever it requests it. It is updated
whenever the LSP server decides to.
* eglot.el (eglot--last-reported-diagnostics): Delete.
(eglot--unreported-diagnostics): Delete.
(eglot--diagnostics): New variable..
(eglot--maybe-activate-editing-mode): Use eglot--diagnostics.
(eglot-handle-notification): Set eglot--diaggnostics.
(eglot-flymake-backend): Read eglot--diagnostics. Always report.
(eglot--report-to-flymake): Set eglot--diagnostics.
Felicián Németh [Sat, 15 Jan 2022 17:51:36 +0000 (18:51 +0100)]
Rework eglot's mode-line
Mimic flymake by replacing the old menus of the mode-line with
"context menus". List all usefull commands under the main menu
(eglot-menu-map), and commands related to LSP debugging under the
project menu (eglot-debug-map).
* eglot.el (eglot-read-documentation, eglot-customize): New
commands.
(eglot-mode-line-string): New defcustom.
(eglot-menu-map, eglot-debug-map,): New variables.
(eglot--mode-line-props): Rework to use eglot-menu-map and
eglot-debug-map.
(eglot--mode-line-format): Use eglot-mode-line-string.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/792
João Távora [Mon, 4 Apr 2022 08:39:59 +0000 (09:39 +0100)]
Make eglot--plist-keys a simple (non-map.el) helper again
This removes a nagging compilation warning when developing on Emacs
master.
There's not much point in depending on map.el just for this util. And
there' snot much point in making eglot--plist-keys go through a
generic dispatching mechanism when we happen to know the thing
being dispatched
* eglot.el (eglot--plist-keys): Define in helpers section.
João Távora [Mon, 28 Mar 2022 10:00:44 +0000 (11:00 +0100)]
Easier initializationoptions in eglot-server-programs
Per https://github.com/joaotavora/eglot/issues/845.
* NEWS.md: Update.
* eglot.el (eglot-server-programs): Document new syntax.
(eglot-initialization-options): Can use initializationOptions from
server's saved initargs.
(eglot--connect): Allow a plist to be appended to a server
contact.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/901
Felicián Németh [Wed, 23 Mar 2022 20:47:45 +0000 (21:47 +0100)]
Implement on-type-formatting support
* eglot.el (eglot-format): Add new optional argument `on-type-format'
to request :textDocument/onTypeFormatting, and ...
(eglot--post-self-insert-hook): ... call it from here when necessary.
* eglot-tests.el (eglot--simulate-key-event): New helper defun.
(rust-on-type-formatting): New test.
* NEWS.md: mention feature.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/899
Felicián Németh [Sun, 20 Mar 2022 08:50:15 +0000 (09:50 +0100)]
Add simple support for workspacefolders
Close https://github.com/joaotavora/eglot/issues/893.
Clients can support workspaceFolders since LSP 3.6. rootUri and
rootPath are deprecated. Dynamic changes in folders are not
supported, i.e., this patch does not implement
workspace/didChangeWorkspaceFolders.
* eglot.el (eglot-client-capabilities): Add capability
`workspaceFolders'.
(eglot-workspace-folders): New cl-defgeneric.
(eglot--connect): Add workspaceFolders to initializeParams.
(eglot-handle-request workspace/workspaceFolders): New cl-defmethod.
1 // args_out_of_range.c
2 struct Book {
3 int id;
4 char title[50]
5 } book = { 1024, "C" };
6
7 int main(int argc, char *argv[])
8 {
9
10 // Error when typing the dot to make "book."
11 book
12 return 0;
13 }
When one types the dot after the "book" on line 11, company-mode
displays a two-line overlay that visually encompasses line 12 after
"book", which has the "return 0;" statement. That line happens to
also hold a warning about incorrect syntax, one that starts at column
2.
Eglot uses 'move-to-column' to go that precise place.
In Emacs 27.2, move-to-column is unaffected by previous company-mode
overlays, even if the current line is being co-used visually by the
overlay. It moves to the right buffer position.
In Emacs master, this isn't true. It seems to be confounded by the
company-mode overlay and moves to eob, which eventually breaks Eglot
with a backtrace such as this one:
Augusto Stoffel [Thu, 10 Mar 2022 11:32:20 +0000 (12:32 +0100)]
Don't strip invisible text when formatting hover string
This was introduced in https://github.com/joaotavora/eglot/issues/482 due to a bad interaction with a specific
server. But this solution makes hyperlinks in Eldoc buffers
unclickable, because the markdown-mode function that visits a link
relies on the invisible text.
Per https://github.com/joaotavora/eglot/issues/866
* eglot.el (eglot--format-markup): Use buffer-string instead of
filter-buffer-substring
Brian Leung [Tue, 1 Mar 2022 15:59:05 +0000 (07:59 -0800)]
Prevent empty diagnostic tags vector hiding main fontification
* eglot.el (eglot-handle-notification): Require that the resulting
list of faces is non-empty and that each face corresponds only to a
known tag.
For unknown tags, we don't pass any additional face information to
Flymake, and instead expect it to make the appropriate overlay with
the "severity" property of the Diagnostic.
Co-authored-by: João Távora <joaotavora@gmail.com>
GitHub-reference: fix https://github.com/joaotavora/eglot/issues/851
Brian Leung [Sun, 23 Jan 2022 03:59:06 +0000 (19:59 -0800)]
Properly check the completionitem.deprecated property
* eglot.el (eglot-completion-at-point): Check the :deprecated property
is `t'. We do this so that a :deprecated property of :json-false does
not cause a completion candidate to be incorrectly marked as deprecated.
Brian Leung [Thu, 13 Jan 2022 03:06:18 +0000 (19:06 -0800)]
Add support for optional completionitem.tags
* eglot.el (eglot--lsp-interface-alist): Add optional CompletionItem.tags.
(eglot-completion-at-point): Add :company-deprecated key and value,
checking for either the appropriate tag (1) in the :tags property, or
a truthy value for the :deprecated property.
(eglot-client-capabilities): Advertise tagSupport (for tag == 1) and
deprecatedSupport.
Also load an updated version of seq.el in Emacsen < 27.
Stefan Kangas [Sat, 22 Jan 2022 03:13:11 +0000 (04:13 +0100)]
Don't use :exclusive no
See https://github.com/joaotavora/eglot/issues/812 for background, in particular:
https://github.com/joaotavora/eglot/issues/812#issuecomment-1014821345
* eglot.el (eglot-completion-at-point): Don't use :exclusive no, as it
leads to breakage in many cases.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/812
* eglot.el (eglot-handle-notification): Pass on diagnostics from
unvisited files to flymake. Enables project-wide-diagnostics, so that
we can view all diagnostics in a given workspace. Uses new
functionality from flymake 1.2.1, hence the version bump.
* eglot-tests.el (project-wide-diagnostics-typescript): New tests
showcasing the possibility to see all related diagnostics in a
workspace.
* eglot-tests.el (project-wide-diagnostics-rust-analyzer): New tests
showcasing the possibility to see all related diagnostics in a
workspace.
* NEWS.md: Mention the new functionality
* README.md: Mention the new functionality
Stefan Kangas [Fri, 14 Jan 2022 12:03:44 +0000 (13:03 +0100)]
Change rust language server to rust-analyzer
rust-analyzer is the officially blessed Language Server for Rust:
https://github.com/rust-lang/rfcs/pull/2912
Also drop the special support code for RLS.
* eglot.el (eglot-server-programs): Add rust-mode language server
"rust-analyzer" and prefer it to the older "rls".
(eglot-rls, jsonrpc-connection-ready-p)
(eglot-handle-notification): Delete special support for "rls".
* eglot-tests.el (rls-analyzer-watches-files)
(rls-analyzer-hover-after-edit): Rename to ...
(rust-analyzer-watches-files)
(rust-analyzer-hover-after-edit): ... this. Update tests to work
with rust-analyzer.
* README.md: Update references for RLS to point to rust-analyzer.
* NEWS.md: Announce above change.
GitHub-reference: per https://github.com/joaotavora/eglot/issues/803
* eglot.el (eglot-rename): Change from symbol-at-point to
thing-at-point to avoid interning a symbol. Add "unknown symbol" to
prompt when no symbol is found.
Co-authored-by: João Távora <joaotavora@gmail.com>
GitHub-reference: close https://github.com/joaotavora/eglot/issues/385
A DiagnosticTag can be either 1 (DiagnosticTag.Unnecessary) or
2 (DiagnosticTag.Deprecated). Following the rendering suggestions in
the protocol, we fade out Unnecessary code and strike-through
Deprecated code.
* eglot.el (eglot-diagnostic-tag-unnecessary-face)
(eglot-diagnostic-tag-deprecated-face): New faces.
(eglot--tag-faces): New defconst.
(eglot--lsp-interface-alist): Add Diagnostic.tags.
(eglot-client-capabilities): Advertise supported tags.
(eglot-handle-notification): Assign the appropriate properties.
* eglot-tests.el (diagnostic-tags-unnecessary-code): New test.
GitHub-reference: per https://github.com/joaotavora/eglot/issues/794
Brian Leung [Tue, 11 Jan 2022 03:32:19 +0000 (19:32 -0800)]
Don't error out on unsupported diagnostic.codedescription
A codeDescription property is, at the time of writing, an object with
an href property (of type URI, or a string), denoting a "URI to open
with more information about the diagnostic error".
It's not obvious how best to put this into a Flymake diagostic
aside from simply appending it to the diagnostic message, so we'll
worry about it some other time.
* eglot.el (eglot--lsp-interface-alist)
(eglot-client-capabilities): Don't error out on unsupported
Diagnostic.codeDescription.
Brian Leung [Sun, 9 Jan 2022 02:08:23 +0000 (18:08 -0800)]
Properly print error message of eglot-alternatives
* eglot.el (eglot-alternatives): Work with the listified form. This
allows presumed executables provided as (EXECUTABLE &rest ARGS...)
to be displayed in the error.
GitHub-reference: per https://github.com/joaotavora/eglot/issues/786
The {html,css,json}-languageserver executables that are distributed
outside VS Code are not regularly updated by Microsoft; any relevant
updates to the VS Code source tree reach VS Code users without the
need for VS Code developers to go out of their way to publish new
versions of the executables. Consequently, users of other editors who
have been using the server executables from the most obvious NPM
packages are likely using stale versions.
@hrsh7th, a Vim user, created an NPM package with updated versions of these
executables taken straight from VS Code's source tree. We therefore
prefer to direct users to the corresponding repo, which contains
appropriate installation instructions, in the README.
Garret Buell [Wed, 15 Dec 2021 21:17:26 +0000 (13:17 -0800)]
Mark eglot-completion-at-point capf "non-exclusive"
Add :exclusive 'no to eglot-completion-at-point results marking it as
non-exclusive. This will allow completion to fall back to other less precise
completion backends (e.g. dabbrev) if Eglot's returns no results.
* eglot.el (eglot-completion-at-point): Set :exclusive to 'no
Copyright-paperwork-exempt: Yes
GitHub-reference: close https://github.com/joaotavora/eglot/issues/770
Stephen Leake [Tue, 16 Nov 2021 08:23:39 +0000 (00:23 -0800)]
Merge pull request from stephe-ada-guru/master
Fix issues https://github.com/joaotavora/eglot/issues/755, https://github.com/joaotavora/eglot/issues/401; severity not set in textDocument/publishDiagnostics