-
Notifications
You must be signed in to change notification settings - Fork 688
[move-analyzer] Add Docstring rendering on-hover #328
[move-analyzer] Add Docstring rendering on-hover #328
Conversation
I was wondering if you'd consider adding an automated test to the newly extended testing framework to test this feature. |
Also a bit of heads up, modifying source code of the Move test files will break the move-analyzer tests ( The only Move source file you can modify freely without worrying about it is This in addition to the current problem which seems unrelated ( |
Crap... I guess I was wrong about that... My apologies... You have to adjust line numbers in the test portion of |
By newly extended testing framework do you mean the tests in
No problem - will create new modules and fix up |
I see the unit tests (currently in Admittedly there are not "integration" tests ( So, in short, ideally we'd have both - more functionally testing (if necessary) in unit tests and perhaps just one integration test just to make sure that things work properly between the move analyzer and the editor. |
bc759f2
to
a7f08b9
Compare
Changes
LMK how that looks! |
@yubing744: bors r+ Help review |
@Deagler You don't seem to be dealing with another form of documentation comments /**, which is mentioned in the lexical analysis related code: move/language/move-compiler/src/parser/lexer.rs Lines 212 to 216 in f618b1b
The rest of the code looks fine. |
Thanks for the heads up. For some reason I thought Move only supported /// as docstrings. I've added the relevant changes + unit tests + integration test to support that format. |
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.
LGTM
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.
Overall looks great! I requested a few small(ish) changes but we are almost good to go!
@@ -0,0 +1,42 @@ | |||
module Symbols::M6 { |
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 seems like these test files are duplicates of those in language/move-analyzer/tests/symbols/sources
. Could we keep just one copy?
I suggest we we adopt the following convention. If a move source file is used only for integration test, it would be in language/move-analyzer/editors/code/tests/lsp-demo/sources
, but if it's used for both integration and unit tests, let's keep it in language/move-analyzer/tests/symbols/sources
.
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've been unable to reliably access files from language/move-analyzer/tests/symbols/sources
via the test-runner in editors/code
.
Instead, I've stripped the irrelevant portions of code from the tests so they can be used purely as integration tests. Similar to what @yubing744 did for porting M1.move
over as an integration test.
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 just rubs me the wrong way to have Move source files used for testing (and similar ones at that) in two different locations.
I've been unable to reliably access files from
language/move-analyzer/tests/symbols/sources
via the test-runner ineditors/code
.
If the opposite is true (you can access editors/code
tests from symbolicator tests, and if changing your tests to use the same files is not a huge problem, please use tests in editors/code
for everything and I will move my tests there (will also try to re-do @yubing744's integration test to use the original, possibly augmented, M1 module code).
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 can't access editors/code
tests from symbolicator tests with the current setup because cargo test
runs the tests at a different level compared to editors/code
This causes the reference to MoveStdLib
to break (see: Move.toml
in editors/code
). If I update the path to MoveStdLib
then the symbolicator tests start working but the editors/code
tests break.
If you know how to fix that reference to the StdLib in both cases then I think what you're proposing will work!
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.
If you know how to fix that reference to the StdLib in both cases then I think what you're proposing will work!
Technically we could pull the dependency remotely but perhaps it's indeed not worth it at the moment. Thank you for your patience!
/** | ||
* An LSP command textDocument/hover | ||
*/ | ||
export async function textDocumentHover( |
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.
Just for my own information - this is only used in tests, right (and would not be needed otherwise)?
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.
Yes - this is only used in the integration tests. I've followed the same format as the existing LSP command in that file (textDocumentDocumentSymbol
).
@@ -147,6 +147,8 @@ pub struct UseDef { | |||
def_loc: DefLoc, | |||
/// Location of the type definition | |||
type_def_loc: Option<DefLoc>, | |||
/// Doc string for the relevant identifier/function |
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 also realized that it might be more intuitive to make the doc_string
part of DefLoc
(possibly renaming it to DefInfo
), particularly keeping in mind that we may want to optimize this code at some point and use a reference to DefLoc
in UseDef
rather than "inlining" 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 will cause a lot of diffs across symbols.rs
and it will require a few changes to the code itself. I don't think I can include a String inside DefLoc
as it has the Copy
trait and DefLoc
is copied in multiple places across this file.
Unless there's a simple way to do it, I won't have time to make these changes in this PR.
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 will cause a lot of diffs across
symbols.rs
and it will require a few changes to the code itself. I don't think I can include a String insideDefLoc
as it has theCopy
trait andDefLoc
is copied in multiple places across this file.Unless there's a simple way to do it, I won't have time to make these changes in this PR.
Not necessarily. It's just that after looking at this again it seemed like comment is associated with a def and we have a structure that describes the def already, so it would be a more natural place for the doc string. I think it may be worth doing in the future, though.
4c485d6
to
8923e41
Compare
@Deagler - linting is failing and it's a required check.... |
edit: my bad - failed again... fixed one more time and force-pushed. |
390b73d
to
f2fdfb6
Compare
* [move-analyzer] Add docstring rendering for consts, structs, functions * [move-analyzer] Optimize docstring construction * [move-analyzer] Add rendering for docstrings across other modules * [move-analyzer] Fix M1.move tests * [move-analyzer] Add unit tests for docstring construction * [move-analyzer] Add integration tests for docstring construction * [move-analyzer] Add support for /** .. */ docstring comments * [move-analyzer] Update unit/integration tests to test asterix-based docstrings * [move-analyzer] Fix general PR comments * [move-analyzer] Improve extract_doc_string readability * [move-analyzer] Fix linter issues
Motivation
The existing
move-analyzer
does not render docstrings when you hover over functions, structs, or fields.Due to the lack of docstring rendering, new Move developers need to keep a separate window open where they can reference the standard library and the Sui/Aptos codebase.
These changes speed up DX by adding docstring rendering when hovering over functions, structs, constants, etc...
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Build the move-analyzer locally and install the move analyzer extension. Now setup
.vscode/settings.json
like this:You will see that the docstrings are now attached on-hover (test via the files provided in
move-analyzer/tests/symbols/sources
)