Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

Add different Contexts for Module, import etc... #1375

Merged
merged 5 commits into from
Sep 1, 2019

Conversation

fendor
Copy link
Collaborator

@fendor fendor commented Aug 29, 2019

Add more Contexts for the function getContext.
Goal: Provide information with the Contexts that otherwise need to be reparsed or are simply not available for completions.
So far, this pr provides context for the module header module Foo.Bar where, export list from the module and imports.

Currently, the performance may take a hit when there are a lot of imports, but I dont know what 'a lot' might be.

Also, adds tests for the different contexts.

PR aims to not change the existing completion system but rather expand available contexts.
Completion system should be changed in a different PR.

Contexts that are planned to be implemented here:

  • Module Declaration, extracts module name
  • Module Declaration, export list
  • Imports, import name
  • Imports, import list, etc...
  • [x] Class declaration
  • [x] Instance declaration
  • [ ] Language pragma (Seems impossible?)

@fendor fendor force-pushed the completion-context branch from 7160f52 to 2060ad0 Compare August 29, 2019 16:02
@@ -13,27 +15,86 @@ import Haskell.Ide.Engine.PluginUtils
-- smarter code completion
data Context = TypeContext
| ValueContext
| ModuleContext String
| ImportContext String
| ImportListContext String
Copy link
Collaborator Author

@fendor fendor Aug 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other information is relevant? List of imported symbols?
Do we have to be careful to not clone the GHC/ghc-lib/haskell-src-exts API, since we would duplicate the efforts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of trying to anticipate every possible use-case, I would leave it like that and required context information should be added as needed.

| Just ctx <- everything (<|>) (Nothing `mkQ` go `extQ` goInline) decl
= Just ctx

| Just ctx <- asum $ map importGo imports
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I restrained myself to use everything here, since we do not wish to traverse every info in import lists, this seemed to be more efficient to me, but I do not understand Data enough, if it actually does what I would expect it to.

Copy link
Collaborator Author

@fendor fendor Aug 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now uses something which is the same as everything (<|>) afaik.

go (L (GHC.RealSrcSpan r) GHC.DerivD {})
| pos `isInsideRange` r = Just DerivingContext
| otherwise = Nothing
go (L (GHC.RealSrcSpan r) (GHC.TyClD _ GHC.ClassDecl {}))
Copy link
Collaborator Author

@fendor fendor Aug 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should we handle GHC AST version differences?
A quick work around would be, to add another pattern synonym to Compat.
However, it seems like this would grow out of control quickly. Should we rather use something more version independent, such as ghc-lib or haskell-src-exts?

@fendor fendor requested a review from lukel97 August 30, 2019 13:12
@fendor fendor changed the title WIP: Add different Contexts for Module, import etc... Add different Contexts for Module, import etc... Aug 30, 2019
@fendor
Copy link
Collaborator Author

fendor commented Aug 31, 2019

Only keep contexts that I have a specific use-case in mind for.
E.g. ClassContext and InstanceContext might overshadow the more specific TypeContexts that are currently more helpful.
In a follow-up PR, I aim to add Completions for Import Lists and tidying up Completions.hs. Especially the backtick aware completions are a mess.

@fendor fendor force-pushed the completion-context branch from 2b9fc88 to a127d55 Compare August 31, 2019 09:24
@fendor fendor merged commit 22a61da into haskell:master Sep 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant