Skip to content

[purs ide] Represent Filters as a datatype rather than functions#3547

Merged
kritzcreek merged 9 commits into
purescript:masterfrom
kritzcreek:ide-filter-datatype
Mar 12, 2019
Merged

[purs ide] Represent Filters as a datatype rather than functions#3547
kritzcreek merged 9 commits into
purescript:masterfrom
kritzcreek:ide-filter-datatype

Conversation

@kritzcreek
Copy link
Copy Markdown
Member

This allows us to reorder the filtering to always filter by module name first and exploit the fact that we store our declarations in a Map of a module names.

Also cleans up the declaration type filter implementation (I don't know of any editor plugin that was using these so far so I decided to break the protocol). If I'm wrong please let me know.

Copy link
Copy Markdown
Contributor

@hdgarrood hdgarrood left a comment

Choose a reason for hiding this comment

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

LGTM :) I don't have any objection to breaking the protocol if nobody is using it. I just have a couple of small comments; totally up to you if/how you address them.

Comment thread psc-ide/DESIGN.org
Filters are functions of type =Map ModuleName [IdeDeclaration] -> Map
ModuleName [IdeDeclaration]=. We keep the =Map= structure around to make the
common case of filtering by module names fast.
Filters are functions of type =Map ModuleName [IdeDeclaration] ->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps this is a bit pedantic of me, but I think it's probably safer to say that filters can be thought of as functions of that type, rather than actually being functions of that type. I think there are lots of functions of that type which aren't expressible as filters, or which wouldn't be commutative.

Comment thread src/Language/PureScript/Ide/Filter.hs Outdated
( Filter
, declarationTypeFilter
, namespaceFilter
( Filter(..)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unless I'm missing something I think you can continue not to export the constructor?


newtype Filter = Filter (Endo [Module])
deriving (Semigroup, Monoid)
newtype Filter = Filter (Either (Set P.ModuleName) DeclarationFilter)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Have you considered having Filter be a newtype around [Either (Set P.ModuleName) DeclarationFilter]? Then I think you could still have a monoid instance which does something similar to optimizeFilters. Just a suggestion; it might be nice for consumers of this API not to have to worry about the difference between a single filter and a collection of filters.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I did, I just wanted to keep the model closer to the protocol here. I'm thinking about making a new command which makes more assumptions about how editors end up asking for completions which could change things around a bit more.

@kritzcreek kritzcreek merged commit 029e222 into purescript:master Mar 12, 2019
@kritzcreek kritzcreek deleted the ide-filter-datatype branch March 12, 2019 07:32
@kritzcreek
Copy link
Copy Markdown
Member Author

Thanks for reviewing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants