microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.16k stars 28.84k forks source link

Feature request: prettify symbols mode #2402

Closed siegebell closed 6 years ago

siegebell commented 8 years ago

Feature request: Emacs has a cool feature called "prettify symbols mode," demonstrated for Haskell here. This could also subsume #192.

The basic idea is to register a sequence of characters whose glyphs will be replaced with another glyph, but the original characters still appear in the text document. Ideally, the substitutions would be dependent on the context returned by a syntax highlighter or some other parser.

egamma commented 8 years ago

@siegebell the January update will support for font ligatures, this might help for your scenario, please give it a try.

siegebell commented 8 years ago

@egamma: font ligatures won't really help me.

Use case: The Coq Proof Assistant allows one to write proofs about mathematics (category theory, real numbers, etc.), program behavior, program logics, type systems, etc. I am writing an extension to work with Coq proofs in vscode. It would be useful for the user to be able to define a set of symbol substitutions particular to the domain that they are writing proofs about. For example, set notation is useful for visualizing proofs about set theory.

192 demonstrates that symbols are also useful for general programming.

Limitations of ligatures for symbol substitutions:

Solution:

egamma commented 8 years ago

@siegebell no doubt prettify symbols is more powerful than ligatures. Thanks for the clarifications.

siegebell commented 8 years ago

@egamma @aeschli - I've managed to implement a rudimentary prettify symbols mode using #7181 (before & after decorations) -- thanks!

But there are a couple bugs in #7181 and limitations elsewhere that need to be addressed, so I'll be filing a few more related issues soon.

siegebell commented 8 years ago

Most of the features can be implemented as an extension, but here are a couple reasons it might be better to implement this in vscode itself:

  1. It uses code injection (#6201) to hide the replaced text, which is not officially supported and has some bugs.
  2. Cursor movement still steps through each character of the hidden text. I have not found an ideal hook for overriding cursor movement: I can hook the 'cursorLeft' command, but there seems to be no way to restore the original behavior, or I can set up keybindings that hook cursor movement keys. Neither of these options play well with potential extensions that change cursor movement behavior or a user's custom keybindings that choose alternatives to e.g. the left key (e.g. the vim extensions).
  3. I've tried both display: none and font-size: 0pt to hide text, and both cause the cursor to disappear when at the left or right edges of the range where such a decoration is applied.

But my preference would be to have a supported way to hide text (e.g. through decorations) that handles cursor movement and cursor visibility properly, and then leave the rest to an extension.

alexdima commented 8 years ago

:+1: on implementing this in the core. Sounds like something the ViewModel should do -- it has the ability to transform view <-> model positions and randomly insert/remove text, etc.

Note: it is not trivial

siegebell commented 8 years ago

@alexandrudima @aeschli this could also be resolved by #3422 if it gives extensions a flexible API to control code folding.

The API would need to allow specifying:

siegebell commented 8 years ago

@alexandrudima If I were to attempt a PR to support hiding text, do you think adding it as a decoration property would be a good idea?

E.g. add foldContent: boolean to ThemableDecorationRenderOptions? Unlike display: none, the behavior would not hide the attachments.

voronoipotato commented 7 years ago

This feature could in theory satisfy both Allow Unicode Operators and Remove Fun Keyword. Really hoping this feature gets implemented at some point.

siegebell commented 7 years ago

@voronoipotato check it out: https://marketplace.visualstudio.com/items?itemName=siegebell.prettify-symbols-mode.

Miguel-Fontes commented 7 years ago

+1

alexdima commented 6 years ago

To keep the number of issues in our inbox at a manageable level, we're closing issues that have been on the backlog for a long time but haven't gained traction: we look at the number of votes the issue has received and the number of duplicate issues filed. Thank you for your time and understanding.

P.S. If you disagree and feel that this issue is crucial: we're happy to listen and to reconsider.