zig icon indicating copy to clipboard operation
zig copied to clipboard

autodoc: make imports into links

Open tjog opened this issue 1 year ago • 3 comments

This PR contains three changes:

Keybindings on non US keyboards

The keybindings previously switched on the code (MDN) rather than the key (MDN). Many keyboards are QWERTY based, but I noticed this when pressing ?. Either UI should change or this key handling should be used instead.

Tarballs with backslashes

Tarball unpacking replaces backslashes with forward slashes. Discovered this during local development on Windows where the found files logged std/Thread\Pool.zig. Perhaps a change to the std.tar implementation to reject setPath with backslashes is in order. I am not aware if it should be forbidden by the tar implementation, or the caller to understand backslashes will not register as separate directories. Either way, this unpacking change will handle more tarballs, regardless of source.

Make imports into links

Before: image

After (while hovering the second import statement): image

Currently, the import token is the one with link and highlighting (when hovered). The alternative is the import string being linkified. I could try to make that change, but this was the most straightforward version. Field access can also terminate in an import statement now, leading to more identifiers being linked, e.g. the @import("array_list").XyzVersion pattern.

This ticks one of the TODOs in #19249

tjog avatar May 19 '24 21:05 tjog

Found #19276 which changed to code rather than key to support non-latin keyboards. Read a bit more and the extensive solution seems to be doing something like

https://www.kravchyk.com/keyboard-shortcuts-on-non-latin-alphabet-layouts/

which basically uses key by default, but if a non-latin character is detected it falls back to code and uses some custom logic to extract a latin character from that code. (source code)

Let me know if the commit should be dropped.

tjog avatar May 19 '24 22:05 tjog

Currently, the import token is the one with link and highlighting (when hovered). The alternative is the import string being linkified.

Can you try linkifying both the builtin token and the string argument?

Or just linkify the string to match how ZLS does it.

Vexu avatar May 20 '24 11:05 Vexu

Or just linkify the string to match how ZLS does it.

Done, link (and hover) only applied to the import string now: image

Was easier this time around now that I understood where data is located in the DOD Tokenizer and Ast structures.

tjog avatar May 20 '24 11:05 tjog

The keybindings previously switched on the code (MDN) rather than the key (MDN). Many keyboards are QWERTY based, but I noticed this when pressing ?. Either UI should change or this key handling should be used instead.

I use the Colemak Mod-DH keyboard layout remapped by systemd. #19276 halfway broke the keyboard shortcuts for me, since my remapped s key is physically the d key. I have to press my r key, which is physically my s key to search, for example. I suspect this is the case for other non-querty layout users out there who've also remapped their layouts in software (systemd, gnome, MS KLC, etc).

weskoerber avatar Oct 01 '24 18:10 weskoerber