Closed rikvdkleij closed 6 years ago
For now you can't. But it's not hard to implement.
You can also inspect sql db (if specified --db
arg on hsdev start) with sqlite3
See hsdev.sql for schema
All resolved names are saved in names
table.
Local identifiers (not top-level) will refer to same definition position (def_line
, def_column
)
For example, finding usages of ploaded
binding in module HsDev.Database.Update
select n.name, n.line, n.column
from
names as n,
(select
ns.module_id, ns.def_line, ns.def_column
from names as ns
where
ns.module_id = (select id from modules where file like '%\Update.hs') and
ns.line == 215 and
ns.name = 'ploaded'
) as def
where
n.module_id = def.module_id
and n.def_line = def.def_line
and n.def_column = def.def_column;
Result:
ploaded|214|3
ploaded|215|18
ploaded|233|14
I've changed usages
in hsdev-0.3.0.1. It now accepts location in file, so it should return local symbols too.
Thanks! I will try it later.
I was travelling for a few days. Finally had some time to test. This new feature works great. Thanks!
But while experimenting with hsdev, I could not get any info about identifiers which are imported. I have scanned the .stack-work
but no command (symbol, whois, whoat, usages) gives info about imported identifiers.
Also sometimes sometimes command hangs while hsdev is not using CPU.
Scan command I use:
hsdev scan --project . --cabal --infer --sandbox ./.stack-work
Could you describe steps to reproduce?
I have project:
stacktest
.stack-work
dist
install
9b83077b
pkgdb
...
src
Main.hs
StackTest.hs
Setup.hs
stack.yaml
stacktest.cabal
hsdev commands:
> hsdev start
> hsdev scan --project stacktest --sandbox stacktest\.stack-work
...
> hsdev whoat 13 2 -f .\stacktest\src\Main.hs | json | % { $_.id.module.name + '.' + $_.id.name + ' :: ' + $_.info.type + ' -- from ' + $_.id.module.location.package }
Formatting.Internal.fprint :: Format (IO ()) a -> a -- from formatting-6.2.5
I have this problem with this project: https://github.com/rikvdkleij/quicksort
I notice a difference in the structure of my .stack-work
directory. I have
.stack-work
│ ├── dist
│ │ └── x86_64-osx
│ │ └── Cabal-2.0.1.0
│ │ ├── build
│ │ ├── package.conf.inplace
│ │ ├── setup-config
│ │ ├── stack-build-cache
│ │ ├── stack-cabal-mod
│ │ └── stack-config-cache
│ ├── install
│ │ └── x86_64-osx
│ │ └── lts-10.0
│ │ └── 8.2.2
As you see I'm on OSX and using Stack with LTS 10.0 to build this project.
hsdev whoat 3 15 -f src/Quicksort.hs
In general it works. For example
> hsdev whoat 6 45 -f src\Quicksort.hs | json | % { $_.id.module.name + '.' + $_.id.name + ' :: ' + $_.info.type }
GHC.Base.++ :: [a] -> [a] -> [a]
Also, note, that lines and columns starts from 1.
But there was a bug, thanks.
hsdev looked for resolved_name
symbol in resolved_module
, but restricts modules to project-dependent (i.e. modules from dependent packages)
it's incorrect, because resolved_module
is module where symbol defined, but it can be exported from other package
In this case Ord
is defined in ghc-prim
package, but reexported from Data.Ord
from base
package.
But there's no need to lookup for symbol at all, we can get symbol_id
from scopes
tables (symbols in scope of module)
Added symbol_id
column to names
table - resolved symbol id, and rewritten commands whoat
and usages
to use it (https://github.com/mvoidex/hsdev/commit/e38abd713e7ad697b95681c472f25af3cdb514e7)
Uploaded hsdev-0.3.0.2
Sorry to say but it still does not work. I have rebuilt hsdev
from source.
Same problem and I'm using the same project and commands.
Could you describe steps to reproduce?
Here's mine:
quicksort> stack build --only-configure
quicksort> hsdev start --db hsdev.db
quicksort> hsdev scan --sandbox .stack-work --project .
...
quicksort> hsdev whoat 4 15 -f src\Quicksort.hs
[{"id":{"name":"Ord","module":{"location":...
quicksort> hsdev usages 4 1 -f src\Quicksort.hs
[{"at":{"line":4,"column":1},"symbol":{"pos":{"line":5,"column":1},"id":{"name":"quicksort"...
I did the same steps as you did and
hsdev whoat 4 15 -f src/Quicksort.hs
returns empty array.
hsdev usages 4 1 -f src\Quicksort.hs
works.
Could you start hsdev with log: hsdev start --log hsdev.log --log-level trace
and copy here logs?
2018-01-23 20:48:28 +0100 TRACE :> waiting for starting accept thread...
2018-01-23 20:48:28 +0100 TRACE :listener> accepting connection...
2018-01-23 20:48:28 +0100 INFO :> Server started at port 4567
2018-01-23 20:48:28 +0100 TRACE :> waiting for accept thread...
2018-01-23 20:48:34 +0100 TRACE :listener> accepted 127.0.0.1:50384
2018-01-23 20:48:34 +0100 TRACE :listener> accepting connection...
2018-01-23 20:48:34 +0100 INFO :127.0.0.1:50384> connected
2018-01-23 20:48:34 +0100 TRACE :127.0.0.1:50384> received >> {"command":"scan","cabal":false,"current-directory":"/Users/rik/projects/quicksort","infer":false,"silent":false,"ghc-opts":[],"no-file":false,"files":[],"id":null,"sandboxes":[".stack-work"],"docs":false,"timeout":0,"projects":["."],"paths":[]}
2018-01-23 20:48:34 +0100 TRACE :127.0.0.1:50384/127.0.0.1:50384/req/_> requested >> {"command":"scan","cabal":false,"infer":false,"ghc-opts":[],"files":[],"sandboxes":[".stack-work"],"docs":false,"projects":["."],"paths":[]}
2018-01-23 20:48:34 +0100 TRACE sqlite:update> entering sqlite transaction
2018-01-23 20:48:34 +0100 DEBUG sqlite:update> updating sql database
2018-01-23 20:48:34 +0100 TRACE :ghc> session: tmp global-db
2018-01-23 20:48:34 +0100 TRACE :ghc> setting flags: -no-user-package-db
2018-01-23 20:48:34 +0100 TRACE :ghc> invoking stack: /usr/local/bin/stack --compiler ghc-8.2.2 --arch x86_64 build --only-dependencies
2018-01-23 20:48:34 +0100 TRACE :ghc> session: tmp global-db
2018-01-23 20:48:34 +0100 TRACE :ghc> setting flags: -no-user-package-db
2018-01-23 20:48:34 +0100 TRACE :ghc> invoking stack: /usr/local/bin/stack --compiler ghc-8.2.2 --arch x86_64 build --only-configure
2018-01-23 20:48:35 +0100 TRACE :ghc> session: tmp global-db
2018-01-23 20:48:35 +0100 TRACE :ghc> setting flags: -no-user-package-db
2018-01-23 20:48:35 +0100 TRACE :ghc> invoking stack: /usr/local/bin/stack --compiler ghc-8.2.2 --arch x86_64 path
2018-01-23 20:48:36 +0100 TRACE :update/sandbox/task/package-db-stack> package-db-stack state: 3657 modules
2018-01-23 20:48:36 +0100 TRACE :ghc> killing session: tmp global-db
2018-01-23 20:48:36 +0100 TRACE :ghc> session: tmp global-db/package-db /Users/rik/.stack/snapshots/x86_64-osx/lts-10.0/8.2.2/pkgdb/package-db /Users/rik/projects/quicksort/.stack-work/install/x86_64-osx/lts-10.0/8.2.2/pkgdb
2018-01-23 20:48:36 +0100 TRACE :ghc> setting flags: -package Cabal-2.0.1.0 -package array-0.5.2.0 -package base-4.10.1.0 -package binary-0.8.5.1 -package bytestring-0.10.8.2 -package containers-0.5.10.2 -package deepseq-1.4.3.0 -package directory-1.3.0.2 -package filepath-1.4.1.2 -package ghc-8.2.2 -package ghc-boot-8.2.2 -package ghc-boot-th-8.2.2 -package ghc-compact-0.1.0.0 -package ghc-prim-0.5.1.1 -package ghci-8.2.2 -package haskeline-0.7.4.0 -package hoopl-3.10.2.2 -package hpc-0.6.0.3 -package integer-gmp-1.0.1.0 -package pretty-1.1.3.3 -package process-1.6.1.0 -package rts-1.0 -package template-haskell-2.12.0.0 -package terminfo-0.4.1.0 -package time-1.8.0.2 -package transformers-0.5.2.0 -package unix-2.7.2.2 -package xhtml-3000.2.2 -package Cabal-2.0.1.1 -package Decimal-0.4.2 -package Diff-0.3.4 -package HUnit-1.6.0.0 -package ListLike-4.5.1 -package MonadRandom-0.5.1 -package QuickCheck-2.10.1 -package StateVar-1.1.0.4 -package adjunctions-4.3 -package aeson-1.2.3.0 -package aeson-compat-0.3.7.1 -package ansi-terminal-0.7.1.1 -package ansi-wl-pprint-0.6.8.1 -package appar-0.1.4 -package asn1-encoding-0.9.5 -package asn1-parse-0.9.4 -package asn1-types-0.3.2 -package async-2.1.1.1 -package attoparsec-0.13.2.0 -package attoparsec-iso8601-1.0.0.0 -package auto-update-0.1.4 -package base-compat-0.9.3 -package base-orphans-0.6 -package base64-bytestring-1.0.0.1 -package basement-0.0.4 -package bifunctors-5.5 -package blaze-builder-0.4.0.2 -package blaze-html-0.9.0.1 -package blaze-markup-0.8.0.0 -package brick-0.29.1 -package byteable-0.1.1 -package byteorder-1.0.4 -package bytestring-builder-0.10.8.1.0 -package cabal-doctest-1.0.4 -package call-stack-0.1.0 -package case-insensitive-1.2.0.10 -package cereal-0.5.4.0 -package cipher-aes-0.2.11 -package clientsession-0.9.1.2 -package clock-0.7.2 -package cmdargs-0.10.18 -package colour-2.3.4 -package comonad-5.0.2 -package conduit-1.2.12.1 -package conduit-extra-1.2.2 -package config-ini-0.2.1.1 -package connection-0.2.8 -package contravariant-1.4 -package control-monad-free-0.6.1 -package cookie-0.4.3 -package cpphs-1.20.8 -package cprng-aes-0.6.1 -package crypto-api-0.13.2 -package crypto-cipher-types-0.0.9 -package crypto-random-0.0.9 -package cryptonite-0.24 -package cryptonite-conduit-0.2.2 -package css-text-0.1.2.2 -package csv-0.1.2 -package data-clist-0.1.2.0 -package data-default-0.7.1.1 -package data-default-class-0.1.2.0 -package data-default-instances-containers-0.0.1 -package data-default-instances-dlist-0.0.1 -package data-default-instances-old-locale-0.0.1 -package deepseq-generics-0.2.0.0 -package distributive-0.5.3 -package dlist-0.8.0.3 -package docopt-0.7.0.5 -package easy-file-0.2.1 -package either-4.5 -package email-validate-2.3.2 -package entropy-0.3.8 -package exceptions-0.8.3 -package extra-1.6.2 -package fail-4.9.0.0 -package fast-logger-2.4.10 -package file-embed-0.0.10.1 -package fmlist-0.9 -package foundation-0.0.17 -package free-4.12.4 -package fsnotify-0.2.1.1 -package generic-deriving-1.12 -package generics-sop-0.3.1.0 -package ghc-paths-0.1.0.9 -package hashable-1.2.6.1 -package hashtables-1.2.2.1 -package haskeline-0.7.4.2 -package haskell-lexer-1.0.1 -package haskell-src-exts-1.19.1 -package haskell-src-exts-util-0.2.1.2 -package haskell-src-meta-0.8.0.1 -package here-1.2.11 -package hfsevents-0.1.6 -package hjsmin-0.2.0.2 -package hlint-2.0.11 -package hoogle-5.0.14 -package hourglass-0.2.10 -package hscolour-1.24.2 -package hspec-2.4.4 -package hspec-core-2.4.4 -package hspec-discover-2.4.4 -package hspec-expectations-0.8.2 -package html-1.0.1.2 -package http-api-data-0.3.7.1 -package http-client-0.5.7.1 -package http-client-tls-0.3.5.1 -package http-conduit-2.2.4 -package http-date-0.0.6.1 -package http-media-0.7.1.1 -package http-types-0.9.1 -package http2-1.6.3 -package insert-ordered-containers-0.2.1.0 -package integer-logarithms-1.0.2 -package iproute-1.7.1 -package js-flot-0.8.3 -package js-jquery-3.2.1 -package json-0.9.1 -package kan-extensions-5.0.2 -package language-javascript-0.6.0.10 -package lens-4.15.4 -package lifted-base-0.2.3.11 -package math-functions-0.2.1.0 -package megaparsec-6.3.0 -package memory-0.14.10 -package microlens-0.4.8.1 -package microlens-ghc-0.4.8.0 -package microlens-mtl-0.1.11.0 -package microlens-platform-0.3.9.0 -package microlens-th-0.4.1.1 -package mime-types-0.1.0.7 -package mmap-0.5.9 -package mmorph-1.1.0 -package monad-control-1.0.2.2 -package monad-logger-0.3.26 -package monad-loops-0.4.3 -package mtl-2.2.1 -package mtl-compat-0.2.1.3 -package mwc-random-0.13.6.0 -package natural-transformation-0.4 -package network-2.6.3.2 -package network-uri-2.6.1.0 -package old-locale-1.0.0.7 -package old-time-1.1.0.3 -package optparse-applicative-0.14.0.0 -package parallel-3.2.1.1 -package parsec-3.1.11 -package parser-combinators-0.2.1 -package path-pieces-0.2.1 -package pem-0.2.2 -package persistent-2.7.1 -package persistent-template-2.5.3 -package polyparse-1.12 -package prelude-extras-0.4.0.3 -package pretty-show-1.6.15 -package primitive-0.6.2.0 -package process-extras-0.7.2 -package profunctors-5.2.1 -package protolude-0.2 -package psqueues-0.2.4.0 -package quickcheck-io-0.2.0 -package random-1.1 -package refact-0.3.0.2 -package reflection-2.1.2 -package regex-base-0.93.2 -package regex-compat-0.95.1 -package regex-posix-0.95.2 -package regex-tdfa-1.2.2 -package resource-pool-0.2.3.2 -package resourcet-1.1.10 -package safe-0.3.15 -package scientific-0.3.5.2 -package securemem-0.1.9 -package semigroupoids-5.2.1 -package semigroups-0.18.3 -package servant-0.11 -package servant-server-0.11.0.1 -package servant-swagger-1.1.4 -package setenv-0.1.1.3 -package shakespeare-2.0.14.1 -package silently-1.2.5 -package simple-sendfile-0.2.26 -package skein-1.0.9.4 -package socks-0.5.5 -package split-0.2.3.2 -package stm-2.4.4.1 -package stm-chans-3.0.0.4 -package storable-record-0.0.3.1 -package storable-tuple-0.0.3.3 -package streaming-commons-0.1.18 -package string-conversions-0.4.0.1 -package stringsearch-0.3.6.6 -package swagger2-2.2 -package syb-0.7 -package system-filepath-0.4.13.4 -package tabular-0.2.2.7 -package tagged-0.8.5 -package tagsoup-0.14.2 -package tar-0.5.0.3 -package temporary-1.2.1.1 -package text-1.2.2.2 -package text-zipper-0.10.1 -package tf-random-0.5 -package th-abstraction-0.2.6.0 -package th-expand-syns-0.4.3.0 -package th-lift-0.7.7 -package th-lift-instances-0.1.11 -package th-orphans-0.13.4 -package th-reify-many-0.1.8 -package time-locale-compat-0.1.1.3 -package tls-1.4.0 -package tls-session-manager-0.0.0.2 -package transformers-base-0.4.4 -package transformers-compat-0.5.1.4 -package typed-process-0.2.0.0 -package uglymemo-0.1.0.1 -package uniplate-1.6.12 -package unix-compat-0.5.0.1 -package unix-time-0.3.7 -package unliftio-core-0.1.0.0 -package unordered-containers-0.2.8.0 -package uri-bytestring-0.3.0.1 -package utf8-string-1.0.1.1 -package utility-ht-0.0.14 -package uuid-types-1.0.3 -package vault-0.3.0.7 -package vector-0.12.0.1 -package vector-th-unbox-0.2.1.6 -package void-0.7.2 -package vty-5.19 -package wai-3.2.1.1 -package wai-app-static-3.1.6.1 -package wai-extra-3.0.20.2 -package wai-handler-launch-3.0.2.3 -package wai-logger-2.3.0 -package warp-3.2.13 -package warp-tls-3.2.4 -package wizards-1.0.2 -package word-wrap-0.4.1 -package word8-0.1.3 -package x509-1.7.2 -package x509-store-1.6.5 -package x509-system-1.6.6 -package x509-validation-1.6.9 -package xss-sanitize-0.3.5.7 -package yaml-0.8.25 -package yesod-1.4.5 -package yesod-core-1.4.37.2 -package yesod-form-1.4.16 -package yesod-persistent-1.4.3 -package yesod-static-1.5.3.1 -package zlib-0.6.1.2
2018-01-23 20:48:36 +0100 TRACE :update/sandbox/task/package-db-stack> 1744 modules found
2018-01-23 20:48:36 +0100 TRACE :ghc> session: tmp global-db/package-db /Users/rik/.stack/snapshots/x86_64-osx/lts-10.0/8.2.2/pkgdb/package-db /Users/rik/projects/quicksort/.stack-work/install/x86_64-osx/lts-10.0/8.2.2/pkgdb
2018-01-23 20:48:36 +0100 TRACE :ghc> setting flags:
2018-01-23 20:48:43 +0100 TRACE :update/sandbox/task/package-db-stack/scan> scanned 1732 modules
2018-01-23 20:48:48 +0100 TRACE sqlite:update/update/sandbox/task/package-db-stack/scan/update-package-db> update package-db: global-db
2018-01-23 20:48:48 +0100 TRACE sqlite:update/update/sandbox/task/package-db-stack/scan/update-package-db> update package-db: package-db /Users/rik/.stack/snapshots/x86_64-osx/lts-10.0/8.2.2/pkgdb
2018-01-23 20:48:48 +0100 TRACE sqlite:update/update/sandbox/task/package-db-stack/scan/update-package-db> update package-db: package-db /Users/rik/projects/quicksort/.stack-work/install/x86_64-osx/lts-10.0/8.2.2/pkgdb
2018-01-23 20:48:48 +0100 TRACE :ghc> killing session: tmp global-db/package-db /Users/rik/.stack/snapshots/x86_64-osx/lts-10.0/8.2.2/pkgdb/package-db /Users/rik/projects/quicksort/.stack-work/install/x86_64-osx/lts-10.0/8.2.2/pkgdb
2018-01-23 20:48:48 +0100 TRACE :ghc> session: haddock global-db/package-db /Users/rik/.stack/snapshots/x86_64-osx/lts-10.0/8.2.2/pkgdb/package-db /Users/rik/projects/quicksort/.stack-work/install/x86_64-osx/lts-10.0/8.2.2/pkgdb
2018-01-23 20:48:48 +0100 TRACE :ghc> setting flags:
2018-01-23 20:48:49 +0100 TRACE :update/sandbox/task/package-db-stack/scan/docs> docs scanned: 280 packages, 1274 modules total
2018-01-23 20:48:49 +0100 TRACE :update/sandbox/task/package-db-stack/scan/docs> docs set
2018-01-23 20:48:49 +0100 DEBUG sqlite:update> sql database updated
2018-01-23 20:48:49 +0100 DEBUG :update> updated 1732 modules
2018-01-23 20:48:49 +0100 TRACE :update/task/files> scanning 0 files
2018-01-23 20:48:49 +0100 TRACE sqlite:update> entering sqlite transaction
2018-01-23 20:48:49 +0100 DEBUG sqlite:update> updating sql database
2018-01-23 20:48:49 +0100 TRACE :update/task/files/scan> dependent modules: 0
2018-01-23 20:48:49 +0100 DEBUG sqlite:update> sql database updated
2018-01-23 20:48:49 +0100 DEBUG :update> updated 0 modules
2018-01-23 20:48:49 +0100 TRACE sqlite:update> entering sqlite transaction
2018-01-23 20:48:49 +0100 DEBUG sqlite:update> updating sql database
2018-01-23 20:48:49 +0100 TRACE :ghc> session: tmp global-db
2018-01-23 20:48:49 +0100 TRACE :ghc> setting flags: -no-user-package-db
2018-01-23 20:48:49 +0100 TRACE :ghc> invoking stack: /usr/local/bin/stack --compiler ghc-8.2.2 --arch x86_64 path
2018-01-23 20:48:49 +0100 TRACE sqlite:update/update/task/project/task/scan-project-file/update-project> update project: quicksort
2018-01-23 20:48:49 +0100 TRACE :ghc> session: tmp global-db
2018-01-23 20:48:49 +0100 TRACE :ghc> setting flags: -no-user-package-db
2018-01-23 20:48:49 +0100 TRACE :ghc> invoking stack: /usr/local/bin/stack --compiler ghc-8.2.2 --arch x86_64 path
2018-01-23 20:48:49 +0100 TRACE :ghc> killing session: tmp global-db
2018-01-23 20:48:49 +0100 TRACE :ghc> session: tmp global-db/package-db /Users/rik/.stack/snapshots/x86_64-osx/lts-10.0/8.2.2/pkgdb/package-db /Users/rik/projects/quicksort/.stack-work/install/x86_64-osx/lts-10.0/8.2.2/pkgdb
2018-01-23 20:48:50 +0100 TRACE :ghc> setting flags:
2018-01-23 20:48:50 +0100 TRACE :ghc> killing session: tmp global-db/package-db /Users/rik/.stack/snapshots/x86_64-osx/lts-10.0/8.2.2/pkgdb/package-db /Users/rik/projects/quicksort/.stack-work/install/x86_64-osx/lts-10.0/8.2.2/pkgdb
2018-01-23 20:48:50 +0100 TRACE :ghc> session: tmp global-db
2018-01-23 20:48:50 +0100 TRACE :ghc> setting flags: -no-user-package-db
2018-01-23 20:48:50 +0100 TRACE :ghc> invoking stack: /usr/local/bin/stack --compiler ghc-8.2.2 --arch x86_64 path
2018-01-23 20:48:50 +0100 TRACE sqlite:update/update/task/project/scan/scan-modules/update-project> update project: quicksort
2018-01-23 20:48:50 +0100 ERROR :update/task/project/scan/scan-modules/task> Scope leaves with exception: failed to inspect: Parsing module head and imports results in empty module name, file /Users/rik/projects/quicksort/test/Spec.hs
CallStack (from HasCallStack):
onError, called at src/System/Log/Simple/Monad.hs:104:36 in simple-log-0.9.3-k2D7B3DBfeFhISQLkQoVj:System.Log.Simple.Monad
2018-01-23 20:48:50 +0100 TRACE :update/task/project/scan/scan-modules> resolving environment: 153 modules
2018-01-23 20:48:50 +0100 DEBUG sqlite:update> sql database updated
2018-01-23 20:48:50 +0100 DEBUG :update> updated 7 modules
2018-01-23 20:48:50 +0100 TRACE :127.0.0.1:50384/127.0.0.1:50384/req/_> responsed << {"result":[]}
2018-01-23 20:48:50 +0100 INFO :127.0.0.1:50384> disconnected
2018-01-23 20:48:59 +0100 TRACE :listener> accepted 127.0.0.1:50386
2018-01-23 20:48:59 +0100 TRACE :listener> accepting connection...
2018-01-23 20:48:59 +0100 INFO :127.0.0.1:50386> connected
2018-01-23 20:48:59 +0100 TRACE :127.0.0.1:50386> received >> {"command":"whoat","current-directory":"/Users/rik/projects/quicksort","line":4,"silent":false,"no-file":false,"id":null,"timeout":0,"column":15,"file":"src/Quicksort.hs"}
2018-01-23 20:48:59 +0100 TRACE :127.0.0.1:50386/127.0.0.1:50386/req/_> requested >> {"command":"whoat","line":4,"column":15,"file":"src/Quicksort.hs"}
2018-01-23 20:48:59 +0100 TRACE :127.0.0.1:50386/127.0.0.1:50386/req/_> responsed << {"result":[]}
2018-01-23 20:48:59 +0100 INFO :127.0.0.1:50386> disconnected
And what says
sqlite3 hsdev.db "select * from names where module_id in (select id from modules where file like '%Quicksort.hs') and name == 'Ord';"
In my case result is
1212||Ord|4|15|4|18||||GHC.Classes|Ord||573
2263||Ord|4|15|4|18||||||/Users/rik/projects/quicksort/src/Quicksort.hs:4:15: not in scope: Ord
Can you drop somewhere hsdev.db
, I'll try to examine it
There's no Prelude
module in base
package. Seems, that it hadn't been inspected for unknown reasons.
Your hsdev
is built with same stack?
Try run clean inspection of global-db
, where base
should be:
> hsdev start
> hsdev scan --cabal
> hsdev module -m Prelude -h # should output smth
> hsdev module --package base -h | jq -c -r '.[].name' | sort # list all module names in base
Your hsdev is built with same stack?
Yes, they are built with same Stackage version and the stack tool version.
hsdev module -m Prelude -h
gives no output.
hsdev module --package base -h | jq -c -r '.[].name' | sort
gives the module names.
Also I wonder how do you find the package db's? There are local and global ones. Do you use the stack path
command? Also the sandbox
.stack-work
can contain package db's of multiple Stackage versions.
Also I wonder how do you find the package db's? There are local and global ones. Do you use the stack path command?
Yes, it runs stack path
, you can notice it in log.
Here's package-dbs for your project:
> select package_db_stack from projects;
["global-db","package-db:/Users/rik/.stack/snapshots/x86_64-osx/lts-10.0/8.2.2/pkgdb","package-db:/Users/rik/haskell/quicksort/.stack-work/install/x86_64-osx/lts-10.0/8.2.2/pkgdb"]
They goes from global to local. In this case second one is snapshot-pkg-db
and last is local-pkg-db
.
global-db
should be default for compiler. It's not stored directly, but we can look at install_dirs
of installed modules:
> select distinct install_dirs from modules where package_name in (select package_name from package_dbs where package_db = 'global-db')
["/Users/rik/.stack/snapshots/x86_64-osx/lts-10.0/8.2.2/lib/x86_64-osx-ghc-8.2.2/Cabal-2.0.1.1-ARIl7MGNKZFBAH1HVzpC6s"]
["/Users/rik/.stack/programs/x86_64-osx/ghc-8.2.2/lib/ghc-8.2.2/base-4.10.1.0"]
["/Users/rik/.stack/programs/x86_64-osx/ghc-8.2.2/lib/ghc-8.2.2/binary-0.8.5.1"]
["/Users/rik/.stack/programs/x86_64-osx/ghc-8.2.2/lib/ghc-8.2.2/ghc-prim-0.5.1.1"]
["/Users/rik/.stack/programs/x86_64-osx/ghc-8.2.2/lib/ghc-8.2.2/containers-0.5.10.2"]
["/Users/rik/.stack/programs/x86_64-osx/ghc-8.2.2/lib/ghc-8.2.2/deepseq-1.4.3.0"]
["/Users/rik/.stack/programs/x86_64-osx/ghc-8.2.2/lib/ghc-8.2.2/integer-gmp-1.0.1.0"]
["/Users/rik/.stack/programs/x86_64-osx/ghc-8.2.2/lib/ghc-8.2.2/bytestring-0.10.8.2"]
["/Users/rik/.stack/programs/x86_64-osx/ghc-8.2.2/lib/ghc-8.2.2/process-1.6.1.0"]
["/Users/rik/.stack/programs/x86_64-osx/ghc-8.2.2/lib/ghc-8.2.2/directory-1.3.0.2"]
["/Users/rik/.stack/snapshots/x86_64-osx/lts-10.0/8.2.2/lib/x86_64-osx-ghc-8.2.2/haskeline-0.7.4.2-AeEGhncg0K8ACPik34VchK"]
["/Users/rik/.stack/programs/x86_64-osx/ghc-8.2.2/lib/ghc-8.2.2/pretty-1.1.3.3"]
["/Users/rik/.stack/programs/x86_64-osx/ghc-8.2.2/lib/ghc-8.2.2/transformers-0.5.2.0"]
["/Users/rik/.stack/programs/x86_64-osx/ghc-8.2.2/lib/ghc-8.2.2/unix-2.7.2.2"]
["/Users/rik/.stack/programs/x86_64-osx/ghc-8.2.2/lib/ghc-8.2.2/time-1.8.0.2
Seems, that global-db
is somewhere in /Users/rik/.stack/programs/x86_64-osx/ghc-8.2.2/lib
This works as expected. Unexpected is that there's no Prelude
module, while it should be.
You can even run hsdev from repl:
λ> :set -XOverloadedStrings
λ> import HsDev
λ> import HsDev.Scan.Browse
λ> s <- startServer_ silentOpts -- start server with no listening to port
λ> mlocs <- inServer s (inSessionGhc (listModules [] globalDb [])) -- list modules in global-db
λ> "Prelude" `elem` (mlocs ^.. each . installedModuleName) -- check whether Prelude there
True
Cool!
I have removed ~/.stack
and .stack-work
in project. Build project again but it does not help.
@rikvdkleij have you tried run from repl?
I guess whether hsdev even doesn't see Prelude
module while scanning global-db
, or it sees, but then fails somewhere else.
have you tried run from repl?
No, because I did not understand how that will point us to the cause of this problem. But I will try now.
I do not get in working in quicksort, I have added hsdev, lens and test dependencies to cabal file.
I probably missing yet another dependency:
*Quicksort Quicksort HsDev HsDev.Scan.Browse Control.Lens.Operators Data.Text> "Prelude" `elem` (mlocs ^.. each . installedModuleName)
<interactive>:11:29: error:
Variable not in scope:
each
:: (ModuleLocation
-> Data.Functor.Const.Const
(Data.Monoid.Endo [Text]) ModuleLocation)
-> [ModuleLocation]
-> Data.Functor.Const.Const
(Data.Monoid.Endo [Text]) [ModuleLocation]
I found one bug, but not sure if it's related in this case. Could you try latest hsdev from repo?
elem
is from Data.List
I found one bug, but not sure if it's related in this case. Could you try latest hsdev from repo?
Yes, it works. You solved it! Thanks!
elem is from Data.List
It could not find each
Something else. Because I want to integrate hsdev
with IntelliJ it has to be as light as possible. hsdev
has to be build as fast as possible. It helps to minimize the dependencies. Also caching is already done in IntelliJ because I know when code is changed. Would you be willing to create a "light" or simplified version of hsdev
? I'm only interested in symbol, usage and type info. So hsdev
would act more as gateway to the GHC API.
Btw, my previous comment is just a question. I understand it if you say no. I’m just looking for a good solution for the IntelliJ Haskell plugin.
It's ok, but we should discuss details of what exactly light hsdev should do. Could you describe desired api?
Great! Thanks! I will create separate issue for that.
How do I find the usages of identifier which is not defined at the top-level?