Zulip Chat Archive

Stream: general

Topic: VSCode highlighting


Patrick Massot (Jan 18 2021 at 20:30):

How hard would it be to have a VSCode extension setting defining a list of extra words that should be highlighted (say in tactic mode if this makes sense)?

Bryan Gin-ge Chen (Jan 18 2021 at 20:46):

VS Code expects grammars to be provided as a file, so I don't see an easy way to modify the grammar dynamically: https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#contributing-a-basic-grammar

See also https://github.com/microsoft/vscode/issues/53885

VS Code does support semantic highlighting but this looks to me like a big project.

I'm sure Gabriel wouldn't mind a PR which just added some extra keywords to this file: https://github.com/leanprover/vscode-lean/blob/master/syntaxes/lean.json

The grammar doesn't currently have any way of detecting what's in tactic mode or not at the moment though.

Patrick Massot (Jan 18 2021 at 20:49):

Too bad. Thanks for answering. I'm pretty sure Gabriel wouldn't like my list.

Gabriel Ebner (Jan 19 2021 at 08:45):

Let me clarify the criteria for inclusion in the vscode syntax highlighting: I will add it if and only if it is used in mathlib.

Patrick Massot (Jan 19 2021 at 08:46):

Let me clarify that my list is absolutely not for general consumption :wink:

Patrick Massot (Jan 19 2021 at 08:46):

It's part of my controlled natural language experiment.

Gabriel Ebner (Jan 19 2021 at 08:46):

So it's also French as well? Yes, the chances are not good.

Gabriel Ebner (Jan 19 2021 at 08:49):

It might be possible to use the same trick that we use for Lean 4 here. Have two syntax highlighting files, and the extension sets a property on the file that changes the highlighting. This could even be in two different extension. But this takes work and time.

Patrick Massot (Jan 19 2021 at 08:49):

Yes, it is. If you feel brave, open the next block

Patrick Massot (Jan 19 2021 at 08:50):

I need to prepare Lean+mathlib+VScode+extension bundles for my course anyway. I may simply hack the grammar there.

Eric Wieser (Jan 19 2021 at 08:51):

@Patrick Massot, if these are keywords for your natural language tactics, would you consider begin[natural] end? If so, I think the lean grammar could do something like "if you see this funny tactic block, delegate to another syntax highlighter"

Eric Wieser (Jan 19 2021 at 08:53):

Which at least would mean there are only a few lines of weirdness in lean-vscode instead of an unexpected pile of French words!

Sebastien Gouezel (Jan 19 2021 at 08:57):

Je suis curieux de voir ce que ça va donner. Tu pourras poster un exemple de tes fichiers quand tu seras content de ce à quoi ça ressemble ?

(Sorry for the French, but it feels in line with the discussion :-)

Patrick Massot (Jan 19 2021 at 08:57):

Again, I never suggested to add any word to the official VScode extension. I was asking about a new variable in settings that any user (or Lean project) could set.

Eric Wieser (Jan 19 2021 at 09:00):

It looks like you might be looking for an "injection grammar"

Eric Wieser (Jan 19 2021 at 09:00):

https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#injection-grammars

Eric Wieser (Jan 19 2021 at 09:02):

Which at least would mean you don't have to fork lean-vscode, you can just distribute a custom extension alongside it

Patrick Massot (Jan 19 2021 at 09:07):

Thanks for the pointer Eric!

Patrick Massot (Jan 19 2021 at 09:07):

Small sample for @Sebastien Gouezel

import m154
import .tactiques

-- Définition de « limite de f en x₀ = y₀ »
-- Lean n'a pas besoin de parenthèse dans f(x)
def continue_en (f :   ) (x₀ : ) : Prop :=
 ε > 0,  δ > 0,  x, |x - x₀|  δ  |f x - f x₀|  ε

-- Une suite u est une fonction de ℕ dans ℝ
-- Définition de « u tend vers l »
def limite_suite (u :   ) (l : ) : Prop :=
 ε > 0,  N,  n  N, |u n - l|  ε

-- Si f est continue en x₀ et la suite u tend vers x₀ alors la suite f ∘ u,
-- qui envoie n sur f (u n), tend vers f x₀
example (f u x₀) (hu : limite_suite u x₀) (hf : continue_en f x₀) :
  limite_suite (f  u) (f x₀) :=
