Dependencies view: `getParent` loops forever on untitled documents, extension host runs out of memory
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 70/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript, vscode
- 领域
- tooling
调研方向
循环位于 vscode/src/dependenciesTree.ts:getParent(约第 55 行)会一直向上回溯,直到遇到路径根;而 activeEditorDidChange(约第 92 行)会无视 scheme 去 reveal 任何活动编辑器的 URI,因此 untitled 文档会被无限回溯。请先阅读这两个函数以及 treeVisibilityDidChange,后者还会 reveal 已记住的 currentVisibleItem。完成的标准是:激活 untitled 编辑器不再触发 reveal 或父节点回溯,并且对于非绝对路径或不前进的父路径,getParent 返回 undefined。
由索引模型根据 Issue 内容生成。
描述
Description
Ruby LSP Information
VS Code Version
1.141.0
Ruby LSP Extension Version
0.10.6
Ruby LSP Server Version
0.26.11
Ruby LSP Add-ons
- Ruby LSP Rails (0.4.8)
- RuboCop (1.86.1)
Ruby Version
3.4.7
Ruby Version Manager
mise
Installed Extensions
Click to expand
- bruno (6.0.0)
- claude-code (2.1.296)
- gitlab-workflow (7.2.0)
- ruby-extensions-pack (0.1.14)
- ruby-lsp (0.10.6)
- sorbet-vscode-extension (0.3.47)
- sql-developer (26.3.0)
- vscode-yaml (1.25.0)
Ruby LSP Settings
Click to expand
Workspace
{}
User
{
"enabledFeatures": {
"codeActions": true,
"diagnostics": true,
"documentHighlights": true,
"documentLink": true,
"documentSymbols": true,
"foldingRanges": true,
"formatting": true,
"hover": true,
"inlayHint": true,
"onTypeFormatting": true,
"selectionRanges": true,
"semanticHighlighting": true,
"completion": false,
"codeLens": true,
"definition": true,
"workspaceSymbol": true,
"signatureHelp": true,
"typeHierarchy": true
},
"featuresConfiguration": {},
"addonSettings": {},
"rubyVersionManager": {
"identifier": "auto"
},
"customRubyCommand": "",
"formatter": "rubocop_internal",
"linters": [
"rubocop_internal"
],
"bundleGemfile": "",
"testTimeout": 30,
"pullDiagnosticsOn": "both",
"useBundlerCompose": false,
"bypassTypechecker": false,
"rubyExecutablePath": "sh",
"indexing": {},
"erbSupport": true,
"featureFlags": {},
"sigOpacityLevel": "1"
}
Also: Remote – Dev Containers on linux-arm64 (Apple Silicon host), explorer.autoReveal left at its default (true). All versions above are the latest stable releases, and the same code is still on main.
Reproduction steps
- Start the Ruby LSP in VS Code by opening a Rails project.
- In the Explorer, expand the Dependencies view so its contents are visible.
- Create an untitled document with File → New Text File (
Untitled-N). - Click a saved file, then click back to the untitled tab.
- The extension host's memory starts climbing straight away (591 MB → 1.46 GB in about 20 seconds) until V8 aborts it with
JavaScript heap out of memory. The VS Code window hangs in the meantime.
No other extensions are needed. We first hit this through Oracle SQL Developer worksheets, which are also untitled documents.
It also triggers if an untitled editor is active while the Dependencies view is hidden and you then show the view, because currentVisibleItem is remembered and revealed in treeVisibilityDidChange.
Expected: nothing happens, because an untitled document can't be part of any gem.
Code snippet or error message
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Extension Host Process exited with code: null, signal: SIGABRT.
Heap-allocation profile of the extension host while memory was growing:
-- live allocations by extension
65.3% (vscode core)
34.3% shopify.ruby-lsp
-- top allocating functions
49.0% (vscode core) :: r extensionHostProcess.js:28
34.1% shopify.ruby-lsp :: getParent extension.js:79
15.5% (vscode core) :: (anon) extensionHostProcess.js:294
0.3% (vscode core) :: _resolveParent extensionHostProcess.js:294
0.3% (vscode core) :: joinPath extensionHostProcess.js:28
The cause seems to be in vscode/src/dependenciesTree.ts. activeEditorDidChange (line 92) wraps any active editor's URI in a GemFilePath and reveals it, whatever its scheme. TreeView.reveal then calls getParent (line 55) until it returns undefined, and getParent only stops when parentUri.path === path.parse(parentUri.path).root:
getParent(element: BundlerTreeNode): vscode.ProviderResult<BundlerTreeNode> {
const parentUri = vscode.Uri.joinPath(element.resourceUri, "..");
const rootPath = path.parse(parentUri.path).root;
if (parentUri.path === rootPath) {
return undefined;
}
// ...otherwise returns a gem root or a new GemDirectoryPath(parentUri)
}
For a file: URI the walk ends at /. An untitled document's path has no leading /, so rootPath is "", and joining .. never produces "":
/workspaces/app/db/x.sql -> /workspaces/app/db -> /workspaces/app -> /workspaces -> / (stops)
Untitled-2 -> . -> .. -> ../.. -> ../../.. -> ../../../.. -> ... (never stops)
(The trace comes from running the same check with path.posix.join in Node. The profile above matches it.)
Possible fix: skip non-file: URIs in activeEditorDidChange, ideally only revealing URIs under one of gemRootFolders. As a safety net, getParent could return undefined when the parent path isn't absolute or equals the current path:
const uri = editor?.document.uri;
if (!uri || uri.scheme !== "file") {
return;
}
Workaround: hide the Dependencies view, or set "explorer.autoReveal": false.
- 主要语言
- Ruby
- 星标
- 2k
- 派生
- 286
- 平均合并
- 8 小时 37 分钟
- 30 天内合并 PR
- 12
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Shopify/ruby-lsp 的其他 Issue
-
Linux file system with square brackets in the directory/filename are failing to be indexed可能已有人在做 @andriytyurnikov 于 221 天前认领。 未关闭bug help-wanted pinned
难度 2/5 1-3 小时 新手友好度 68/100
Shopify/ruby-lsp#3503 · 8 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
Diagnostics use a stale parse_result when the request is read before its didChange is applied可能已有人在做 @efegokdemir 于 4 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 52/100
维护者通常 1 天内回复
-
rbenv activation leaks RBENV_VERSION and RBENV_DIR into process.env of the extension host可能已有人在做 @efegokdemir 于 12 天前认领。 未关闭bug
难度 3/5 半天 新手友好度 45/100
维护者通常 1 天内回复
-
Rename of a class moves its file and leaves require_relative on the old path可能已有人在做 @efegokdemir 于 18 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 22/100
维护者通常 1 天内回复
-
Paths need to be escaped可能已有人在做 @Vraiment 于 22 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 25/100
维护者通常 1 天内回复
相似的 Issue
-
verified
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 5 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
zerocracy/judges-action#2984 ·
维护者通常 1 天内回复