Skip to content

Commit

Permalink
Remove .hls directory magic strings
Browse files Browse the repository at this point in the history
  • Loading branch information
nlander committed Aug 17, 2023
1 parent 6b98465 commit 3d098ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ghcide/src/Development/IDE/Core/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import qualified Development.IDE.Spans.AtPoint as AtPoint
import Development.IDE.Types.HscEnvEq (hscEnv)
import Development.IDE.Types.Location
import qualified HieDb
import Ide.Types (hlsDirectory, dependenciesDirectory)
import Language.LSP.Protocol.Types (DocumentHighlight (..),
SymbolInformation (..),
normalizedFilePathToUri,
Expand Down Expand Up @@ -116,7 +117,7 @@ lookupMod HieDbWriter{indexQueue} hieFile moduleName uid _boot = MaybeT $ do
-- name and hash of the package the dependency module is
-- found in. The name and hash are both parts of the UnitId.
writeOutDir :: FilePath
writeOutDir = projectRoot </> ".hls" </> "dependencies" </> show uid
writeOutDir = projectRoot </> hlsDirectory </> dependenciesDirectory </> show uid
-- The module name is separated into directories, with the
-- last part of the module name giving the name of the
-- haskell file with a .hs extension.
Expand Down
3 changes: 2 additions & 1 deletion ghcide/src/Development/IDE/Core/Dependencies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import HieDb (SourceFile (FakeFile),
lookupPackage,
removeDependencySrcFiles)
import Ide.Logger (Recorder, WithPriority)
import Ide.Types (hlsDirectory)
import Language.LSP.Server (resRootPath)
import System.Directory (doesDirectoryExist)
import System.FilePath ((<.>), (</>))
Expand All @@ -46,7 +47,7 @@ indexDependencyHieFiles recorder se hscEnv = do
mHlsDir :: Maybe FilePath
mHlsDir = do
projectDir <- resRootPath =<< lspEnv se
pure $ projectDir </> ".hls"
pure $ projectDir </> hlsDirectory
-- Add the deletion of dependency source files from the
-- HieDb database to the database write queue.
deleteMissingDependencySources :: IO ()
Expand Down
10 changes: 9 additions & 1 deletion hls-plugin-api/src/Ide/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ module Ide.Types
, PluginNotificationHandlers(..)
, PluginRequestMethod(..)
, SourceFileOrigin(..)
, dependenciesDirectory
, hlsDirectory
, getSourceFileOrigin
, getProcessID, getPid
, installSigUsr1Handler
Expand Down Expand Up @@ -296,13 +298,19 @@ data PluginFileType = PluginFileType [SourceFileOrigin] [T.Text]

data SourceFileOrigin = FromProject | FromDependency deriving Eq

hlsDirectory :: FilePath
hlsDirectory = ".hls"

dependenciesDirectory :: FilePath
dependenciesDirectory = "dependencies"

-- | Dependency files are written to the .hls/dependencies directory
-- under the project root.
-- If a file is not in this directory, we assume that it is a
-- project file.
getSourceFileOrigin :: NormalizedFilePath -> SourceFileOrigin
getSourceFileOrigin f =
case [".hls", "dependencies"] `isInfixOf` (splitDirectories file) of
case [hlsDirectory, dependenciesDirectory] `isInfixOf` (splitDirectories file) of
True -> FromDependency
False -> FromProject
where
Expand Down

0 comments on commit 3d098ba

Please sign in to comment.