Zulip Chat Archive

Stream: lean4

Topic: Custom suggestions


Kenny Lau (Sep 17 2025 at 10:20):

Following #mathlib4 > bool syntax @ 💬 , is it possible to tweak the VSCode suggestions?

import Lean

syntax "#asdf " (&"true" <|> &"false") : command

-- truman falsify

#asdf t
#asdf f

In this declared syntax, only true or false are allowed, but the VSCode suggestion doesn't know this, so you get:

image.png

image.png

Is it possible to make VSCode only suggest true or false?

Kenny Lau (Sep 17 2025 at 10:20):

(update: import Lean is not needed)

Jakub Nowak (Sep 17 2025 at 11:04):

Not sure if completely removing "truman" and "falsify" from suggestions would be possible? But VSCode lists text suggestions last, so if lsp could suggest "true" and "false" as keywords it would ensure they're listed first.

Jakub Nowak (Sep 17 2025 at 11:04):

This example showcases the problem even more, because "true" and "false" are listed before "truman" and "falsify":

import Lean

syntax "#asdf " (&"truman" <|> &"falsify") : command

-- true false

#asdf t
#asdf f

Robin Arnez (Sep 17 2025 at 11:43):

you can do... uhh

import Lean

syntax (name := asdf) "#asdf " ident : command

-- truman falsify

open Lean Parser Elab Meta Command

@[command_elab asdf]
def elabAsdf : CommandElab := fun stx => do
  let newEnv := errorExplanationExt.setState ( getEnv) (.ofList [
    (`true, {
      doc := "_"
      metadata := {
        summary := "adfeq"
        sinceVersion := "r8347871"
      }
      declLoc? := none
    }),
    (`false, {
      doc := "_"
      metadata := {
        summary := "adfeq"
        sinceVersion := "r8347871"
      }
      declLoc? := none
    })
  ] _)
  let funnyCtx : PartialContextInfo := .commandCtx {
    env := newEnv
    fileMap :=  getFileMap
    ngen := {}
  }
  pushInfoTree <| .context funnyCtx <| .node (children := {}) <| .ofCompletionInfo <| .errorName stx stx[1]

#asdf true
#asdf false

Kenny Lau (Sep 17 2025 at 11:52):

:melt:

Aaron Liu (Sep 17 2025 at 18:49):

very complicated looking


Last updated: Dec 20 2025 at 21:32 UTC