File: .lake/packages/lean4/src/lean/Lean/Server/Completion.lean

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.consumeImplicitPrefix
code: private partial def Lean.Server.Completion.consumeImplicitPrefix (e : Expr) (k : Expr → MetaM α) : MetaM α 
goal: Lean.MetaM α

full_name: Lean.Lsp.CompletionIdentifier.fvar
code: /--
Identifier that is sent from the server to the client as part of the `CompletionItem.data?` field.
Needed to resolve the `CompletionItem` when the client sends a `completionItem/resolve` request
for that item, again containing the `data?` field provided by the server.
-/
inductive CompletionIdentifier where
  | const (declName : Name)
  | fvar  (id       : FVarId)
  deriving FromJson, ToJson
goal: Lean.Lsp.CompletionIdentifier

full_name: Lean.Lsp.CompletionIdentifier.const
code: /--
Identifier that is sent from the server to the client as part of the `CompletionItem.data?` field.
Needed to resolve the `CompletionItem` when the client sends a `completionItem/resolve` request
for that item, again containing the `data?` field provided by the server.
-/
inductive CompletionIdentifier where
  | const (declName : Name)
  | fvar  (id       : FVarId)
  deriving FromJson, ToJson
goal: Lean.Lsp.CompletionIdentifier

full_name: Lean.Lsp.CompletionIdentifier
code: /--
Identifier that is sent from the server to the client as part of the `CompletionItem.data?` field.
Needed to resolve the `CompletionItem` when the client sends a `completionItem/resolve` request
for that item, again containing the `data?` field provided by the server.
-/
inductive CompletionIdentifier where
  | const (declName : Name)
  | fvar  (id       : FVarId)
  deriving FromJson, ToJson
goal: Type

full_name: Lean.Lsp.instFromJsonCompletionIdentifier
code: FromJson
goal: Lean.FromJson Lean.Lsp.CompletionIdentifier

full_name: Lean.Lsp.instToJsonCompletionIdentifier
code: ToJson
goal: Lean.ToJson Lean.Lsp.CompletionIdentifier

full_name: Lean.Lsp.CompletionItemDataWithId.id?
code: /--
`CompletionItemData` that also contains a `CompletionIdentifier`.
See the documentation of`CompletionItemData` and `CompletionIdentifier`.
-/
structure CompletionItemDataWithId extends CompletionItemData where
  id?    : Option CompletionIdentifier
  deriving FromJson, ToJson
goal: Option Lean.Lsp.CompletionIdentifier

full_name: Lean.Lsp.CompletionItemDataWithId
code: /--
`CompletionItemData` that also contains a `CompletionIdentifier`.
See the documentation of`CompletionItemData` and `CompletionIdentifier`.
-/
structure CompletionItemDataWithId extends CompletionItemData where
  id?    : Option CompletionIdentifier
  deriving FromJson, ToJson
goal: Type

full_name: Lean.Lsp.instFromJsonCompletionItemDataWithId
code: FromJson
goal: Lean.FromJson Lean.Lsp.CompletionItemDataWithId

full_name: Lean.Lsp.instToJsonCompletionItemDataWithId
code: ToJson
goal: Lean.ToJson Lean.Lsp.CompletionItemDataWithId

full_name: Lean.Lsp.CompletionItem.resolve
code: /--
Fills the `CompletionItem.detail?` field of `item` using the pretty-printed type identified by `id`.
-/
def CompletionItem.resolve
    (item : CompletionItem)
    (id   : CompletionIdentifier)
    : MetaM CompletionItem 
goal: Lean.MetaM Lean.Lsp.CompletionItem

full_name: Lean.Server.Completion.EligibleHeaderDecls
code: abbrev EligibleHeaderDecls 
goal: Type

full_name: Lean.Server.Completion.initFn._@..lake.packages.lean4.src.lean.Lean.Server.Completion._hyg.723
code: /-- Cached header declarations for which `allowCompletion headerEnv decl` is true. -/
builtin_initialize eligibleHeaderDeclsRef : IO.Ref (Option EligibleHeaderDecls) ←
  IO.mkRef none
goal: IO (IO.Ref (Option Lean.Server.Completion.EligibleHeaderDecls))

full_name: Lean.Server.Completion.eligibleHeaderDeclsRef
code: /-- Cached header declarations for which `allowCompletion headerEnv decl` is true. -/
builtin_initialize eligibleHeaderDeclsRef : IO.Ref (Option EligibleHeaderDecls) ←
  IO.mkRef none
