Skip to content

Commit

Permalink
Large file optimization for updating outline
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Feb 28, 2021
1 parent 24bd96f commit 733dcd5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
6 changes: 3 additions & 3 deletions dist/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/main.js.map

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions lib/main/atom/utils/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,32 @@ async function editorTokenized(editor: Atom.TextEditor) {
}
})
}

// From https://github.com/atom-community/atom-ide-outline/blob/ec1a7197d63055de910562da3cc2b95fd939afc4/src/main.ts#L53
// minimum number of line length to trigger large file optimizations
const longLineLength =
(atom.config.get("linter-ui-default.longLineLength") as number | null) ?? 4000
// minimum number of lines to trigger large file optimizations
const largeFileLineCount =
((atom.config.get("linter-ui-default.largeFileLineCount") as number | null) ?? 3000) / 6

export function lineCountIfLarge(editor: Atom.TextEditor) {
// @ts-ignore
if (editor.largeFileMode) {
return 20000
}
const lineCount = editor.getLineCount()
if (lineCount >= largeFileLineCount) {
// large file detection
return lineCount
} else {
// long line detection
const buffer = editor.getBuffer()
for (let i = 0, len = lineCount; i < len; i++) {
if (buffer.lineLengthForRow(i) > longLineLength) {
return longLineLength
}
}
return 0 // small file
}
}
6 changes: 5 additions & 1 deletion lib/main/atom/views/outline/navigationTreeComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {CompositeDisposable, Disposable, TextEditor} from "atom"
import * as etch from "etch"
import {isEqual} from "lodash"
import debounce from "lodash/debounce"
import {NavigationTree} from "typescript/lib/protocol"
import {GetClientFunction} from "../../../../client"
import {handlePromise} from "../../../../utils"
Expand Down Expand Up @@ -185,6 +186,9 @@ export class NavigationTreeComponent
// set navTree
await this.loadNavTree()

this.editorChanging = editor.onDidStopChanging(this.loadNavTree)
const lineCount = atomUtils.lineCountIfLarge(editor)
this.editorChanging = editor.onDidStopChanging(
lineCount === 0 ? this.loadNavTree : debounce(this.loadNavTree, Math.max(lineCount / 5, 300)),
)
}
}

0 comments on commit 733dcd5

Please sign in to comment.