mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-08 08:52:12 +00:00
feat(editor): Show the enclosing declarations with Context Info
View > Context Info (Ctrl+Shift+Q on macOS, Alt+Q on Windows) shows the class, method and block header lines around the caret in a hint, which helps when they are scrolled out of view.
This commit is contained in:
1 parent
b35035f8d9
commit
db6acf829e
8 files changed
+26
-1
No files matched your search
@@ -442,6 +442,7 @@ pub fn spec(os: Os) -> Vec<Entry> {
|
||||
act("code.quickDocumentation", "Quick Documentation"),
|
||||
act("code.expressionTypeInfo", "Expression Type Info"),
|
||||
act("code.showErrorDescription", "Error Description"),
|
||||
act("editor.contextInfo", "Context Info"),
|
||||
act("code.showIntentions", "Show Context Actions"),
|
||||
act("code.generate", "Generate…"),
|
||||
act("code.overrideMethods", "Override Methods…"),
|
||||
|
||||
@@ -52,6 +52,7 @@ import {
|
||||
} from "./cm/folding";
|
||||
import { reverseLines, sortLines } from "./cm/lines";
|
||||
import { customRegions } from "./cm/regions";
|
||||
import { enclosingHeaders } from "./cm/stickyScroll";
|
||||
import { moveElementLeft, moveElementRight } from "./cm/moveElement";
|
||||
import { caretAnchor, openPopup } from "@/editor/lsp/popupStore";
|
||||
import {
|
||||
@@ -328,6 +329,18 @@ function completeCurrentStatement(view: EditorView, slot: EditorSlot) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* View › Context Info (⌃⇧Q / Alt+Q): the declaration lines around the caret
|
||||
* (class, method, block headers), most useful when they are scrolled away.
|
||||
*/
|
||||
function showContextInfo(view: EditorView) {
|
||||
const state = view.state;
|
||||
const line = state.doc.lineAt(state.selection.main.head).number;
|
||||
const headers = enclosingHeaders(state, line);
|
||||
const text = headers.map((n) => state.doc.line(n).text.trimEnd()).join("\n");
|
||||
void executeAction("editor.showHint", { text: text || "No context information here" });
|
||||
}
|
||||
|
||||
/** Navigate › Custom Folding (⌥⌘.): the file's custom regions; picking one moves the caret to it. */
|
||||
function showCustomRegions(view: EditorView) {
|
||||
const regions = customRegions(view.state.doc);
|
||||
@@ -574,6 +587,10 @@ export function registerEditorActions(): () => void {
|
||||
category: "Editor Actions",
|
||||
},
|
||||
),
|
||||
text("editor.contextInfo", "Context Info", (v) => showContextInfo(v), {
|
||||
category: "View",
|
||||
keywords: ["enclosing method", "enclosing class", "where am I"],
|
||||
}),
|
||||
text("navigate.customRegion", "Custom Folding…", (v) => showCustomRegions(v), {
|
||||
category: "Navigate",
|
||||
keywords: ["region", "editor-fold", "go to region"],
|
||||
|
||||
@@ -123,6 +123,7 @@ export const intellijMacos: Record<string, string[]> = {
|
||||
"editor.codeBlockEnd": ["Meta+Alt+]"],
|
||||
"editor.codeBlockStartWithSelection": ["Meta+Alt+Shift+["],
|
||||
"editor.codeBlockEndWithSelection": ["Meta+Alt+Shift+]"],
|
||||
"editor.contextInfo": ["Ctrl+Shift+Q"],
|
||||
"navigate.customRegion": ["Meta+Alt+."],
|
||||
"code.expandToLevel1": ["Meta+* 1"],
|
||||
"code.expandToLevel2": ["Meta+* 2"],
|
||||
|
||||
@@ -124,6 +124,7 @@ export const intellijWindows: Record<string, string[]> = {
|
||||
"editor.codeBlockEnd": ["Ctrl+]"],
|
||||
"editor.codeBlockStartWithSelection": ["Ctrl+Shift+["],
|
||||
"editor.codeBlockEndWithSelection": ["Ctrl+Shift+]"],
|
||||
"editor.contextInfo": ["Alt+Q"],
|
||||
"navigate.customRegion": ["Ctrl+Alt+."],
|
||||
"code.expandToLevel1": ["Ctrl+* 1"],
|
||||
"code.expandToLevel2": ["Ctrl+* 2"],
|
||||
|
||||
@@ -28,6 +28,7 @@ export const vscodeMacos: Record<string, string[]> = {
|
||||
"navigate.callHierarchy": ["Alt+Shift+H"],
|
||||
"navigate.showFilePath": [],
|
||||
"navigate.customRegion": [],
|
||||
"editor.contextInfo": [],
|
||||
// editor.action.wordHighlight.next / prev
|
||||
"navigate.nextHighlightedUsage": ["F7"],
|
||||
"navigate.prevHighlightedUsage": ["Shift+F7"],
|
||||
|
||||
@@ -431,6 +431,7 @@
|
||||
"menu.code.expandAllToLevel4": "4",
|
||||
"menu.code.expandToLevel5": "5",
|
||||
"menu.code.expandAllToLevel5": "5",
|
||||
"menu.editor.contextInfo": "Context Info",
|
||||
"run.services.configurationCount": "{count} configurations",
|
||||
"search.bookmarks.count": "{count, plural, one {# bookmark} other {# bookmarks}}",
|
||||
"settings.zoom.hint": "Change with {zoomIn} or {zoomOut}. Set to 100% with {reset}"
|
||||
|
||||
@@ -4605,5 +4605,7 @@
|
||||
"Copies the change at the caret from the left side to the right one": "将光标处的变更从左侧复制到右侧",
|
||||
"Copies the change at the caret from the right side to the left one": "将光标处的变更从右侧复制到左侧",
|
||||
"Compare Next File": "比较下一个文件",
|
||||
"Compare Previous File": "比较上一个文件"
|
||||
"Compare Previous File": "比较上一个文件",
|
||||
"Context Info": "上下文信息",
|
||||
"No context information here": "此处没有上下文信息"
|
||||
}
|
||||
@@ -431,6 +431,7 @@
|
||||
"menu.code.expandAllToLevel4": "4",
|
||||
"menu.code.expandToLevel5": "5",
|
||||
"menu.code.expandAllToLevel5": "5",
|
||||
"menu.editor.contextInfo": "上下文信息",
|
||||
"run.services.configurationCount": "{count} 个配置",
|
||||
"search.bookmarks.count": "{count} 个书签",
|
||||
"settings.zoom.hint": "使用 {zoomIn} 或 {zoomOut} 更改,使用 {reset} 重置为 100%"
|
||||
|
||||
Reference in new issue
Block a user