goal: IO.Ref (Option Lean.Server.Completion.EligibleHeaderDecls)

full_name: Lean.Server.Completion.getEligibleHeaderDecls
code: /--
Returns the declarations in the header for which `allowCompletion env decl` is true, caching them
if not already cached.
-/
def getEligibleHeaderDecls (env : Environment) : IO EligibleHeaderDecls 
goal: IO Lean.Server.Completion.EligibleHeaderDecls

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.forEligibleDeclsM
code: /-- Iterate over all declarations that are allowed in completion results. -/
private def forEligibleDeclsM [Monad m] [MonadEnv m] [MonadLiftT (ST IO.RealWorld) m]
    [MonadLiftT IO m] (f : Name → ConstantInfo → m PUnit) : m PUnit 
goal: m PUnit

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.allowCompletion
code: /-- Checks whether this declaration can appear in completion results. -/
private def allowCompletion (eligibleHeaderDecls : EligibleHeaderDecls) (env : Environment)
    (declName : Name) : Bool 
goal: Bool

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.sortCompletionItems
code: /--
Sorts `items` descendingly according to their score and ascendingly according to their label
for equal scores.
-/
private def sortCompletionItems (items : Array (CompletionItem × Float)) : Array CompletionItem 
goal: Array Lean.Lsp.CompletionItem

full_name: Lean.Server.Completion.State
code: /-- Intermediate state while completions are being computed. -/
structure State where
  /-- All completion items and their fuzzy match scores so far. -/
  items  : Array (CompletionItem × Float) := #[]
goal: Type

full_name: Lean.Server.Completion.State.items
code: /-- Intermediate state while completions are being computed. -/
structure State where
  /-- All completion items and their fuzzy match scores so far. -/
  items  : Array (CompletionItem × Float) := #[]
goal: Array (Lean.Lsp.CompletionItem × Float)

full_name: Lean.Server.Completion.M
code: /--
Monad used for completion computation that allows modifying a completion `State` and reading
`CompletionParams`.
-/
abbrev M 
goal: Type

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.addItem
code: /-- Adds a new completion item to the state in `M`. -/
private def addItem
    (item  : CompletionItem)
    (score : Float)
    (id?   : Option CompletionIdentifier := none)
    : M Unit 
goal: Lean.Server.Completion.M Unit

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.addUnresolvedCompletionItem
code: /--
Adds a new completion item with the given `label`, `id`, `kind` and `score` to the state in `M`.
Computes the doc string from the environment if available.
-/
private def addUnresolvedCompletionItem
    (label         : Name)
    (id            : CompletionIdentifier)
    (kind          : CompletionItemKind)
    (score         : Float)
    : M Unit 
goal: Lean.Server.Completion.M Unit

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.getCompletionKindForDecl
code: private def getCompletionKindForDecl (constInfo : ConstantInfo) : M CompletionItemKind 
goal: Lean.Server.Completion.M Lean.Lsp.CompletionItemKind

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.addUnresolvedCompletionItemForDecl
code: private def addUnresolvedCompletionItemForDecl (label : Name) (declName : Name) (score : Float) : M Unit 
goal: Lean.Server.Completion.M Unit

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.addKeywordCompletionItem
code: private def addKeywordCompletionItem (keyword : String) (score : Float) : M Unit 
goal: Lean.Server.Completion.M Unit

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.addNamespaceCompletionItem
code: private def addNamespaceCompletionItem (ns : Name) (score : Float) : M Unit 
goal: Lean.Server.Completion.M Unit

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.runM
code: private def runM (params : CompletionParams) (ctx : ContextInfo) (lctx : LocalContext) (x : M Unit)
    : IO (Option CompletionList) 
goal: IO (Option Lean.Lsp.CompletionList)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.matchAtomic
code: private def matchAtomic (id : Name) (declName : Name) : Option Float 
goal: Option Float

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.normPrivateName?
code: private def normPrivateName? (declName : Name) : MetaM (Option Name) 
goal: Lean.MetaM (Option Lean.Name)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.matchDecl?
code: /--
  Return the auto-completion label if `id` can be auto completed using `declName` assuming namespace `ns` is open.
  This function only succeeds with atomic labels. BTW, it seems most clients only use the last part.

  Remark: `danglingDot == true` when the completion point is an identifier followed by `.`.
-/
private def matchDecl? (ns : Name) (id : Name) (danglingDot : Bool) (declName : Name) : MetaM (Option (Name × Float)) 
goal: Lean.MetaM (Option (Lean.Name × Float))

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.truncate
code: /--
  Truncate the given identifier and make sure it has length `≤ newLength`.
  This function assumes `id` does not contain `Name.num` constructors.
