Skip to content

Commit

Permalink
Merge branch 'pr/1575'
Browse files Browse the repository at this point in the history
  • Loading branch information
lierdakil committed Mar 27, 2021
2 parents 4f877d6 + 0bfcd98 commit 3bcb499
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 8 deletions.
4 changes: 2 additions & 2 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.

60 changes: 55 additions & 5 deletions lib/main/atom/views/outline/navigationTreeComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {CompositeDisposable, CursorPositionChangedEvent, Disposable, TextEditor} from "atom"
import {CompositeDisposable, Disposable, Point, 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 * as atomUtils from "../../utils"
Expand All @@ -26,11 +27,38 @@ export class NavigationTreeComponent
private editorChanging?: Disposable
private getClient?: GetClientFunction
private subscriptions = new CompositeDisposable()
private longLineLength: number = 4000
private largeFileLineCount: number = 500

constructor(public props: Props) {
prepareNavTree(props.navTree)
etch.initialize(this)
this.subscriptions.add(atom.workspace.observeActiveTextEditor(this.subscribeToEditor))
this.subscriptions.add(
atom.workspace.observeActiveTextEditor(this.subscribeToEditor),
atom.commands.add("atom-text-editor.typescript-editor" as "atom-text-editor", {
"typescript:reveal-in-semantic-view": {
description: "Reveal the symbol under the text cursor in semantic view",
didDispatch: (event) => {
const editor = event.currentTarget.getModel()
this.selectAtCursorLine({newBufferPosition: editor.getCursorBufferPosition()})
},
},
}),
atom.config.observe("atom-typescript.longLineLength", (value) => {
if (value > 0) this.longLineLength = value
}),
atom.config.observe("atom-typescript.largeFileLineCount", (value) => {
if (value > 0) this.largeFileLineCount = value
}),
atom.config.observe("linter-ui-default.longLineLength", (value) => {
if (atom.config.get("atom-typescript.longLineLength") > 0) return
if (typeof value === "number") this.longLineLength = value
}),
atom.config.observe("linter-ui-default.largeFileLineCount", (value) => {
if (atom.config.get("atom-typescript.largeFileLineCount") > 0) return
if (typeof value === "number") this.largeFileLineCount = value / 6
}),
)
}

public async update(props: Partial<Props>) {
Expand Down Expand Up @@ -152,7 +180,7 @@ export class NavigationTreeComponent
* HELPER select the node's HTML represenation which corresponds to the
* current cursor position
*/
private selectAtCursorLine = ({newBufferPosition}: CursorPositionChangedEvent) => {
private selectAtCursorLine = ({newBufferPosition}: {newBufferPosition: Point}) => {
const firstNodeElem = this.firstNode()
if (!firstNodeElem) {
return
Expand Down Expand Up @@ -194,7 +222,29 @@ export class NavigationTreeComponent
// set navTree
await this.loadNavTree()

this.editorScrolling = editor.onDidChangeCursorPosition(this.selectAtCursorLine)
this.editorChanging = editor.onDidStopChanging(this.loadNavTree)
const lineCount = this.lineCountIfLarge(editor)
if (!atom.config.get("atom-typescript.largeFileNoFollowCursor") || lineCount === 0) {
this.editorScrolling = editor.onDidChangeCursorPosition(this.selectAtCursorLine)
}
this.editorChanging = editor.onDidStopChanging(
lineCount === 0 ? this.loadNavTree : debounce(this.loadNavTree, Math.max(lineCount / 5, 300)),
)
}

private lineCountIfLarge(editor: TextEditor) {
const lineCount = editor.getLineCount()
if (lineCount >= this.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) > this.longLineLength) {
return this.longLineLength
}
}
return 0 // small file
}
}
}
6 changes: 6 additions & 0 deletions lib/typings/atom-config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ declare module "atom" {
"atom-typescript.jsSyntaxScopes": string[]
"atom-typescript.allowJS": boolean
"atom-typescript.tsserverInstancePerTsconfig": boolean
"atom-typescript.longLineLength": number
"atom-typescript.largeFileLineCount": number
"atom-typescript.largeFileNoFollowCursor": boolean
"atom-typescript": {
unusedAsInfo: boolean
checkAllFilesOnSave: boolean
Expand Down Expand Up @@ -83,6 +86,9 @@ declare module "atom" {
jsSyntaxScopes: string[]
allowJS: boolean
tsserverInstancePerTsconfig: boolean
longLineLength: number
largeFileLineCount: number
largeFileNoFollowCursor: boolean
}
}
}
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,27 @@
"type": "boolean",
"default": false,
"order": 180
},
"longLineLength": {
"title": "Single line length that triggers semantic view large file optimizations",
"description": "Will throttle semantic view updates on the file if any one line is longer than this number; value of 0 means getting the value from the corresponding setting in linter-ui-default, or 4000 if that is unavaliable",
"type": "integer",
"default": 0,
"order": 200
},
"largeFileLineCount": {
"title": "Number of lines that triggers semantic view large file optimizations",
"description": "Will throttle semantic view updates on the file if it has more lines than this number; value of 0 means getting the value from the corresponding setting in linter-ui-default, or 500 if that is unavaliable",
"type": "integer",
"default": 0,
"order": 210
},
"largeFileNoFollowCursor": {
"title": "Disable semantic view focus following text cursor on large files",
"description": "If a file is large, as defined by previous options, don't update semantic view focus on text cursor moves; use typescript:reveal-in-semantic-view command instead",
"type": "boolean",
"default": false,
"order": 220
}
},
"deserializers": {
Expand Down

0 comments on commit 3bcb499

Please sign in to comment.