diff --git a/Pantograph/Environment.lean b/Pantograph/Environment.lean index ad21284..c9f9fec 100644 --- a/Pantograph/Environment.lean +++ b/Pantograph/Environment.lean @@ -58,7 +58,7 @@ def inspect (args: Protocol.EnvInspect) (options: @&Protocol.Options): CoreM (Pr | none => return .error $ Protocol.errorIndex s!"Symbol not found {args.name}" | some info => pure info let module? := env.getModuleIdxFor? name >>= - (λ idx => env.allImportedModuleNames.get? idx.toNat) |>.map toString + (λ idx => env.allImportedModuleNames.get? idx.toNat) let value? := match args.value?, info with | .some true, _ => info.value? | .some false, _ => .none @@ -80,7 +80,7 @@ def inspect (args: Protocol.EnvInspect) (options: @&Protocol.Options): CoreM (Pr then value?.map (λ e => e.getUsedConstants.filter (!isNameInternal ·) |>.map (λ n => serializeName n) ) else .none, - module? := module? + module? := module?.map (·.toString) } let result ← match info with | .inductInfo induct => pure { core with inductInfo? := .some { @@ -113,6 +113,20 @@ def inspect (args: Protocol.EnvInspect) (options: @&Protocol.Options): CoreM (Pr k := r.k, } } | _ => pure core + let result ← if args.source?.getD false then + let searchPath ← searchPathRef.get + let sourceUri? ← module?.bindM (Server.documentUriFromModule searchPath ·) + let declRange? ← findDeclarationRanges? name + let sourceStart? := declRange?.map (·.range.pos) + let sourceEnd? := declRange?.map (·.range.endPos) + .pure { + result with + sourceUri?, + sourceStart?, + sourceEnd?, + } + else + .pure result return .ok result def addDecl (args: Protocol.EnvAdd): CoreM (Protocol.CR Protocol.EnvAddResult) := do let env ← Lean.MonadEnv.getEnv diff --git a/Pantograph/Protocol.lean b/Pantograph/Protocol.lean index 90ac149..67a37df 100644 --- a/Pantograph/Protocol.lean +++ b/Pantograph/Protocol.lean @@ -5,6 +5,7 @@ Note that no command other than `InteractionError` may have `error` as one of its field names to avoid confusion with error messages generated by the REPL. -/ import Lean.Data.Json +import Lean.Data.Position namespace Pantograph.Protocol @@ -121,11 +122,13 @@ structure EnvCatalogResult where -- Print the type of a symbol structure EnvInspect where name: String - -- If true/false, show/hide the value expressions; By default definitions - -- values are shown and theorem values are hidden. + -- Show the value expressions; By default definitions values are shown and + -- theorem values are hidden. value?: Option Bool := .some false - -- If true, show the type and value dependencies + -- Show the type and value dependencies dependency?: Option Bool := .some false + -- Show source location + source?: Option Bool := .some false deriving Lean.FromJson -- See `InductiveVal` structure InductInfo where @@ -172,6 +175,10 @@ structure EnvInspectResult where inductInfo?: Option InductInfo := .none constructorInfo?: Option ConstructorInfo := .none recursorInfo?: Option RecursorInfo := .none + + sourceUri?: Option String := .none + sourceStart?: Option Lean.Position := .none + sourceEnd?: Option Lean.Position := .none deriving Lean.ToJson structure EnvAdd where