Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update branch to main #139

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions expect_tests/HirTest.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE QuasiQuotes #-}

module HirTest (tests) where
module HirTest where

import AST.Haskell qualified as H
import Data.Text qualified as T
Expand All @@ -19,9 +19,10 @@ checkParse name source ex = test name ex $ do
checkHir :: String -> T.Text -> Expect -> TestTree
checkHir name source ex = test name ex $ do
let tree = H.parse source
let (es, hir) = Hir.parseHaskell tree
let (_es, hir) = Hir.parseHaskell tree
pure $ TL.toStrict $ Pretty.pShowNoColor hir

src1 :: T.Text
src1 =
[trimming|
module First where
Expand All @@ -30,6 +31,7 @@ src1 =
import Second (First, C(.., first, type Another, (+++))) as Another
|]

src2 :: T.Text
src2 =
[trimming|
module Second
Expand All @@ -43,6 +45,7 @@ src2 =

|]

src3 :: T.Text
src3 =
[trimming|
module Third where
Expand Down Expand Up @@ -74,6 +77,7 @@ src3 =
first :: a -> a
|]

tests :: TestTree
tests =
testGroup
"HirTest"
Expand Down
1 change: 0 additions & 1 deletion expect_tests/Main.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Main where

import Data.Text qualified as T
import HirTest qualified
import Test.Tasty
import Test.Tasty.Expect
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies:
- sqlite-simple >= 0.4.18 && < 0.5
- template-haskell >= 2.19.0 && < 2.23
- text >= 2.0.1 && < 2.2
- time >= 1.0 && < 2.0
- bytestring >=0.10 && <0.13
- transformers >= 0.5.6.2 && < 0.7
- unliftio-core >= 0.2.1 && < 0.3
Expand Down
11 changes: 11 additions & 0 deletions src/Data/ConcurrentCache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
module Data.ConcurrentCache (
ConcurrentCache,
new,
Data.ConcurrentCache.lookup,
remove,
insert,
) where

import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.IO.Unlift (MonadUnliftIO)
import Control.Monad.Trans.Class
import Control.Monad.Trans.Maybe
import Data.HashMap.Strict (HashMap)
import Data.HashMap.Strict qualified as HashMap
import Data.Hashable (Hashable)
import StaticLS.Maybe
import UnliftIO (onException)
import UnliftIO.Exception (mask)
import UnliftIO.IORef (IORef)
Expand All @@ -37,6 +41,13 @@ remove k cache = do
IORef.atomicModifyIORef' cache.map \m -> do
(HashMap.delete k m, ())

lookup :: (MonadIO m, Hashable k) => k -> ConcurrentCache k v -> m (Maybe v)
lookup k cache = do
runMaybeT $ do
cacheMap <- lift $ IORef.readIORef cache.map
(m :: MVar (Maybe v)) <- toAlt $ HashMap.lookup k cacheMap
MaybeT $ MVar.readMVar m

insert :: (Hashable k, MonadUnliftIO m) => k -> m v -> ConcurrentCache k v -> m v
insert k act cache = mask \restore -> do
var <- MVar.newEmptyMVar
Expand Down
2 changes: 0 additions & 2 deletions src/StaticLS/Except.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ module StaticLS.Except where
import Control.Error.Util
import Control.Monad.Trans.Except
import Data.Pos (Pos (..))
import Data.Text (Text)
import StaticLS.HieView.View

exceptToMaybe :: Except a b -> Maybe b
exceptToMaybe = hush . runExcept
Expand Down
11 changes: 10 additions & 1 deletion src/StaticLS/FilePath.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
module StaticLS.FilePath (modToFilePath, subRootExtensionFilepath) where
module StaticLS.FilePath (modToFilePath, subRootExtensionFilepath, getFileModifiedAt) where

import Control.Monad.IO.Class
import Control.Monad.Trans.Maybe
import Data.List qualified as List
import Data.Path (AbsPath, Path (..), RelPath)
import Data.Path qualified as Path
import Data.Time
import GHC.Plugins qualified as GHC
import StaticLS.SrcFiles
import System.Directory qualified as Dir
import System.FilePath ((-<.>))
import System.IO.Error

getFileModifiedAt :: (MonadIO m) => AbsPath -> MaybeT m UTCTime
getFileModifiedAt path = do
MaybeT $
liftIO $
(Just <$> Dir.getModificationTime (Path.toFilePath path))
`catchIOError` const (pure Nothing)

modToFilePath :: GHC.ModuleName -> String -> RelPath
modToFilePath modName ext =
Expand Down
5 changes: 3 additions & 2 deletions src/StaticLS/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ handleDidChange = LSP.notificationHandler LSP.SMethod_TextDocumentDidChange $ \m
handleDidSave :: Handlers (LspT c StaticLsM)
handleDidSave = LSP.notificationHandler LSP.SMethod_TextDocumentDidSave $ \message -> do
let params = message._params
let _uri = params._textDocument._uri
pure ()
let uri = params._textDocument._uri
-- Useful to invalidate for file watchers if a branch checkout invalidates the file state cache
updateFileStateForUri uri

