Skip to content
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

[move-ide] On-hover improvements #19437

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

awelc
Copy link
Contributor

@awelc awelc commented Sep 18, 2024

Description

This PR improves on several instance of on-hover.

  1. Doc comments now preserves indentation
    image
  2. Clean up the way function signatures (in particular type params and regular params) are displayed on-hover instead of always displaying them on a single line:
    image
  3. Use information about implicit modules/datatype when displaying type information on-hover to abbreviate types by omitting package (for implicit modules, e.g., vector::singleton instead of std::vector::singleton) or both package and modules (for implicit datatypes, e.g., Option, instead of std::option::Option)
    image

Test plan

All new and old tests must pass

Copy link

vercel bot commented Sep 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 20, 2024 0:04am
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Sep 20, 2024 0:04am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Sep 20, 2024 0:04am
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Sep 20, 2024 0:04am

Comment on lines 1001 to 1052
#[derive(Copy, Clone, Debug)]
pub enum ModuleMemberKind {
Constant,
Function,
Struct,
Enum,
}

impl ModuleMemberKind {
pub fn case(self) -> NameCase {
match self {
ModuleMemberKind::Constant => NameCase::Constant,
ModuleMemberKind::Function => NameCase::Function,
ModuleMemberKind::Struct => NameCase::Struct,
ModuleMemberKind::Enum => NameCase::Enum,
}
}
}

#[derive(Copy, Clone, Debug)]
pub enum NameCase {
Constant,
Function,
Struct,
Enum,
Module,
ModuleMemberAlias(ModuleMemberKind),
ModuleAlias,
Variable,
Address,
TypeParameter,
}

impl NameCase {
pub const fn name(&self) -> &'static str {
match self {
NameCase::Constant => "constant",
NameCase::Function => "function",
NameCase::Struct => "struct",
NameCase::Enum => "enum",
NameCase::Module => "module",
NameCase::ModuleMemberAlias(ModuleMemberKind::Function) => "function alias",
NameCase::ModuleMemberAlias(ModuleMemberKind::Constant) => "constant alias",
NameCase::ModuleMemberAlias(ModuleMemberKind::Struct) => "struct alias",
NameCase::ModuleMemberAlias(ModuleMemberKind::Enum) => "enum alias",
NameCase::ModuleAlias => "module alias",
NameCase::Variable => "variable",
NameCase::Address => "address",
NameCase::TypeParameter => "type parameter",
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if these should live in the AST. It might be worth making a new module called name_validation that has these plus the checking functions. Then at least all the code and definitions will still live together.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to these not being in the AST. You could stick them in expansion/mod.rs if you are really struggling for a place. But something like name_validation with all of the other various checking names (some of which might have been dragged into the AST already?) sounds like a great long term solution

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, though it required a bit more massaging as all these name validation functions take context as an argument to generate diagnostics

Comment on lines 972 to 999
// Implicit aliases for the Move Stdlib:
// use std::vector;
// use std::option::{Self, Option};
pub const IMPLICIT_STD_MODULES: &[Symbol] = &[symbol!("option"), symbol!("vector")];
pub const IMPLICIT_STD_MEMBERS: &[(Symbol, Symbol, ModuleMemberKind)] = &[(
symbol!("option"),
symbol!("Option"),
ModuleMemberKind::Struct,
)];

// Implicit aliases for Sui mode:
// use sui::object::{Self, ID, UID};
// use sui::transfer;
// use sui::tx_context::{Self, TxContext};
pub const IMPLICIT_SUI_MODULES: &[Symbol] = &[
symbol!("object"),
symbol!("transfer"),
symbol!("tx_context"),
];
pub const IMPLICIT_SUI_MEMBERS: &[(Symbol, Symbol, ModuleMemberKind)] = &[
(symbol!("object"), symbol!("ID"), ModuleMemberKind::Struct),
(symbol!("object"), symbol!("UID"), ModuleMemberKind::Struct),
(
symbol!("tx_context"),
symbol!("TxContext"),
ModuleMemberKind::Struct,
),
];
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider implicit_imports.rs or similar for these definitions, because they don't really belong in the AST file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, a strange one.
We currently have Flavor defined in editions/mod.rs but maybe we need a flavor module. I think default implementations would make a lot of sense in that module, since the default imports are defined by the flavor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if there is a concrete suggestion here on where to move it in this PR or it's something we are thinking about but could wait for a separate PR...

@@ -90,10 +90,13 @@ use move_command_line_common::files::FileHash;
use move_compiler::{
Copy link
Contributor

Choose a reason for hiding this comment

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

These changes all seem coherent, though I wonder if there is an opportunity to write a helper or two to simplify some of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking the same thing, but honestly I could not find a sensible way to helper-ize it as most additional are not easily separable from their enclosing context. Happy to follow suggestions, though!

Copy link
Contributor

@cgswords cgswords left a comment

Choose a reason for hiding this comment

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

Overall LGTM modulo some suggestions about compiler reorganization. Please make those changes and ask for a re-review.

@@ -1,6 +1,6 @@
module Symbols::M1 {

struct SomeStruct has key, drop, store {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes are unrelated, but remove compilation errors which do not affect symbolication but are annoying when working with these Move files

//**************************************************************************************************
// Valid names
//**************************************************************************************************

Copy link
Contributor

Choose a reason for hiding this comment

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

It's strange to me to change these all to Result<(),Box<Diagnostic>> from their original interface. Instead they should take CompilationEnv and retain their previous behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants