haskell - 如何将依赖项集成到 Haskell 中的现有项目中?
问题描述
我目前正在尝试开始使用 Haskell,因为我想将Pandoc的部分代码库用于不同的项目。由于我是 Haskell 的新手,我需要适当的 IDE 功能,例如代码完成和跳转到定义 和 类型信息以及hover 上的文档。我选择了带有Haskell 扩展的VSCode来完成这项工作。现在我的问题来了:Pandoc 依赖于pandoc-types,它是代码的一个组成部分,我需要理解和修改它。但是使用ghc-option
"$everything": -haddock
(根据this应该是实现我的目标的正确方法)似乎没有给我正确的类型信息和悬停文档。由于我复制了整个仓库并且不打算从原始仓库中提取或推送,我想将代码添加pandoc-types
到主仓库中现有的 Haskell 代码中pandoc
。
所以我尝试的一部分是下载pandoc-types
将.hs
文件移动到相应的目录中pandoc
,将模块添加到.cabal
文件中,同时pandoc-<version>
从.cabal
文件和stack.yaml
. 但是我在构建时遇到的所有兼容性错误:
➜ pandoc git:(master) ✗ stack build
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for citeproc-0.1.0.1:
pandoc-types-1.17.6 from stack configuration does not match >=1.22 && <1.23 (latest matching version is 1.22)
needed due to pandoc-2.11.0.1 -> citeproc-0.1.0.1
In the dependencies for commonmark-pandoc-0.2.0.1:
pandoc-types-1.17.6 from stack configuration does not match >=1.21 && <1.23 (latest matching version is 1.22)
needed due to pandoc-2.11.0.1 -> commonmark-pandoc-0.2.0.1
In the dependencies for texmath-0.12.0.3:
pandoc-types-1.17.6 from stack configuration does not match >=1.20 && <1.23 (latest matching version is 1.22)
needed due to pandoc-2.11.0.1 -> texmath-0.12.0.3
Some different approaches to resolving this:
* Set 'allow-newer: true' in /Users/johannes/.stack/config.yaml to ignore all version constraints and build anyway.
* Recommended action: try adding the following to your extra-deps in /Users/johannes/Programmieren/GITGOV/Pandocs/pandoc/stack.yaml:
- pandoc-types-1.22@sha256:15512ce011555ee720820f11cac0598317293406da5812337cbb1550d144e3bd,4071
Plan construction failed.
如何将依赖项中的 repo 更改为代码库的一部分。我尝试了一些不同的方法,但似乎没有任何效果。我不太熟悉GHC
,stack
甚至cabal
是 Haskell 本身。还是有另一种方法来获取悬停工作的类型信息和文档?特别是作为一个 Haskell 初学者,我真的需要这个功能来正确掌握代码库。
也许也相关:
两个 repos 似乎都Paths_*.hs
在构建过程中生成文件。据我了解,它们还需要复制到这里src/
提到的目录中。
解决方案
根据使用的工具,有不同的方法来解决它。
如果stack
使用:
按照这个问题中接受的答案,我stack build
可以通过withpandoc-types
作为本地依赖项来编译代码。
如果cabal
使用:
与上面的解决方案一样,需要将本地依赖项添加到 repo 的根文件夹中。此外,应该将依赖cabal
文件的引用添加到cabal.project
该部分中的文件中packages:
,如下所示(这告诉 cabal 也编译该文件夹的内容):
packages: pandoc-types/pandoc-types.cabal pandoc.cabal
package pandoc
flags: +embed_data_files -trypandoc
ghc-options: -j +RTS -A64m -RTS
source-repository-package
type: git
location: https://github.com/jgm/citeproc
tag: 0.1.0.1
<projectname>.cabal
还需要删除版本限制中的依赖项。所以文件从这个改变:
library
build-depends: pandoc-types >= 1.22 && < 1.23
...对此:
library
build-depends: pandoc-types
现在我的代码用cabal build
.
然而,我的问题的一部分仍然存在。当遵循这两种方法时,VSCode 中的 Haskell 扩展仍然不能正确地自动完成。使用该stack
方法会给出类似的警告和类似的A do-notation statement discarded a result of type ...
错误Could not deduce ... arising from a use of ...
。第一个警告实际上应该已经被文件中的标志所抑制(-fno-warn-unused-do-bind
假设这是扩展读取的内容以打印警告/错误)。所以我不知道是什么导致了这些错误。在构建过程中从 Hackage 下载 repo 时,它们不存在。关于这个问题,我可能需要就堆栈溢出提出另一个问题。ghc-options
pandoc.cabal
无论如何,既然标题中的问题得到了回答,我希望这在将来的某个时候对某人有所帮助。
推荐阅读
- javascript - 正则表达式替换重复模式
- java - 使用 Jackson 将大量 JSON 响应反序列化为 POJO 的最有效方法是什么?
- visual-studio - 调试期间如何在每次更改时将文件复制到输出目录
- sql - 在 SQL 中为表中的一组行偏移日期时间数据
- go - 这个 rot13 密码有什么问题?
- node.js - 在本地主机之外的 AWS Lightsail 中访问 NodeJS 演示应用程序
- jenkins - Jmeter jenkins 不存储过去的构建结果
- android - 错误:不兼容的类型:字符串无法转换为 JSONArray
- .net - 即使在 linux/mac/windows 上,如何让 NuGet 包在安装时运行命令/逻辑?
- r - 如何在 forest_model 中将换行符添加到因子级别