LSP jump to definition

This commit is contained in:
2026-02-12 21:59:56 -08:00
parent ab33635642
commit e1d83556ae
6 changed files with 44 additions and 22 deletions

View File

@@ -24,7 +24,7 @@ decomposeName fn =
-- The cheap version of type at point, find the token, lookup in global context
-- Later we will either get good FC for entries or scan them all and build a cache.
getHoverInfo : FileSource List String Int Int M (Maybe String)
getHoverInfo : FileSource List String Int Int M (Maybe (String × FC))
getHoverInfo repo modns row col = do
mod <- processModule emptyFC repo Nil modns
-- not necessarily loaded into top... (Maybe push this down into that branch of processModule)
@@ -39,7 +39,7 @@ getHoverInfo repo modns row col = do
-- Lookup the name
let (Just e) = lookupRaw name top | _ => pure Nothing
pure $ Just "\{show e.name} : \{rpprint Nil e.type}"
pure $ Just ("\{show e.name} : \{rpprint Nil e.type}", e.fc)
where
getTok : List BTok Maybe String

View File

@@ -79,6 +79,14 @@ updateFile fn src = unsafePerformIO $ do
-- modifyIORef state [ topContext := ctx ]
modifyIORef state $ \a => [ topContext := ctx ] a
fcToRange : FC Json
fcToRange (MkFC uri (MkBounds sr sc er ec)) =
JsonObj $ ("start", mkPosition sr sc) :: ("end", mkPosition er (ec + 1)) :: Nil
where
mkPosition : Int Int Json
mkPosition l c = JsonObj $ ("line", JsonInt l) :: ("character", JsonInt c) :: Nil
hoverInfo : String Int Int JSObject
hoverInfo uri line col = unsafePerformIO $ do
let (base,modns) = decomposeName uri
@@ -87,27 +95,24 @@ hoverInfo uri line col = unsafePerformIO $ do
if (st.baseDir /= base)
then resetState base
else pure MkUnit
Right (_, Just msg) <- (getHoverInfo lspFileSource modns line col).runM st.topContext
Right (_, Just (msg, fc)) <- (getHoverInfo lspFileSource modns line col).runM st.topContext
| Right _ => do
putStrLn $ "Nothing to see here"
pure $ jsonToJObject JsonNull
| Left err => do
putStrLn $ showError "" err
pure $ jsonToJObject JsonNull
pure $ jsonToJObject $ JsonStr msg
let location = JsonObj $ ("uri", JsonStr fc.file) :: ("range", fcToRange fc) :: Nil
pure $ jsonToJObject $ JsonObj $ ("info", JsonStr msg) :: ("location", location) :: Nil
errorToDiag : Error -> Json
errorToDiag (E (MkFC fn (MkBounds sr sc er ec)) msg) =
errorToDiag (E fc msg) =
JsonObj
$ ("severity", JsonInt 1)
-- PARSER `$` is winning over `,`, which is not what I'm expecting Maybe `,` should be special...
:: ("range", (JsonObj $ ("start", range sr sc) :: ("end", range er (ec + 1)) :: Nil))
:: ("range", fcToRange fc)
:: ("message", JsonStr msg)
:: ("source", JsonStr "newt") -- what is this key for?
:: Nil
where
range : Int Int Json
range l c = JsonObj $ ("line", JsonInt l) :: ("character", JsonInt c) :: Nil
-- These shouldn't escape
errorToDiag (Postpone fc qn msg) = errorToDiag $ E fc "Postpone \{show qn} \{msg}"

View File

@@ -440,10 +440,8 @@ solve env m sp t = do
-- let someone else solve this and then check again.
debug $ \ _ => "CONSTRAINT2 \{show ix} \{show sp} =?= \{show t}"
addConstraint env m sp t
E fc msg => throwError (E fc "\{msg} for \{show ix} \{show sp} =?= \{show t}")
-- debug $ \ _ => "CONSTRAINT3 \{show ix} \{show sp} =?= \{show t}"
-- debug $ \ _ => "because \{showError "" err}"
-- addConstraint env m sp t
-- replace with wrapper
err => throwError (E (getFC err) "\{errorMsg err} for \{show ix} \{show sp} =?= \{show t}")
)
unifySpine : Env -> UnifyMode -> Bool -> SnocList Val -> SnocList Val -> M UnifyResult