-
Notifications
You must be signed in to change notification settings - Fork 123
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 a modules() method to the cryptol python api for listing modules and their documentation #1755
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
33cc874
Add a modules() method to the cryptol python api for listing modules …
glguy 9fed2c5
Changelog!
glguy a486cb8
update rpc docs
glguy 122aeea
Additional changelog
glguy 7735acf
Add modules() to the many layers of the API and add a test case
glguy bda99ac
Put the space back into the manually line-wrapped documentation
glguy 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 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 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 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 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 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 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 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 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 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 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 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
18 changes: 18 additions & 0 deletions
18
cryptol-remote-api/python/tests/cryptol/test-files/Modules.cry
This file contains 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,18 @@ | ||
/** | ||
* A top-level | ||
* docstring | ||
*/ | ||
module Modules where | ||
|
||
/** A functor docstring */ | ||
submodule F where | ||
parameter | ||
type N : # | ||
|
||
/** A submodule in a functor docstring */ | ||
submodule Q where | ||
q = () | ||
|
||
/** A submodule docstring */ | ||
submodule M = submodule F where | ||
type N = 0 |
This file contains 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,26 @@ | ||
import unittest | ||
from pathlib import Path | ||
import cryptol | ||
from cryptol.single_connection import * | ||
|
||
class TestModules(unittest.TestCase): | ||
def test_modules(self): | ||
connect(verify=False) | ||
load_file(str(Path('tests','cryptol','test-files', 'Modules.cry'))) | ||
|
||
expected = [ | ||
{'module': 'Cryptol', 'parameterized': False}, | ||
{'module': 'Modules', 'parameterized': False, 'documentation': ['A top-level\ndocstring\n']}, | ||
{'module': 'Modules::`where` argument of M', 'parameterized': False}, | ||
{'module': 'Modules::M', 'parameterized': False, 'documentation': ['A submodule docstring\n', 'A functor docstring\n']}, | ||
{'module': 'Modules::M::Q', 'parameterized': False, 'documentation': ['A submodule in a functor docstring\n']}, | ||
{'module': 'Modules::F', 'parameterized': True, 'documentation': ['A functor docstring\n']}, | ||
{'module': 'Modules::F::Q', 'parameterized': True, 'documentation': ['A submodule in a functor docstring\n']}, | ||
] | ||
|
||
names_to_check = modules() | ||
|
||
self.assertCountEqual(expected, names_to_check) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains 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,83 @@ | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module CryptolServer.Modules | ||
( visibleModules | ||
, visibleModulesDescr | ||
) where | ||
|
||
import qualified Argo.Doc as Doc | ||
import qualified Data.Aeson as JSON | ||
import Data.Aeson ((.=)) | ||
import qualified Data.Map as Map | ||
import Data.Text (unpack) | ||
|
||
import Cryptol.ModuleSystem.Env (loadedModules) | ||
import Cryptol.ModuleSystem.Interface (ifsDoc) | ||
import Cryptol.TypeCheck.AST as T | ||
import Cryptol.Utils.PP (PP, pp) | ||
|
||
import CryptolServer (CryptolCommand, getModuleEnv) | ||
|
||
|
||
data VisibleModulesParams = VisibleNamesParams | ||
|
||
instance JSON.FromJSON VisibleModulesParams where | ||
parseJSON _ = pure VisibleNamesParams | ||
|
||
instance Doc.DescribedMethod VisibleModulesParams [VisibleModuleInfo] where | ||
parameterFieldDescription = [] | ||
|
||
resultFieldDescription = | ||
[ ("module", | ||
Doc.Paragraph [ Doc.Text "A human-readable representation of the module's name"]) | ||
, ("documentation", | ||
Doc.Paragraph [ Doc.Text "An optional field containing documentation strings for the module, " | ||
, Doc.Text "if it is documented"]) | ||
, ("parameterized", | ||
Doc.Paragraph [ Doc.Text "A Boolean value indicating whether the focused module is " | ||
, Doc.Text "parameterized" | ||
]) | ||
] | ||
|
||
visibleModulesDescr :: Doc.Block | ||
visibleModulesDescr = | ||
Doc.Paragraph [Doc.Text "List the currently visible (i.e., in scope) module names."] | ||
|
||
visibleModules :: VisibleModulesParams -> CryptolCommand [VisibleModuleInfo] | ||
visibleModules _ = concatMap (moduleToInfos False) . loadedModules <$> getModuleEnv | ||
|
||
|
||
moduleToInfos :: PP a => Bool -> T.ModuleG a -> [VisibleModuleInfo] | ||
moduleToInfos p m = | ||
ModuleInfo | ||
{ name = show (pp (T.mName m)) | ||
, parameterized = p | ||
, docs = map unpack (T.mDoc m) | ||
} : | ||
[ ModuleInfo | ||
{ name = show (pp k) | ||
, parameterized = p | ||
, docs = map unpack (ifsDoc (T.smIface v)) | ||
} | ||
| (k,v) <- Map.assocs (T.mSubmodules m) | ||
] ++ | ||
[ x | ||
| v <- Map.elems (T.mFunctors m) | ||
, x <- moduleToInfos True v | ||
] | ||
|
||
data VisibleModuleInfo = | ||
ModuleInfo | ||
{ name :: String | ||
, parameterized :: Bool | ||
, docs :: [String] | ||
} | ||
|
||
instance JSON.ToJSON VisibleModuleInfo where | ||
toJSON ModuleInfo{..} = JSON.object ( | ||
[ "module" .= name | ||
, "parameterized" .= parameterized] ++ | ||
["documentation" .= docs | not (null docs)]) |
Oops, something went wrong.
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.
Can you add a similar changelog entry to the
cryptol-remote-api
changelog?