-/
private partial def truncate (id : Name) (newLen : Nat) : Name 
goal: Lean.Name

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.truncate.go
code: /--
  Truncate the given identifier and make sure it has length `≤ newLength`.
  This function assumes `id` does not contain `Name.num` constructors.
-/
private partial def truncate (id : Name) (newLen : Nat) : Name 
goal: Lean.Name × Nat

full_name: Lean.Server.Completion.HoverInfo.inside
code: inductive HoverInfo where
  | after
  | inside (delta : Nat)
goal: Lean.Server.Completion.HoverInfo

full_name: Lean.Server.Completion.HoverInfo.after
code: inductive HoverInfo where
  | after
  | inside (delta : Nat)
goal: Lean.Server.Completion.HoverInfo

full_name: Lean.Server.Completion.HoverInfo
code: inductive HoverInfo where
  | after
  | inside (delta : Nat)
goal: Type

full_name: Lean.Server.Completion.matchNamespace
code: def matchNamespace (ns : Name) (nsFragment : Name) (danglingDot : Bool) : Option Float 
goal: Option Float

full_name: Lean.Server.Completion.completeNamespaces
code: def completeNamespaces (ctx : ContextInfo) (id : Name) (danglingDot : Bool) : M Unit 
goal: Lean.Server.Completion.M Unit

full_name: Lean.Server.Completion.completeNamespaces.visitNamespaces
code: def completeNamespaces (ctx : ContextInfo) (id : Name) (danglingDot : Bool) : M Unit 
goal: Lean.Server.Completion.M Unit

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.idCompletionCore.visitNamespaces
code: private def idCompletionCore
    (ctx         : ContextInfo)
    (id          : Name)
    (hoverInfo   : HoverInfo)
    (danglingDot : Bool)
    : M Unit 
goal: StateT (Option (Lean.Name × Float)) Lean.Server.Completion.M Unit

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.idCompletionCore
code: private def idCompletionCore
    (ctx         : ContextInfo)
    (id          : Name)
    (hoverInfo   : HoverInfo)
    (danglingDot : Bool)
    : M Unit 
goal: Lean.Server.Completion.M Unit

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.idCompletionCore.searchAlias
code: private def idCompletionCore
    (ctx         : ContextInfo)
    (id          : Name)
    (hoverInfo   : HoverInfo)
    (danglingDot : Bool)
    : M Unit 
goal: Lean.Server.Completion.M Unit

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.idCompletion
code: private def idCompletion
    (params        : CompletionParams)
    (ctx           : ContextInfo)
    (lctx          : LocalContext)
    (id            : Name)
    (hoverInfo     : HoverInfo)
    (danglingDot   : Bool)
    : IO (Option CompletionList) 
goal: IO (Option Lean.Lsp.CompletionList)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.unfoldeDefinitionGuarded?
code: private def unfoldeDefinitionGuarded? (e : Expr) : MetaM (Option Expr) 
goal: Lean.MetaM (Option Lean.Expr)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.isDefEqToAppOf
code: /-- Return `true` if `e` is a `declName`-application, or can be unfolded (delta-reduced) to one. -/
private partial def isDefEqToAppOf (e : Expr) (declName : Name) : MetaM Bool 
goal: Lean.MetaM Bool

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.isDotCompletionMethod
code: private def isDotCompletionMethod (typeName : Name) (info : ConstantInfo) : MetaM Bool 
goal: Lean.MetaM Bool

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.isDotIdCompletionMethod
code: /--
Checks whether the expected type of `info.type` can be reduced to an application of `typeName`.
-/
private def isDotIdCompletionMethod (typeName : Name) (info : ConstantInfo) : MetaM Bool 
goal: Lean.MetaM Bool

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.stripPrivatePrefix
code: /--
Converts `n` to `Name.anonymous` if `n` is a private prefix (see `Lean.isPrivatePrefix`).
-/
private def stripPrivatePrefix (n : Name) : Name 
goal: Lean.Name

full_name: Lean.Server.Completion.cmpModPrivate
code: /--
Compares `n₁` and `n₂` modulo private prefixes. Similar to `Name.cmp` but ignores all
private prefixes in both names.
Necessary because the namespaces of private names do not contain private prefixes.
-/
partial def cmpModPrivate (n₁ n₂ : Name) : Ordering 
goal: Ordering