begin
  Montrons que  ε > 0,  (N : ),  n  N, |(f  u) n - f x₀|  ε,
  Soit (ε > 0),
  Par hf appliqué à [ε, ε_pos] on obtient δ tel que
    (δ_pos : δ > 0) (Hf :  (x : ), |x - x₀|  δ  |f x - f x₀|  ε),
  Par hu appliqué à [δ, δ_pos] on obtient N tel que
    (Hu :  (N : ),  (n : ), n  N  |u n - x₀|  δ),
  Montrons que N convient,
  Soit (n  N),
  Par Hf il suffit de montrer que |u n - x₀|  δ,
  On conclut par Hu appliqué à [n, n_ge],
end

def croissante (f :   ) :=  x₁ x₂, x₁  x₂  f x₁  f x₂

example (f g :   ) (hf : croissante f) (hg : croissante g) : croissante (g  f) :=
begin
  Soit x₁ x₂,
  Supposons h : x₁  x₂,
  Montrons que g (f x₁)  g (f x₂),
  Par hf appliqué à [x₁, x₂, h] on obtient (hf' : f x₁  f x₂),
  On conclut par hg appliqué à [f x₁, f x₂, hf'],
end

Patrick Massot (Jan 19 2021 at 09:09):

Let me emphasize again that the main goal is not to make Lean easier to write (students actually manage to write Lean code), but to make it easier to go from Lean to paper.

Johan Commelin (Jan 19 2021 at 09:10):

I would love to have an english version of this!

Patrick Massot (Jan 19 2021 at 09:11):

To be honest, I'm surprised by how well it works. I'm almost thinking we should maybe think a bit about seriously using something like this even in mathlib.

Johan Commelin (Jan 19 2021 at 09:14):

we only need to also have versions with lowercases letter, and replace . by something else, so that we can end sentences with . instead of ,.

Johan Commelin (Jan 19 2021 at 09:14):

and and should be a noop.

Sebastien Gouezel (Jan 19 2021 at 09:15):

It definitely helps here that French is disjoint from Lean keywords.

Eric Wieser (Jan 19 2021 at 09:17):

Do begin[foo] end blocks get custom parsers (eg, can choose something other than commas), or just a custom monad type?

Kevin Buzzard (Jan 19 2021 at 09:23):

This is awesome! Those proofs are really cool!

Patrick Massot (Jan 19 2021 at 09:32):

Note that those tactics are not only aliases for the standard tactics with crazy parsers, they also work more to prove stuff we would never write on paper. For instance On conclut par H looks like an alias to exact but it also tries apply H and linarith only [H].

Patrick Massot (Jan 19 2021 at 09:33):

They also do some cleanup compared to their vanilla versions, for instance beta-reductions.

Patrick Massot (Jan 19 2021 at 09:34):

And they work to hide intuistionistic madness.

Patrick Massot (Jan 19 2021 at 09:34):

Blurring the distinction between or.elim and excluded middle, or between cases and choose.

Patrick Massot (Jan 19 2021 at 09:49):

Also, Montrons que is not only change. If the goal is a disjunction, it will try left, change ..., and right, change ....

Kevin Buzzard (Jan 19 2021 at 10:44):

Patrick this is really fabulous. I would imagine that people like Hales and Koepke would be very interested in what you are doing. Thanks for sharing!

Alex Peattie (Jan 19 2021 at 14:47):

I agree that this is very cool :smile: !

Patrick Massot said:

How hard would it be to have a VSCode extension setting defining a list of extra words that should be highlighted (say in tactic mode if this makes sense)?

I think if you just wanted a set of words to have different styling throughout the document, you could do this with decorations in VSCode. This is how the highlight-words extension works for example. The disadvantage of not using the grammar is that it'd be harder to, say, not do the highlighting within comments.

Yaël Dillies (Sep 02 2021 at 16:06):

Very meta. image.png

Marc Masdeu (Sep 03 2021 at 13:59):

Johan Commelin said:

I would love to have an english version of this!

I looked hard for typical food staples of english cuisine, but unfortunately none of them have made it into Zulip yet.


Last updated: Dec 20 2023 at 11:08 UTC