-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Add local definitions to outline #4312
base: master
Are you sure you want to change the base?
Conversation
1cb369c
to
62fb5c1
Compare
getRefMap :: HieAstResult -> RefMap Type | ||
getRefMap HAR{refMap=refMap, hieKind=hieKind} = | ||
case hieKind of | ||
HieFromDisk _ -> mempty |
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.
I have a question, why we use mempty
for HieFromDisk
here
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.
This is mostly because I needed a RefMap Type
, and I didn't know how to get there from RefMap TypeIndex
. If this is important, I can keep hacking.
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.
Maybe you can find some inspiration for how to recover full types here?
haskell-language-server/ghcide/src/Development/IDE/Spans/AtPoint.hs
Lines 298 to 299 in c11f32b
HieFresh -> printOutputable t | |
HieFromDisk full_file -> printOutputable $ hieTypeToIface $ recoverFullType t (hie_types full_file) |
@@ -41,11 +45,13 @@ moduleOutline ideState _ DocumentSymbolParams{ _textDocument = TextDocumentIdent | |||
= liftIO $ case uriToFilePath uri of | |||
Just (toNormalizedFilePath' -> fp) -> do | |||
mb_decls <- fmap fst <$> runAction "Outline" ideState (useWithStale GetParsedModule fp) | |||
mb_hieAst <- fmap fst <$> runAction "Outline" ideState (useWithStale GetHieAst fp) |
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.
Hmmm, these are both ignoring the position mapping, which is probably risky? It means we might create document symbols with out-of-date locations.
@@ -282,4 +305,11 @@ hsConDeclsBinders cons | |||
-> [LFieldOcc GhcPs] | |||
get_flds flds = concatMap (cd_fld_names . unLoc) (unLoc flds) | |||
|
|||
|
|||
getLocalBindings :: RefMap Type -> LHsDecl GhcPs -> [Name] |
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.
This could do with some explanation: I'm not sure reading this why this is the right way to get the local bindings.
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.
What is confusing? Is it the use of getFuzzyScope
or is it something else?
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.
I guess I'm just rather unsure why this is the right thing to do? Why is it okay to use getFuzzyScope
rather than getLocalScope
? What's going on with position mapping?
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.
According to my testing, getLocalScope
only returns symbols at the current start point (the start of the given function), which does not appear to have the locals in scope. getFuzzyScope
returns all symbols that have intersecting scopes. This makes sense to me when I look at the docs for IntervalMap.FingerTree
's dominator
(getLocalScope
) and intersections
(getFuzzyScope
):
dominators
:
O(k log (n/k)). All intervals that contain the given interval, in lexicographical order.
intersections
O(k log (n/k)). All intervals that intersect with the given interval, in lexicographical order.
It's clear that there at least needs a comment there, but maybe it would be better to create a new function with a clearer name?
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.
According to my testing, getLocalScope only returns symbols at the current start point (the start of the given function), which does not appear to have the locals in scope.
I feel confused about what getLocalScope
is for then, if not this? Are we using it wrong?
getLocalBindings refmap (L (locA -> (RealSrcSpan l _)) _) = | ||
nubOrdOn getOccFS . filter isVarName . map fst $ locals | ||
where | ||
locals = getFuzzyScope (bindings refmap) start end |
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.
This doesn't recurse, right? So presumably this won't handle something like:
f = ...
where
g = ...
where
h = ...
?
Worth adding as a test case even if we don't support it, but also maybe we just can support it?
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.
It actually does recurse, I've just pushed an update that adds this and the other test case below
A test case I'd like to see
|
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.
Tests are helpful! I think the results look a bit off?
(R 0 0 0 34) | ||
[ docSymbol "x" SymbolKind_Function (R 0 0 0 34) | ||
, docSymbol "g" SymbolKind_Function (R 0 0 0 34) | ||
, docSymbol "h" SymbolKind_Function (R 0 0 0 34) |
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.
These locations are wrong? They all have the range of the original binding?
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.
Also, shouldn't h
be a child of g
, not of a
?
"f" | ||
SymbolKind_Function | ||
(R 0 0 1 19) | ||
[docSymbol "g" SymbolKind_Function (R 0 0 1 19)] |
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.
This seems wrong, there should be two g
s?
Addresses #3628. Adds all local symbols (functions/vars) as children to function document symbols.
There are a few potential issues:
getFuzzyScope
might be abused here (should I create another function likegetLocalScope
?)Thoughts?