Skip to content

Commit 132a2ee

Browse files
aminyalierdakil
authored andcommitted
Large file optimization for updating outline
1 parent 6a4aebd commit 132a2ee

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

dist/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/main/atom/utils/atom.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,32 @@ async function editorTokenized(editor: Atom.TextEditor) {
9797
}
9898
})
9999
}
100+
101+
// From https://github.com/atom-community/atom-ide-outline/blob/ec1a7197d63055de910562da3cc2b95fd939afc4/src/main.ts#L53
102+
// minimum number of line length to trigger large file optimizations
103+
const longLineLength =
104+
(atom.config.get("linter-ui-default.longLineLength") as number | null) ?? 4000
105+
// minimum number of lines to trigger large file optimizations
106+
const largeFileLineCount =
107+
((atom.config.get("linter-ui-default.largeFileLineCount") as number | null) ?? 3000) / 6
108+
109+
export function lineCountIfLarge(editor: Atom.TextEditor) {
110+
// @ts-ignore
111+
if (editor.largeFileMode) {
112+
return 20000
113+
}
114+
const lineCount = editor.getLineCount()
115+
if (lineCount >= largeFileLineCount) {
116+
// large file detection
117+
return lineCount
118+
} else {
119+
// long line detection
120+
const buffer = editor.getBuffer()
121+
for (let i = 0, len = lineCount; i < len; i++) {
122+
if (buffer.lineLengthForRow(i) > longLineLength) {
123+
return longLineLength
124+
}
125+
}
126+
return 0 // small file
127+
}
128+
}

lib/main/atom/views/outline/navigationTreeComponent.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {CompositeDisposable, Disposable, Point, TextEditor} from "atom"
22
import * as etch from "etch"
33
import {isEqual} from "lodash"
4+
import debounce from "lodash/debounce"
45
import {NavigationTree} from "typescript/lib/protocol"
56
import {GetClientFunction} from "../../../../client"
67
import * as atomUtils from "../../utils"
@@ -205,7 +206,10 @@ export class NavigationTreeComponent
205206
// set navTree
206207
await this.loadNavTree()
207208

209+
const lineCount = atomUtils.lineCountIfLarge(editor)
208210
this.editorScrolling = editor.onDidChangeCursorPosition(this.selectAtCursorLine)
209-
this.editorChanging = editor.onDidStopChanging(this.loadNavTree)
211+
this.editorChanging = editor.onDidStopChanging(
212+
lineCount === 0 ? this.loadNavTree : debounce(this.loadNavTree, Math.max(lineCount / 5, 300)),
213+
)
210214
}
211215
}

0 commit comments

Comments
 (0)