kowainik / extensions Goto Github PK
View Code? Open in Web Editor NEW👅 Parse Haskell Language Extensions
License: Mozilla Public License 2.0
👅 Parse Haskell Language Extensions
License: Mozilla Public License 2.0
I hit this problem when trying to use the getPackageExtentions
function pointing to a cabal file that is not my current directory, but I can also exhibit it using the CLI:
…/ext-stats $ extensions --cabal-file-path hackage/3dmodels-0.3.0/*.cabal
ⓘ Extensions for each module combined with 'default-extensions'
…/ext-stats $ cd hackage/3dmodels-0.3.0
…/hackage/3dmodels-0.3.0 $ extensions --cabal-file-path *.cabal
ⓘ Extensions for each module combined with 'default-extensions'
Graphics/Model/DirectX.hs
OverloadedStrings
RecordWildCards
Graphics/Model/MikuMikuDance.hs
Graphics/Model/MikuMikuDance/Loader.hs
OverloadedStrings
Graphics/Model/MikuMikuDance/Types.hs
Graphics/Model/Obj.hs
OverloadedStrings
TupleSections
I would expect it to find the source code relative to the given cabal file.
Also, as a feature request, it might be nice if I can just pass a path to a directory, and it will use the (existing) logic to find the .cabal
file therein.
Created a separate issue for GHC 9.0 (#73) and GHC 9.2. We use GHC API and Cabal API so some amount of non-trivial changes is required to make this library support newer GHC versions.
Sometimes it's helpful to have a function:
isEnabled :: Extension -> Set OnOffExtension -> Bool
That checks whether there's On
for the particular given extension.
Does it sound useful? For now, I propose not to think about the fact that some extensions can imply other extensions, this is another whole story..
They are not constructors of the Extension
type, but they are specified as {-# LANGUAGE #-}
pragmas.
Could return the map of stanzas' directory to list of enabled extensions
Hi, there have been a few fixes on the main git branch, that have not yet been released in a version on Hackage. These would be useful to have
Thank you
https://github.com/actions/setup-haskell (unmaintained) should be replaced with https://github.com/haskell/actions/tree/main/setup.
After #45 we have showOnOffExtension
to pretty-print OnOffExtension
. In Extensions.Parser
we have readOnOffExtenion
function. We can do the following:
readOnOffExtenion
to Extensions.OnOff
.showOnOffExtension
and readOnOffExtension
.We need to add tests both to Cabal
, Parser
and combined functions that should contain SafeHaskell extensions. Specifically in each we need to check:
Just
extensionJust
extensionSafeExtensionsConflict
)No
Safe Haskell Extension doesn't parsedefault-extensions
results to Just
extension, hspec-hedgehog ^>= 0.0.1
Can this be changed to support 0.1.*
? https://hackage.haskell.org/package/hspec-hedgehog
Thank you
Blocked on
Language extensions Safe
, Unsafe
and Trustworthy
are special, because:
Extension
. Even though they are specified using the {-# LANGUAGE #-}
pragma, they are not recognized as extensions. They are stored in DynFlags
as the safeHaskell
field of type SafeHaskellMode
.No
scheme of disabling/enabling extensions.It would be nice to report these extensions as used, but it's not clear how to model them as data types. Current behaviour: they are ignored during parsing.
Currently extensions
works only with Haskell2010
New constructor like ModuleDoesn'tExist FilePath
in the ExtensionsError
data type.
Some Haskell packages don't have the hs-source-dirs
field in their .cabal
files. In such packages, modules are placed directly on top-level. One example of such package:
So instead of src/Data/ByteString/Base64.hs
file, you have simply Data/ByteString/Base64.hs
. Current implementation of parseCabalExtensions
will return empty map in such cases. But I guess it needs to be patched. I see packages with such structure from time to time in the Haskell ecosystem.
CUSKs was added in 8.10.1 and enabled by default.
References:
.. extension:: CUSKs
:shortdesc: Enable detection of complete user-supplied kind signatures.
:since: 8.10.1
:status: Included in :extension:`Haskell98`, :extension:`Haskell2010`
. extension:: Haskell2010
:shortdesc: Use the Haskell 2010 language variant.
Compile Haskell 2010 language variant. Enables the
following language extensions:
.. hlist::
* :extension:`CUSKs`
* :extension:`DatatypeContexts`
* :extension:`DoAndIfThenElse`
* :extension:`EmptyDataDecls`
* :extension:`FieldSelectors`
* :extension:`ForeignFunctionInterface`
* :extension:`ImplicitPrelude`
* :extension:`MonomorphismRestriction`
* :extension:`PatternGuards`
* :extension:`RelaxedPolyRec`
* :extension:`StarIsType`
* :extension:`TraditionalRecordSyntax`
We could achieve this by making the toGhcExtension
case
end with a wildcard pattern mapping to Nothing
.
On means that extension is enabled. Off — it has No
prefixed and disabled.
Discovered while working on this HLS PR: haskell/haskell-language-server#4023, related to these issues:
Stan, via extensions
, appears to be prepending the hs-source-dirs
from the .cabal
file verbatim onto the module name. This means if the .cabal
file uses /
as its path separators, the returned file paths (and associated extension map) will be broken for Windows users.
For example, if your cabal file has:
hs-source-dirs: extension-tests/language-pragma
... then the resulting Map key winds up looking like this for Windows users:
extension-tests/language-pragma\\LanguagePragmaTest.hs
This results in Map lookups missing, which in turn results in Stan not recognizing any of a project's enabled extensions. (One of the causes for the above-mentioned HLS issue.)
From a quick look, I think the issue might be happening around here somewhere. (I do see some Cabal version checks, not sure how those play into this...)
It seems that extensions
can be thown off by comments before the pragma list, as in these files:
(small selection… I am running your tool on all hackage package’s latest versions, so I can provide more.)
Currently it's not easy to test cabal parsing functions only on cabal-files, since the function requires IO
to check whether the module actually exist. I think cabal parsing functions can be patched, and I see a few ways to do this.
Monad m => FilePath -> m Bool
that checks whether the module exist. So in IO
we will pass the doesFileExist
function, and in tests we will pass const $ pure True
(or something more sophisticated for better testing).hs-source-dirs
using a package like dir-traverse
at the beginning, and then instead of checking whether the file exist, we can just check whether it's in the given list.Option 1 is easier to implement and won't require to have a separate dependency. But maybe Option 2 sounds better in theory. Also, maybe I'm missing something else...
@vrom911 What do you think?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.