Jump to source for imports
This commit is contained in:
@@ -13,6 +13,9 @@ import Lib.Elab
|
||||
import Data.String
|
||||
import Lib.Eval
|
||||
import Data.SortedMap
|
||||
import Lib.Parser
|
||||
import Lib.Syntax
|
||||
import Lib.Parser.Impl
|
||||
|
||||
-- For now we cheat and assume capitalized directories are a module component
|
||||
decomposeName : String → String × String
|
||||
@@ -46,6 +49,12 @@ getHoverInfo repo modns row col = do
|
||||
let (Right toks) = tokenise "" line | Left _ => pure Nothing
|
||||
let (Just name) = getTok toks | _ => pure Nothing
|
||||
|
||||
let (Left _) = partialParse "" parseImport emptyMap toks
|
||||
| Right ((MkImport _ (fc, nm)), _, _) => do
|
||||
let (baseDir, _) = splitFileName fc.file
|
||||
let fc = MkFC (repo.baseDir ++ "/" ++ joinBy "/" (split nm ".")) (MkBounds 0 0 0 0)
|
||||
pure $ Just ("module \{nm}", fc)
|
||||
|
||||
-- Lookup the name
|
||||
let (Just e) = lookupRaw name top | _ => pure Nothing
|
||||
ty <- nf Nil e.type
|
||||
@@ -175,6 +184,7 @@ getCaseSplit row col fc@(MkFC uri (MkBounds sr sc er ec)) ctx nm scty = do
|
||||
let names = map fst cons
|
||||
putStrLn "Make splits for \{show names}"
|
||||
edits <- makeEdits fc names True
|
||||
-- TODO if constructor is not in scope, add import too.
|
||||
pure $ Just $ CaseSplitAction edits
|
||||
|
||||
posInFC : Int → Int → FC → Bool
|
||||
|
||||
29
src/LSP.newt
29
src/LSP.newt
@@ -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
|
||||
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 := `() => {}`
|
||||
|
||||
@@ -26,6 +26,7 @@ addPrimitives = do
|
||||
pure top.currentMod
|
||||
|
||||
record FileSource where
|
||||
baseDir : String
|
||||
getFile : FC → String → M (String × String)
|
||||
|
||||
parseDecls : String → Operators → TokenList → SnocList Decl → M (List Decl × Operators)
|
||||
|
||||
@@ -21,7 +21,7 @@ import Node
|
||||
import Revision
|
||||
|
||||
dirFileSource : String → FileSource
|
||||
dirFileSource base = MkFileSource $ \fc fn => do
|
||||
dirFileSource base = MkFileSource base $ \fc fn => do
|
||||
let fn = base ++ "/" ++ fn
|
||||
(Right src) <- liftIO {M} $ readFile fn
|
||||
| Left err => throwError $ E fc "error reading \{fn}: \{show err}"
|
||||
|
||||
Reference in New Issue
Block a user