Jump to source for imports
This commit is contained in:
@@ -13,6 +13,9 @@ import Lib.Elab
|
|||||||
import Data.String
|
import Data.String
|
||||||
import Lib.Eval
|
import Lib.Eval
|
||||||
import Data.SortedMap
|
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
|
-- For now we cheat and assume capitalized directories are a module component
|
||||||
decomposeName : String → String × String
|
decomposeName : String → String × String
|
||||||
@@ -46,6 +49,12 @@ getHoverInfo repo modns row col = do
|
|||||||
let (Right toks) = tokenise "" line | Left _ => pure Nothing
|
let (Right toks) = tokenise "" line | Left _ => pure Nothing
|
||||||
let (Just name) = getTok toks | _ => 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
|
-- Lookup the name
|
||||||
let (Just e) = lookupRaw name top | _ => pure Nothing
|
let (Just e) = lookupRaw name top | _ => pure Nothing
|
||||||
ty <- nf Nil e.type
|
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
|
let names = map fst cons
|
||||||
putStrLn "Make splits for \{show names}"
|
putStrLn "Make splits for \{show names}"
|
||||||
edits <- makeEdits fc names True
|
edits <- makeEdits fc names True
|
||||||
|
-- TODO if constructor is not in scope, add import too.
|
||||||
pure $ Just $ CaseSplitAction edits
|
pure $ Just $ CaseSplitAction edits
|
||||||
|
|
||||||
posInFC : Int → Int → FC → Bool
|
posInFC : Int → Int → FC → Bool
|
||||||
|
|||||||
29
src/LSP.newt
29
src/LSP.newt
@@ -14,6 +14,7 @@ import Data.IORef
|
|||||||
import Node
|
import Node
|
||||||
import Commands
|
import Commands
|
||||||
import Lib.ProcessDecl
|
import Lib.ProcessDecl
|
||||||
|
import Lib.Prettier
|
||||||
|
|
||||||
pfunc js_castArray : Array JSObject → JSObject := `x => x`
|
pfunc js_castArray : Array JSObject → JSObject := `x => x`
|
||||||
pfunc js_castInt : Int → JSObject := `x => x`
|
pfunc js_castInt : Int → JSObject := `x => x`
|
||||||
@@ -49,9 +50,10 @@ resetState base = do
|
|||||||
putStrLn "Reset base to \{base}"
|
putStrLn "Reset base to \{base}"
|
||||||
writeIORef state $ MkLSPState emptyTop base emptyMap
|
writeIORef state $ MkLSPState emptyTop base emptyMap
|
||||||
|
|
||||||
lspFileSource : FileSource
|
lspFileSource : IO FileSource
|
||||||
lspFileSource = MkFileSource $ \fc fn => do
|
lspFileSource = do
|
||||||
st <- readIORef state
|
st <- readIORef state
|
||||||
|
pure $ MkFileSource st.baseDir $ \fc fn => do
|
||||||
let fn = st.baseDir ++ "/" ++ fn
|
let fn = st.baseDir ++ "/" ++ fn
|
||||||
let (Nothing) = lookupMap' fn st.files
|
let (Nothing) = lookupMap' fn st.files
|
||||||
| Just src => pure (fn,src)
|
| Just src => pure (fn,src)
|
||||||
@@ -73,14 +75,9 @@ updateFile fn src = unsafePerformIO $ do
|
|||||||
modifyIORef state [ topContext := ctx ]
|
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 : FC → Json
|
||||||
fcToRange (MkFC uri (MkBounds sr sc er ec)) =
|
fcToRange (MkFC uri (MkBounds sr sc er ec)) =
|
||||||
if sc == 0 && ec == 0
|
JsonObj $ ("start", mkPosition sr sc) :: ("end", mkPosition er (ec)) :: Nil
|
||||||
-- 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
|
|
||||||
where
|
where
|
||||||
mkPosition : Int → Int → Json
|
mkPosition : Int → Int → Json
|
||||||
mkPosition l c = JsonObj $ ("line", JsonInt l) :: ("character", JsonInt c) :: Nil
|
mkPosition l c = JsonObj $ ("line", JsonInt l) :: ("character", JsonInt c) :: Nil
|
||||||
@@ -94,8 +91,9 @@ hoverInfo uri line col = unsafePerformIO $ do
|
|||||||
then resetState base
|
then resetState base
|
||||||
else pure MkUnit
|
else pure MkUnit
|
||||||
st <- readIORef state
|
st <- readIORef state
|
||||||
|
repo <- lspFileSource
|
||||||
-- We're proactively running check if there is no module information, make sure we save it
|
-- 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
|
| Right (top, _) => do
|
||||||
modifyIORef state $ [ topContext := top ]
|
modifyIORef state $ [ topContext := top ]
|
||||||
putStrLn $ "Nothing to see here"
|
putStrLn $ "Nothing to see here"
|
||||||
@@ -114,8 +112,9 @@ codeActionInfo uri line col = unsafePerformIO $ do
|
|||||||
st <- readIORef state
|
st <- readIORef state
|
||||||
if (st.baseDir /= base) then resetState base else pure MkUnit
|
if (st.baseDir /= base) then resetState base else pure MkUnit
|
||||||
st <- readIORef state
|
st <- readIORef state
|
||||||
|
repo <- lspFileSource
|
||||||
Right (top, actions) <- (do
|
Right (top, actions) <- (do
|
||||||
actions <- getActions lspFileSource modns line col
|
actions <- getActions repo modns line col
|
||||||
putStrLn "\{show $ length' actions} actions"
|
putStrLn "\{show $ length' actions} actions"
|
||||||
pure actions).runM st.topContext
|
pure actions).runM st.topContext
|
||||||
| Left err => do
|
| Left err => do
|
||||||
@@ -200,9 +199,10 @@ checkFile fn = unsafePerformIO $ do
|
|||||||
if (st.baseDir /= base)
|
if (st.baseDir /= base)
|
||||||
then resetState base
|
then resetState base
|
||||||
else pure MkUnit
|
else pure MkUnit
|
||||||
|
repo <- lspFileSource
|
||||||
(Right (top, json)) <- (do
|
(Right (top, json)) <- (do
|
||||||
putStrLn "processModule"
|
putStrLn "processModule"
|
||||||
mod <- processModule emptyFC lspFileSource Nil modName
|
mod <- processModule emptyFC repo Nil modName
|
||||||
modifyTop [ currentMod := mod; ops := mod.modOps ]
|
modifyTop [ currentMod := mod; ops := mod.modOps ]
|
||||||
|
|
||||||
-- pull out errors and infos
|
-- pull out errors and infos
|
||||||
@@ -219,11 +219,4 @@ checkFile fn = unsafePerformIO $ do
|
|||||||
modifyIORef state $ [ topContext := top ]
|
modifyIORef state $ [ topContext := top ]
|
||||||
pure $ jsonToJObject $ JsonArray json
|
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
|
#export updateFile checkFile hoverInfo codeActionInfo
|
||||||
|
|
||||||
-- pfunc main uses (updateFile checkFile hoverInfo codeActionInfo) : IO Unit := `() => {}`
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ addPrimitives = do
|
|||||||
pure top.currentMod
|
pure top.currentMod
|
||||||
|
|
||||||
record FileSource where
|
record FileSource where
|
||||||
|
baseDir : String
|
||||||
getFile : FC → String → M (String × String)
|
getFile : FC → String → M (String × String)
|
||||||
|
|
||||||
parseDecls : String → Operators → TokenList → SnocList Decl → M (List Decl × Operators)
|
parseDecls : String → Operators → TokenList → SnocList Decl → M (List Decl × Operators)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import Node
|
|||||||
import Revision
|
import Revision
|
||||||
|
|
||||||
dirFileSource : String → FileSource
|
dirFileSource : String → FileSource
|
||||||
dirFileSource base = MkFileSource $ \fc fn => do
|
dirFileSource base = MkFileSource base $ \fc fn => do
|
||||||
let fn = base ++ "/" ++ fn
|
let fn = base ++ "/" ++ fn
|
||||||
(Right src) <- liftIO {M} $ readFile fn
|
(Right src) <- liftIO {M} $ readFile fn
|
||||||
| Left err => throwError $ E fc "error reading \{fn}: \{show err}"
|
| Left err => throwError $ E fc "error reading \{fn}: \{show err}"
|
||||||
|
|||||||
Reference in New Issue
Block a user