The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.
TypeScript code-editorcross-platformdapdatabase-clientdebuggerdesktop-appdeveloper-toolsgithttp-clientideintellijlsprusttauriterminal
feat(editor): Show the enclosing declarations with Context Info (#161)
l0ng-aia28600c55a4b
diff --git a/src-tauri/src/menu.rs b/src-tauri/src/menu.rsindex 360a02740..909118a44 100644--- a/src-tauri/src/menu.rs+++ b/src-tauri/src/menu.rs@@ -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…"),diff --git a/src/editor/core/actions.ts b/src/editor/core/actions.tsindex d2304b86f..75a52f743 100644--- a/src/editor/core/actions.ts+++ b/src/editor/core/actions.ts@@ -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"],diff --git a/src/platform/keymaps/intellij-macos.ts b/src/platform/keymaps/intellij-macos.tsindex d8af5b09c..e19f23231 100644--- a/src/platform/keymaps/intellij-macos.ts+++ b/src/platform/keymaps/intellij-macos.ts@@ -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"],diff --git a/src/platform/keymaps/intellij-windows.ts b/src/platform/keymaps/intellij-windows.tsindex 3c1ef2a9a..ace2711b2 100644--- a/src/platform/keymaps/intellij-windows.ts+++ b/src/platform/keymaps/intellij-windows.ts@@ -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"],diff --git a/src/platform/keymaps/vscode-macos.ts b/src/platform/keymaps/vscode-macos.tsindex a3f2b5e04..a0ed485e2 100644--- a/src/platform/keymaps/vscode-macos.ts+++ b/src/platform/keymaps/vscode-macos.ts@@ -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"],diff --git a/src/platform/locales/en.json b/src/platform/locales/en.jsonindex 3c2084be7..8c4182d0b 100644--- a/src/platform/locales/en.json+++ b/src/platform/locales/en.json@@ -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}"diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.jsonindex 3c4ed8d72..76a1b4963 100644--- a/src/platform/locales/text/zh.json+++ b/src/platform/locales/text/zh.json@@ -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": "此处没有上下文信息"}diff --git a/src/platform/locales/zh.json b/src/platform/locales/zh.jsonindex da443b0c9..52855c677 100644--- a/src/platform/locales/zh.json+++ b/src/platform/locales/zh.json@@ -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%"