-
Notifications
You must be signed in to change notification settings - Fork 457
Drop pathtype, part two #689
Changes from all commits
841cd22
a507b45
b8d0505
459338f
6e1aaef
b054d2c
dd1b9f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,13 +8,11 @@ module Analysis.Blob | |
| , nullBlob | ||
| ) where | ||
|
|
||
| import Analysis.File as A | ||
| import Analysis.Reference as A | ||
| import Data.Aeson | ||
| import Source.Language as Language | ||
| import Source.Source as Source | ||
| import qualified System.Path as Path | ||
| import qualified System.Path.PartClass as Path.PartClass | ||
| import Analysis.File as A | ||
| import Analysis.Reference as A | ||
| import Data.Aeson | ||
| import Source.Language as Language | ||
| import Source.Source as Source | ||
|
|
||
| -- | The source, path information, and language of a file read from disk. | ||
| data Blob = Blob | ||
|
|
@@ -25,27 +23,27 @@ data Blob = Blob | |
| instance FromJSON Blob where | ||
| parseJSON = withObject "Blob" $ \b -> do | ||
| src <- b .: "content" | ||
| Right pth <- fmap Path.parse (b .: "path") | ||
| pth <- b .: "path" | ||
|
Comment on lines
-28
to
+26
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simpler terms. |
||
| lang <- b .: "language" | ||
| let lang' = if knownLanguage lang then lang else Language.forPath pth | ||
| pure (fromSource (pth :: Path.AbsRelFile) lang' src) | ||
| pure (fromSource pth lang' src) | ||
|
|
||
|
|
||
| -- | Create a Blob from a provided path, language, and UTF-8 source. | ||
| -- The resulting Blob's span is taken from the 'totalSpan' of the source. | ||
| fromSource :: Path.PartClass.AbsRel ar => Path.File ar -> Language -> Source -> Blob | ||
| fromSource :: FilePath -> Language -> Source -> Blob | ||
|
Comment on lines
-36
to
+34
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simpler types. |
||
| fromSource filepath language source | ||
| = Blob source (A.File (A.Reference (Path.toAbsRel filepath) (totalSpan source)) language) | ||
| = Blob source (A.File (A.Reference filepath (totalSpan source)) language) | ||
|
|
||
| blobLanguage :: Blob -> Language | ||
| blobLanguage = A.fileBody . blobFile | ||
|
|
||
| blobPath :: Blob -> Path.AbsRelFile | ||
| blobPath :: Blob -> FilePath | ||
| blobPath = A.refPath . A.fileRef . blobFile | ||
|
|
||
| -- | Show FilePath for error or json outputs. | ||
| blobFilePath :: Blob -> String | ||
| blobFilePath = Path.toString . blobPath | ||
| blobFilePath = blobPath | ||
|
Comment on lines
-48
to
+46
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opted not to eliminate this in favour of |
||
|
|
||
| nullBlob :: Blob -> Bool | ||
| nullBlob = Source.null . blobSource | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,28 @@ | ||
| {-# LANGUAGE CPP, DisambiguateRecordFields, OverloadedStrings, TypeApplications, ImplicitParams #-} | ||
| {-# LANGUAGE CPP #-} | ||
| {-# LANGUAGE DisambiguateRecordFields #-} | ||
| {-# LANGUAGE ImplicitParams #-} | ||
| {-# LANGUAGE OverloadedStrings #-} | ||
| {-# LANGUAGE TypeApplications #-} | ||
| {-# OPTIONS_GHC -Wno-unused-imports #-} | ||
| module Main (main) where | ||
|
|
||
| import AST.TestHelpers | ||
| import AST.Unmarshal | ||
| import qualified Language.CodeQL.AST as CodeQL | ||
| import Language.CodeQL.Grammar | ||
| import qualified System.Path as Path | ||
| import Test.Tasty | ||
| import qualified System.Path.Fixture as Fixture | ||
| import Test.Tasty | ||
|
|
||
| main :: IO () | ||
| main = do | ||
| #if BAZEL_BUILD | ||
| rf <- Fixture.create | ||
| let ?project = Path.relDir "external/tree-sitter-ql" | ||
| let ?project = "external/tree-sitter-ql" | ||
|
Comment on lines
-17
to
+20
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We aren't currently building with bazel, but I did my best to keep these changes bazel-friendly at least. |
||
| ?runfiles = rf | ||
|
|
||
| let dirs = Fixture.absRelDir "test/corpus" | ||
| #else | ||
| dirs <- Path.absRel <$> CodeQL.getTestCorpusDir | ||
| dirs <- CodeQL.getTestCorpusDir | ||
| #endif | ||
| let parse = parseByteString @CodeQL.Ql @() tree_sitter_ql | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expect lots of this sort of thing due to autoformatter. Apologies.