8000 Drop pathtype, part one by robrix · Pull Request #687 · github/semantic · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Drop pathtype, part one #687

Merged
merged 7 commits into from
Jul 18, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
cabal v2-run --project-file=cabal.project.ci semantic-tags:test
cabal v2-run --project-file=cabal.project.ci semantic-tsx:test
cabal v2-run --project-file=cabal.project.ci semantic-typescript:test
cabal v2-run --project-file=cabal.project.ci semantic-source:test
cd semantic-source && cabal v2-run --project-file=cabal.project.ci semantic-source:test
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're excluding this from the top-level project now, so we cd in first.


- name: Write out cache
run: ./cabal-cache sync-to-archive --threads=2 --archive-uri=dist-cache
1 change: 0 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ packages: semantic
semantic-ruby
semantic-rust
semantic-scope-graph
semantic-source
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, and in cabal.project.ci, we remove semantic-source from the top-level project, ensuring that it'll be fetched from hackage. This makes it possible to factor out PRs like this one, at the cost of making it less convenient to change things across both semantic (or any other local package) and semantic-source.

For this PR I think that's worth it; for the next one I might end up reinstating this. But I wanted to factor the PRs out to begin with to limit scope and to be sure we're handling versioning appropriately.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the cost of making it less convenient to change things across both

To clarify, this means that the process would be to merge the PR that touches the "downstream" package, cut a new release and deploy it to hackage, and then open the PR in the "upstream" package?

(Not meaning to suggest a different approach, just making sure I understand how the process would be impacted.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Or more precisely: reintroduce semantic-source as a local package (i.e. add it back to this list) without committing that change, and then do the hackage dance after the fact.

I think the real moral here is that we probably released semantic-source to hackage too early. Lesson learned.

semantic-tags
semantic-tsx
semantic-typescript
4 changes: 0 additions & 4 deletions cabal.project.ci
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ packages: semantic
semantic-ruby
semantic-rust
semantic-scope-graph
semantic-source
semantic-tags
semantic-tsx
semantic-typescript
Expand Down Expand Up @@ -54,9 +53,6 @@ package semantic-ruby
package semantic-scope-graph
ghc-options: -Werror

package semantic-source
ghc-options: -Werror

package semantic-tags
ghc-options: -Werror

Expand Down
6 changes: 6 additions & 0 deletions semantic-source/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.2.0.0

- Finds languages for `FilePath`s.
- Drops dependency on `pathtype`.


# 0.1.0.2

- Support ghc 9.2.
Expand Down
3 changes: 1 addition & 2 deletions semantic-source/semantic-source.cabal
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cabal-version: 2.4

name: semantic-source
version: 0.1.0.2
version: 0.2.0.0
synopsis: Types and functionality for working with source code
description: Types and functionality for working with source code (program text).
homepage: https://github.com/github/semantic/tree/master/semantic-source#readme
Expand Down Expand Up @@ -64,7 +64,6 @@ library
, containers ^>= 0.6.2
, hashable >= 1.2.7 && < 1.4
, lingo ^>= 0.5.0.3
, pathtype ^>= 0.8.1
, semilattices ^>= 0.0.0.3
, text ^>= 1.2.3.2
hs-source-dirs: src
Expand Down
54 changes: 26 additions & 28 deletions semantic-source/src/Source/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import qualified Data.Languages as Lingo
import qualified Data.Map.Strict as Map
import qualified Data.Text as T
import GHC.Generics (Generic)
import qualified System.Path as Path
import qualified System.Path.PartClass as Path.PartClass

-- | The various languages we support.
data Language
Expand Down Expand Up @@ -96,47 +94,47 @@ knownLanguage = (/= Unknown)
extensionsForLanguage :: Language -> [String]
extensionsForLanguage language = fmap T.unpack (maybe mempty Lingo.languageExtensions (Map.lookup (languageToText language) Lingo.languages))

forPath :: Path.PartClass.AbsRel ar => Path.File ar -> Language
forPath :: FilePath -> Language
forPath path =
let spurious lang = lang `elem` [ "Hack" -- .php files
, "GCC Machine Description" -- .md files
, "XML" -- .tsx files
]
allResults = Lingo.languageName <$> Lingo.languagesForPath (Path.toString path)
allResults = Lingo.languageName <$> Lingo.languagesForPath path
Comment on lines -99 to +103
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only real code change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥲

in case filter (not . spurious) allResults of
[result] -> textToLanguage result
_ -> Unknown

languageToText :: Language -> T.Text
languageToText = \case
Unknown -> "Unknown"
CodeQL -> "CodeQL"
Go -> "Go"
Haskell -> "Haskell"
Java -> "Java"
Unknown -> "Unknown"
CodeQL -> "CodeQL"
Go -> "Go"
Haskell -> "Haskell"
Java -> "Java"
JavaScript -> "JavaScript"
JSON -> "JSON"
JSX -> "JSX"
Markdown -> "Markdown"
PHP -> "PHP"
Python -> "Python"
Ruby -> "Ruby"
JSON -> "JSON"
JSX -> "JSX"
Markdown -> "Markdown"
PHP -> "PHP"
Python -> "Python"
Ruby -> "Ruby"
TypeScript -> "TypeScript"
TSX -> "TSX"
TSX -> "TSX"

textToLanguage :: T.Text -> Language
textToLanguage = \case
"CodeQL" -> CodeQL
"Go" -> Go
"Haskell" -> Haskell
"Java" -> Java
"CodeQL" -> CodeQL
"Go" -> Go
"Haskell" -> Haskell
"Java" -> Java
"JavaScript" -> JavaScript
"JSON" -> JSON
"JSX" -> JSX
"Markdown" -> Markdown
"PHP" -> PHP
"Python" -> Python
"Ruby" -> Ruby
"JSON" -> JSON
"JSX" -> JSX
"Markdown" -> Markdown
"PHP" -> PHP
"Python" -> Python
"Ruby" -> Ruby
"TypeScript" -> TypeScript
"TSX" -> TSX
_ -> Unknown
"TSX" -> TSX
_ -> Unknown
0