branch: elpa/haskell-tng-mode commit 949f857074aaaf655e10491d7cb94ed4b2138e6c Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
support component directories --- cabal-ghcflags.sh | 11 ++++++++--- haskell-tng-hsinspect.el | 5 ++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cabal-ghcflags.sh b/cabal-ghcflags.sh index ca08e25..138bc4d 100755 --- a/cabal-ghcflags.sh +++ b/cabal-ghcflags.sh @@ -55,11 +55,16 @@ jq -c '(.["install-plan"][] | select(.["pkg-src"].type == "local") | select(.["c COMPONENT="$PART" fi - CACHE=$(echo "$ROOT/.ghc.flags.$PART" | sed 's/:/./g') - echo "creating $CACHE" rm "$TMP/out" 2> /dev/null cabal v2-repl -v0 -w "$TMP/ghc" "$NAME:$COMPONENT" - cat "$TMP/out" > "$CACHE" + + # extract all the source directories that use these flags + for D in $(cat "$TMP/out" | tr ' ' '\n' | grep '^-i' | sed 's/^-i//' | sed '/^$/d') ; do + if [ -d "$D" ] ; then + echo "writing $D/.ghc.flags" + cat "$TMP/out" > "$D/.ghc.flags" + fi + done done if [ -d "$TMP" ] ; then diff --git a/haskell-tng-hsinspect.el b/haskell-tng-hsinspect.el index 3600d6b..5d04250 100644 --- a/haskell-tng-hsinspect.el +++ b/haskell-tng-hsinspect.el @@ -55,14 +55,13 @@ change." (defun haskell-tng--hsinspect-ghcflags () ;; https://github.com/haskell/cabal/issues/6203 "Obtain the ghc flags for the current buffer" - (if-let (cache (locate-dominating-file default-directory ".ghc.flags.lib")) + (if-let (default-directory (locate-dominating-file default-directory ".ghc.flags")) (seq-map ;; hsinspect works best if we trick the compiler into thinking that the ;; file we are inspecting is independent of the current unit. (lambda (e) (if (equal e "-this-unit-id") "-package-id" e)) (with-temp-buffer - ;; FIXME support exe/test/etc components (discover the component) - (insert-file-contents (expand-file-name ".ghc.flags.lib" cache)) + (insert-file-contents (expand-file-name ".ghc.flags")) (split-string (buffer-substring-no-properties (point-min) (point-max))))) (user-error "could not find `.ghc.flags.lib'. Run `M-x haskell-tng-hsinspect'")))