如何在 IntelliJ 中查看 scala 表达式的类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7858588/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 03:36:34  来源:igfitidea点击:

How do I view the type of a scala expression in IntelliJ

scalaintellij-idea

提问by Jon Freedman

The Eclipse scala plugin has a nice feature which shows you the type of a variable when you hover the mouse over it. How do I see the same information with the IntelliJ plugin?

Eclipse scala 插件有一个很好的功能,当您将鼠标悬停在变量上时,它会向您显示变量的类型。如何使用 IntelliJ 插件查看相同的信息?

回答by Sergey Passichenko

Select expression and type Alt+ =.

选择表达式并输入Alt+ =



If you want to change the shortcut go to Preferences > Keymapand enter "Type Info" in the search field.

如果要更改快捷方式,请转到Preferences > Keymap并在搜索字段中输入“类型信息”。

In older versions, it's Shift+ Ctrl+ Alt+ T.

在旧版本中,它是Shift+ Ctrl+ Alt+ T

回答by Zoltán

On OS X, it's ctrl+ shift+ Pfor me. This shows the exact type with resolved generics.

在OS X,这是ctrl+ shift+P我。这显示了具有解析泛型的确切类型。

回答by Pawe? Krupiński

CTRL / Command key and hover over the variable or method.

CTRL / Command 键并将鼠标悬停在变量或方法上。

回答by Tomasz Nurkiewicz

You can hit Ctrl+ Qon a variable or method signature to view its type.

您可以在变量或方法签名上点击Ctrl+Q以查看其类型。

There is also a neat trick to view type of any expression: select the expression and type Ctrl+ Alt+ V. This will show Extract variabledialog with expression type to be extracted shown for convenience.

查看任何表达式的类型还有一个巧妙的技巧:选择表达式并键入Ctrl+ Alt+ V。为方便起见,这将显示带有要提取的表达式类型的提取变量对话框。

回答by Andrew

You can set IntelliJ up sort of like eclipse. Go to:

您可以像日食一样设置 IntelliJ。去:

File -> Settings -> Languages & Frameworks -> Scala

and then tick "Show type info on mouse hover after, ms" and set your preferred timeout.

然后勾选“在鼠标悬停后显示类型信息,毫秒”并设置您的首选超时。

This works well except that other messages seem to take preference. The most common being "Declaration is never used" which is quite a lot of the time if you have just written a valand want to see it's type. Then you have to resort to (Alt+ =) for PC or (Ctrl+ Shift+ P) forMac.

这很有效,只是其他消息似乎更受欢迎。最常见的是“从不使用声明”,如果您刚刚编写了 aval并想查看它的类型,那么这在很多时候是很常见的。然后你必须求助于 ( Alt+ =) 为 PC 或 ( Ctrl+ Shift+ P) 为Mac。

回答by Erik van Oosten

In IntelliJ 2016 and later with Mac OS X 10.5+keybindings the keybinding is Ctrl+?+P.

在带有Mac OS X 10.5+键绑定的IntelliJ 2016 及更高版本中,键绑定是Ctrl+ ?+ P

Old answer:

旧答案:

Under MacOS with Mac OS X 10.5+keybindings, it is supposed to be ?+=, however that does not seem to work at all (for me).

在带有Mac OS X 10.5+键绑定的MacOS 下,它应该是?+ =,但是这似乎根本不起作用(对我来说)。

In the settings (Preferences > Keymapand enter "Type Info" in the search field), I added the shortcut Ctrl+?+Tto the action. This shortcut works fine.

在设置(Preferences > Keymap并输入“类型信息”,在搜索领域),我添加了快捷键Ctrl+ ?+T的行动。这个快捷方式工作正常。

回答by Dave Griffith

Hold down the Command key as you mouseover. Note: I tested this on Mac OS X with standard keybindings. Different OSes or non-standard keybindings may of course be different, but the functionality is certainly there.

鼠标悬停时按住 Command 键。注意:我在 Mac OS X 上使用标准键绑定测试了这个。不同的操作系统或非标准的键绑定当然可能不同,但功能肯定是存在的。

回答by akauppi

There's good tips gathered around here, but since the mappings vary by the keyboard bindings, here's a summary for the Mac OS X 10.5+bindings.

这里收集了一些很好的技巧,但由于映射因键盘绑定而异,这里是绑定的摘要Mac OS X 10.5+

  • ctrl+ hover: show the type of the expression

  • alt+ hover: clicking on the expression inspects its value (very handy!)

  • ?+ hover works like ctrl+hover, but also allows clicking the link to go to other references of the expression (ctrl+click obviously doesn't because it is regarded as right click in OS X).

  • ctrl+ 悬停:显示表达式的类型

  • alt+ 悬停:单击表达式检查其值(非常方便!)

  • ?+ 悬停的工作方式与ctrl+hover类似,但也允许单击链接转到表达式的其他引用(ctrl+click 显然不能,因为它在 OS X 中被视为右键单击)。

Note: The Mac OS X 10.5+bindings are stillnot the default in IntelliJ 13.1, but they really should be. They have a more native OS X feel than the old Mac OS Xbindings. You can activate them via Preferences > "keyboard"(in the search field) > Keymap > Keymaps: Mac OS X 10.5+

注意:Mac OS X 10.5+绑定仍然不是 IntelliJ 13.1 中的默认值,但它们确实应该是。与旧Mac OS X绑定相比,它们具有更原生的 OS X 感觉。您可以通过Preferences > "keyboard"(在搜索字段中)>Keymap > Keymaps: Mac OS X 10.5+

The real usability problem with these (as of IntelliJ 13.1) is that one needs to hold the key, thenmove the cursor. It should ideally also work when you have the cursor already on the expression, then start keeping ctrl/alt/cmd pressed in. I'll request them for this.

这些(从 IntelliJ 13.1 开始)的真正可用性问题是需要按住键,然后移动光标。理想情况下,当您将光标放在表达式上时,它也应该工作,然后开始按住 ctrl/alt/cmd。我会要求他们这样做。

ps. I know it's OS X, officially, not Mac OS X. IntelliJ IDEA still uses the old naming at least for the keycaps.

附:我知道它是 OS X,正式的,而不是 Mac OS X。IntelliJ IDEA 仍然使用旧的命名至少键帽。

回答by piritocle

For OS X, use ctrl+ Jon a variable, function or signature to get full definition, type, and parameters. Use ctrl+ shift+ Pfor evaluated type (this also works on highlighted code block or expression).

对于 OS X,在变量、函数或签名上使用ctrl+J以获得完整的定义、类型和参数。使用ctrl+ shift+P对评价类型(这也适用突出显示的代码块或表达上)。

回答by Pushpendra Jaiswal

In Windows . Alt + = In mac . option + =

在 Windows 中。Alt + = 在 mac 中。选项 + =