Jump to source for imports

This commit is contained in:
2026-02-24 10:28:59 -08:00
parent ccdb15c6ec
commit 90e4bba766
4 changed files with 24 additions and 20 deletions

View File

@@ -14,6 +14,7 @@ import Data.IORef
import Node
import Commands
import Lib.ProcessDecl
import Lib.Prettier
pfunc js_castArray : Array JSObject JSObject := `x => x`
pfunc js_castInt : Int JSObject := `x => x`
@@ -49,9 +50,10 @@ resetState base = do
putStrLn "Reset base to \{base}"
writeIORef state $ MkLSPState emptyTop base emptyMap
lspFileSource : FileSource
lspFileSource = MkFileSource $ \fc fn => do
st <- readIORef state
lspFileSource : IO FileSource
lspFileSource = do
st <- readIORef state
pure $ MkFileSource st.baseDir $ \fc fn => do
let fn = st.baseDir ++ "/" ++ fn
let (Nothing) = lookupMap' fn st.files
| Just src => pure (fn,src)
@@ -73,14 +75,9 @@ updateFile fn src = unsafePerformIO $ do
modifyIORef state [ topContext := ctx ]
-- FIXME - this is an issue - FC doesn't distinguish empty and length 1.
-- Need to put the +1 on FC itself.
fcToRange : FC Json
fcToRange (MkFC uri (MkBounds sr sc er ec)) =
if sc == 0 && ec == 0
-- For the insert position in edits
then JsonObj $ ("start", mkPosition sr sc) :: ("end", mkPosition er (ec)) :: Nil
else JsonObj $ ("start", mkPosition sr sc) :: ("end", mkPosition er (ec)) :: Nil
JsonObj $ ("start", mkPosition sr sc) :: ("end", mkPosition er (ec)) :: Nil
where
mkPosition : Int Int Json
mkPosition l c = JsonObj $ ("line", JsonInt l) :: ("character", JsonInt c) :: Nil
@@ -94,8 +91,9 @@ hoverInfo uri line col = unsafePerformIO $ do
then resetState base
else pure MkUnit
st <- readIORef state
repo <- lspFileSource
-- We're proactively running check if there is no module information, make sure we save it
Right (top, Just (msg, fc)) <- (getHoverInfo lspFileSource modns line col).runM st.topContext
Right (top, Just (msg, fc)) <- (getHoverInfo repo modns line col).runM st.topContext
| Right (top, _) => do
modifyIORef state $ [ topContext := top ]
putStrLn $ "Nothing to see here"
@@ -114,8 +112,9 @@ codeActionInfo uri line col = unsafePerformIO $ do
st <- readIORef state
if (st.baseDir /= base) then resetState base else pure MkUnit
st <- readIORef state
repo <- lspFileSource
Right (top, actions) <- (do
actions <- getActions lspFileSource modns line col
actions <- getActions repo modns line col
putStrLn "\{show $ length' actions} actions"
pure actions).runM st.topContext
| Left err => do
@@ -200,9 +199,10 @@ checkFile fn = unsafePerformIO $ do
if (st.baseDir /= base)
then resetState base
else pure MkUnit
repo <- lspFileSource
(Right (top, json)) <- (do
putStrLn "processModule"
mod <- processModule emptyFC lspFileSource Nil modName
mod <- processModule emptyFC repo Nil modName
modifyTop [ currentMod := mod; ops := mod.modOps ]
-- pull out errors and infos
@@ -219,11 +219,4 @@ checkFile fn = unsafePerformIO $ do
modifyIORef state $ [ topContext := top ]
pure $ jsonToJObject $ JsonArray json
-- This seems like a hack, but it works.
-- Dummy main function with references to force functions into ouput file.
-- but we don't get `export` on it..
-- #export updateFile checkFile hoverInfo
#export updateFile checkFile hoverInfo codeActionInfo
-- pfunc main uses (updateFile checkFile hoverInfo codeActionInfo) : IO Unit := `() => {}`