-
-
Notifications
You must be signed in to change notification settings - Fork 391
Implement explicit fixity in ghcide #2973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
61af55e
Explicit fixity
July541 91a146c
Independent test dir
July541 9a5c60b
Try GetModIfaceFromDisk
July541 2547212
Try Typecheck
July541 4e82134
Merge branch 'master' into explicit-fixity
July541 a40c194
Handle ghc exception
July541 7846fcf
Lower case
July541 44fdcdb
Unifiy to TcGblEnv
July541 06b9677
Render hover doc
July541 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{-# LANGUAGE RecordWildCards #-} | ||
module Fixity where | ||
import Control.Monad | ||
import Data.Function (on) | ||
import Control.Applicative ((<|>)) | ||
f1 = (++) | ||
f2 = ($) | ||
f3 = (.) | ||
f4 = (+) | ||
f5 = 1 - 2 | ||
f6 = (<>) | ||
f7 = (>>=) | ||
f8 = (>=>) | ||
f9 = elem | ||
f10 = on | ||
f11 = (||) | ||
f12 = mod | ||
f13 = (**) | ||
f14 = (^) | ||
f15 = (<$) | ||
f16 = seq | ||
f17 = (<|>) | ||
|
||
infixr 7 >>: | ||
infix 9 >>:: | ||
data F = G | ||
{ (>>:) :: Int -> Int -> Int | ||
, c :: Int | ||
, (>>::) :: Char | ||
} | ||
f G{..} = undefined | ||
|
||
infixl 1 `f` | ||
|
||
infixr 9 >>>: | ||
(>>>:) :: Int -> Int | ||
(>>>:) x = 3 | ||
|
||
infixl 3 ~\: | ||
(~\:) x y = 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module FixityImport where | ||
|
||
import Fixity | ||
|
||
g = (>>>:) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,6 +202,7 @@ main = do | |
, outlineTests | ||
, highlightTests | ||
, findDefinitionAndHoverTests | ||
, hoverFixityTests | ||
, pluginSimpleTests | ||
, pluginParsedResultTests | ||
, preprocessorTests | ||
|
@@ -6523,6 +6524,58 @@ expectSameLocations actual expected = do | |
return (filePathToUri fp, l, c)) | ||
actual' @?= expected' | ||
|
||
hoverFixityTests :: TestTree | ||
hoverFixityTests = testGroup "Explicit fixity" | ||
[ hoverTest "(++)" (Position 5 7) "infixr 5 `++`" | ||
, hoverTest "($)" (Position 6 7) "infixr 0 `$`" | ||
, hoverTest "(.)" (Position 7 7) "infixr 9 `.`" | ||
, hoverTest "(+)" (Position 8 7) "infixl 6 `+`" | ||
, hoverTest "(-)" (Position 9 8) "infixl 6 `-`" | ||
, hoverTest "(<>)" (Position 10 7) "infixr 6 `<>`" | ||
, hoverTest "(>>=)" (Position 11 7) "infixl 1 `>>=`" | ||
, hoverTest "(>=>)" (Position 12 7) "infixr 1 `>=>`" | ||
, hoverTest "elem" (Position 13 7) "infix 4 `elem`" | ||
, hoverTest "on" (Position 14 7) "infixl 0 `on`" | ||
, hoverTest "(||)" (Position 15 8) "infixr 2 `||`" | ||
, hoverTest "mod" (Position 16 8) "infixl 7 `mod`" | ||
, hoverTest "(**)" (Position 17 8) "infixr 8 `**`" | ||
, hoverTest "(^)" (Position 18 8) "infixr 8 `^`" | ||
, hoverTest "(<$)" (Position 19 8) "infixl 4 `<$`" | ||
, hoverTest "seq" (Position 20 9) "infixr 0 `seq`" | ||
, hoverTest "(<|>)" (Position 21 8) "infixl 3 `<|>`" | ||
, hoverTest "fixity define" (Position 23 11) "infixr 7 `>>:`" | ||
, hoverTest "record" (Position 28 10) "infix 9 `>>::`" | ||
, hoverTest "wildcards" (Position 30 5) "infixr 7 `>>:`\n\ninfix 9 `>>::`" | ||
, hoverTest "function" (Position 32 11) "infixl 1 `f`" | ||
, hoverTest "signature" (Position 35 2) "infixr 9 `>>>:`" | ||
, hoverTest "operator" (Position 36 2) "infixr 9 `>>>:`" | ||
, hoverTest "escape" (Position 39 2) "infixl 3 `~\\:`" | ||
, expectFail $ hoverTest "import" (Position 2 18) "Control.Monad***" | ||
-- It will cause error like: "Failed to load interface for \8216Fixity\8217\nIt is not a module in the current program, or in any known package." | ||
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. Get fixity from locally defined module failed because something like It's a trivial case and I think we have an available function even without this. |
||
-- while we look up fixities from imported local defined module, see test below. | ||
, expectFailBecause "Not support yet" | ||
$ hoverTestImport "imported" (Position 4 7) "infixr 9 `>>>:`" | ||
] | ||
where | ||
hoverTest = hoverTest' "Fixity.hs" | ||
hoverTestImport = hoverTest' "FixityImport.hs" | ||
|
||
hoverTest' :: String -> TestName -> Position -> T.Text -> TestTree | ||
hoverTest' docName title pos expected = testSessionWithExtraFiles "fixity" title $ \dir -> do | ||
doc <- openDoc (dir </> docName) "haskell" | ||
void $ waitForTypecheck doc | ||
h <- getHover doc pos | ||
let expected' = "\n" <> sectionSeparator <> expected | ||
case h of | ||
Nothing -> liftIO $ assertFailure "No hover" | ||
Just (Hover contents _) -> case contents of | ||
HoverContentsMS _ -> liftIO $ assertFailure "Unexpected content type" | ||
HoverContents (MarkupContent _ txt) -> | ||
liftIO | ||
$ assertBool ("Failed to find " <> T.unpack expected <> " in " <> T.unpack txt) | ||
$ expected' `T.isInfixOf` txt | ||
closeDoc doc | ||
|
||
---------------------------------------------------------------------- | ||
-- Utils | ||
---------------------------------------------------------------------- | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using
TypeCheck
here is bad. It will make ghcide hovers slower, and it will break the ability to get hover information at cold startup from the local cache.Now, if fixity was in a plugin, it would still create all the problems above since
his-plugin-api
collects all the results before sending the response. But one can:I think this is a blocker. Workarounds:
addPersistentRule
. The persistent implementation can return some placeholder or you can cache the fixity info in hiedb if desired.