@@ -15,6 +15,8 @@ import Distribution.Utils.Path (getSymbolicPath)
15
15
import Ide.Plugin.Cabal.Completion.Types
16
16
import qualified System.FilePath as FP
17
17
import qualified System.FilePath.Posix as Posix
18
+ import Data.List.Extra (dropPrefix )
19
+ import Data.List (isPrefixOf )
18
20
19
21
20
22
{- | Information used to query and build path completions.
@@ -45,6 +47,26 @@ data PathCompletionInfo = PathCompletionInfo
45
47
}
46
48
deriving (Eq , Show )
47
49
50
+
51
+ {- | Posix.splitFileName modification, that drops trailing ./ if
52
+ if wasn't present in the original path.
53
+
54
+ Fix for the issue #3774
55
+
56
+ Examples of path splitting:
57
+ "" -> ("", "") instead of ("./","")
58
+ "./" -> ("./", "")
59
+ "dir" -> ("", "dir") instead of ("./","dir")
60
+ "./dir" -> ("./", "dir")
61
+ "dir1/dir2" -> ("dir1/","dir2")
62
+ "./dir1/dir2" -> ("./dir1/","dir2")
63
+ -}
64
+ splitFileNameNoTrailingSlash :: FilePath -> (String , String )
65
+ splitFileNameNoTrailingSlash prefix = rmTrailingSlash (" ./" `isPrefixOf` prefix) (Posix. splitFileName prefix)
66
+ where rmTrailingSlash hadTrailingSlash (queryDirectory', pathSegment')
67
+ | hadTrailingSlash = (queryDirectory', pathSegment')
68
+ | otherwise = (" ./" `dropPrefix` queryDirectory', pathSegment')
69
+
48
70
{- | Takes an optional source subdirectory and a prefix info
49
71
and creates a path completion info accordingly.
50
72
@@ -64,7 +86,7 @@ pathCompletionInfoFromCabalPrefixInfo srcDir prefInfo =
64
86
}
65
87
where
66
88
prefix = T. unpack $ completionPrefix prefInfo
67
- (queryDirectory', pathSegment') = Posix. splitFileName prefix
89
+ (queryDirectory', pathSegment') = splitFileNameNoTrailingSlash prefix
68
90
69
91
-- | Extracts the source directories of the library stanza.
70
92
sourceDirsExtractionLibrary :: Maybe StanzaName -> GenericPackageDescription -> [FilePath ]
0 commit comments