full_name: Lean.Server.Completion.NameSetModPrivate
code: /--
`NameSet` where names are compared according to `cmpModPrivate`.
Helps speed up dot completion because it allows us to look up names without first having to
strip the private prefix from deep in the name, letting us reject most names without
having to scan the full name first.
-/
def NameSetModPrivate 
goal: Type

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.getDotCompletionTypeNames.visit
code: /--
  Given a type, try to extract relevant type names for dot notation field completion.
  We extract the type name, parent struct names, and unfold the type.
  The process mimics the dot notation elaboration procedure at `App.lean` -/
private partial def getDotCompletionTypeNames (type : Expr) : MetaM NameSetModPrivate 
goal: StateRefT' IO.RealWorld Lean.Server.Completion.NameSetModPrivate Lean.MetaM Unit

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.getDotCompletionTypeNames
code: /--
  Given a type, try to extract relevant type names for dot notation field completion.
  We extract the type name, parent struct names, and unfold the type.
  The process mimics the dot notation elaboration procedure at `App.lean` -/
private partial def getDotCompletionTypeNames (type : Expr) : MetaM NameSetModPrivate 
goal: Lean.MetaM Lean.Server.Completion.NameSetModPrivate

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.dotCompletion
code: private def dotCompletion
    (params        : CompletionParams)
    (ctx           : ContextInfo)
    (info          : TermInfo)
    (hoverInfo     : HoverInfo)
    : IO (Option CompletionList) 
goal: IO (Option Lean.Lsp.CompletionList)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.dotIdCompletion
code: private def dotIdCompletion
    (params        : CompletionParams)
    (ctx           : ContextInfo)
    (lctx          : LocalContext)
    (id            : Name)
    (expectedType? : Option Expr)
    : IO (Option CompletionList) 
goal: IO (Option Lean.Lsp.CompletionList)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.fieldIdCompletion
code: private def fieldIdCompletion
    (params     : CompletionParams)
    (ctx        : ContextInfo)
    (lctx       : LocalContext)
    (id         : Name)
    (structName : Name)
    : IO (Option CompletionList) 
goal: IO (Option Lean.Lsp.CompletionList)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.optionCompletion
code: private def optionCompletion
    (params : CompletionParams)
    (ctx    : ContextInfo)
    (stx    : Syntax)
    (caps   : ClientCapabilities)
    : IO (Option CompletionList) 
goal: IO (Option Lean.Lsp.CompletionList)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.tacticCompletion
code: private def tacticCompletion (params : CompletionParams) (ctx : ContextInfo) : IO (Option CompletionList) 
goal: IO (Option Lean.Lsp.CompletionList)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.findCompletionInfoAt?.choose
code: private def findCompletionInfoAt?
    (fileMap  : FileMap)
    (hoverPos : String.Pos)
    (infoTree : InfoTree)
    : Option (HoverInfo × ContextInfo × CompletionInfo) 
goal: Option (Lean.Server.Completion.HoverInfo × Lean.Elab.ContextInfo × Lean.Elab.Info)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.findCompletionInfoAt?
code: private def findCompletionInfoAt?
    (fileMap  : FileMap)
    (hoverPos : String.Pos)
    (infoTree : InfoTree)
    : Option (HoverInfo × ContextInfo × CompletionInfo) 
goal: Option (Lean.Server.Completion.HoverInfo × Lean.Elab.ContextInfo × Lean.Elab.CompletionInfo)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.Completion.0.Lean.Server.Completion.assignSortTexts
code: /--
Assigns the `CompletionItem.sortText?` for all items in `completions` according to their order
in `completions`. This is necessary because clients will use their own sort order if the server
does not set it.
-/
private def assignSortTexts (completions : CompletionList) : CompletionList 
goal: Lean.Lsp.CompletionList

full_name: Lean.Server.Completion.find?
code: partial def find?
    (params   : CompletionParams)
    (fileMap  : FileMap)
    (hoverPos : String.Pos)
    (infoTree : InfoTree)
    (caps     : ClientCapabilities)
    : IO (Option CompletionList) 
goal: IO (Option Lean.Lsp.CompletionList)

full_name: Lean.Server.Completion.resolveCompletionItem?
code: /--
Fills the `CompletionItem.detail?` field of `item` using the pretty-printed type identified by `id`
in the context found at `hoverPos` in `infoTree`.
-/
def resolveCompletionItem?
    (fileMap  : FileMap)
    (hoverPos : String.Pos)
    (infoTree : InfoTree)
    (item     : CompletionItem)
    (id       : CompletionIdentifier)
    : IO CompletionItem 
goal: IO Lean.Lsp.CompletionItem