handleDidClose :: Handlers (LspT c StaticLsM)
handleDidClose = LSP.notificationHandler LSP.SMethod_TextDocumentDidClose $ \_ -> do
Expand Down
2 changes: 1 addition & 1 deletion src/StaticLS/HieView/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fileEvidenceBinds file =
)
file
where
evSourceNames (EvInstBind {cls}) = Nothing
evSourceNames (EvInstBind {}) = Nothing
evSourceNames (EvLetBind (EvBindDeps {deps})) = Just deps
evSourceNames EvOther = Nothing

Expand Down
4 changes: 2 additions & 2 deletions src/StaticLS/HieView/Type.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module StaticLS.HieView.Type (
Type,
TypeArray,
FlatType,
TypeArray (..),
FlatType (..),
TypeIndex (..),
fromGHCHieType,
fromGHCHieTypeFlat,
Expand Down
12 changes: 6 additions & 6 deletions src/StaticLS/Hir/Make.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ mkModuleText parts =
, text = T.intercalate "." (NE.toList parts)
}

mkModuleName :: NonEmpty Text -> ModuleName
mkModuleName parts =
ModuleName
{ mod = mkModuleText parts
-- , node = AST.defaultNode
}
-- mkModuleName :: NonEmpty Text -> ModuleName
-- mkModuleName parts =
-- ModuleName
-- { mod = mkModuleText parts
-- , node = AST.defaultNode
-- }
4 changes: 3 additions & 1 deletion src/StaticLS/IDE/CodeActions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Data.Path (AbsPath)
import Data.Rope qualified as Rope
import StaticLS.IDE.CodeActions.AddTypeSig qualified as AddTypeSig
import StaticLS.IDE.CodeActions.AutoImport qualified as AutoImport
import StaticLS.IDE.CodeActions.RemoveRedundantImports as RemoveRedundantImports
import StaticLS.IDE.CodeActions.Types
import StaticLS.IDE.Monad
import StaticLS.IDE.SourceEdit (SourceEdit)
Expand All @@ -23,7 +24,8 @@ getCodeActions path lineCol = do
let cx = CodeActionContext {path, pos, lineCol}
typesCodeActions <- AddTypeSig.codeAction cx
importCodeActions <- AutoImport.codeAction cx
let codeActions = typesCodeActions ++ importCodeActions
removeRedundantImports <- RemoveRedundantImports.codeAction cx
let codeActions = typesCodeActions ++ importCodeActions ++ removeRedundantImports
pure codeActions

resolveLazyAssist :: CodeActionMessage -> StaticLsM SourceEdit
Expand Down
2 changes: 1 addition & 1 deletion src/StaticLS/IDE/CodeActions/AddTypeSig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type BindName = Haskell.PrefixId :+ Haskell.Variable :+ Nil

-- For now, it only works with top level declarations
getDeclarationNameAtPos :: Haskell.Haskell -> Pos -> LineCol -> AST.Err (Maybe BindName)
getDeclarationNameAtPos haskell pos lineCol = do
getDeclarationNameAtPos haskell pos _lineCol = do
let node = AST.getDeepestContaining @AddTypeContext (Range.point pos) haskell.dynNode
case node of
Just bind
Expand Down
2 changes: 1 addition & 1 deletion src/StaticLS/IDE/CodeActions/AutoExport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ getDeclarationsAtPoint range decls =
codeAction :: CodeActionContext -> StaticLsM [Assist]
codeAction cx = do
hir <- getHir cx.path
let decls = getDeclarationsAtPoint (Range.point cx.pos) hir.decls
let _decls = getDeclarationsAtPoint (Range.point cx.pos) hir.decls
pure []
4 changes: 2 additions & 2 deletions src/StaticLS/IDE/CodeActions/AutoImport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ createAutoImportCodeActions path mQualifier importMod =
]

codeAction :: CodeActionContext -> StaticLsM [Assist]
codeAction CodeActionContext {path, lineCol, pos} = do
codeAction CodeActionContext {path, pos} = do
hir <- getHir path
modulesToImport <- getModulesToImport path pos

Expand Down Expand Up @@ -135,7 +135,7 @@ data ImportInsertPoint
| AfterImportInsertPoint !Pos

getImportsInsertPoint :: Rope -> Haskell.Haskell -> AST.Err ImportInsertPoint
getImportsInsertPoint rope hs = do
getImportsInsertPoint _rope hs = do
imports <- Tree.getImports hs
header <- Tree.getHeader hs
let headerPos =
Expand Down
Loading
Loading