Skip to content

Commit 3bcb499

Browse files
committed
Merge branch 'pr/1575'
2 parents 4f877d6 + 0bfcd98 commit 3bcb499

File tree

5 files changed

+85
-8
lines changed

5 files changed

+85
-8
lines changed

dist/main.js

Lines changed: 2 additions & 2 deletions
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/views/outline/navigationTreeComponent.tsx

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import {CompositeDisposable, CursorPositionChangedEvent, Disposable, TextEditor} from "atom"
1+
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"
@@ -26,11 +27,38 @@ export class NavigationTreeComponent
2627
private editorChanging?: Disposable
2728
private getClient?: GetClientFunction
2829
private subscriptions = new CompositeDisposable()
30+
private longLineLength: number = 4000
31+
private largeFileLineCount: number = 500
2932

3033
constructor(public props: Props) {
3134
prepareNavTree(props.navTree)
3235
etch.initialize(this)
33-
this.subscriptions.add(atom.workspace.observeActiveTextEditor(this.subscribeToEditor))
36+
this.subscriptions.add(
37+
atom.workspace.observeActiveTextEditor(this.subscribeToEditor),
38+
atom.commands.add("atom-text-editor.typescript-editor" as "atom-text-editor", {
39+
"typescript:reveal-in-semantic-view": {
40+
description: "Reveal the symbol under the text cursor in semantic view",
41+
didDispatch: (event) => {
42+
const editor = event.currentTarget.getModel()
43+
this.selectAtCursorLine({newBufferPosition: editor.getCursorBufferPosition()})
44+
},
45+
},
46+
}),
47+
atom.config.observe("atom-typescript.longLineLength", (value) => {
48+
if (value > 0) this.longLineLength = value
49+
}),
50+
atom.config.observe("atom-typescript.largeFileLineCount", (value) => {
51+
if (value > 0) this.largeFileLineCount = value
52+
}),
53+
atom.config.observe("linter-ui-default.longLineLength", (value) => {
54+
if (atom.config.get("atom-typescript.longLineLength") > 0) return
55+
if (typeof value === "number") this.longLineLength = value
56+
}),
57+
atom.config.observe("linter-ui-default.largeFileLineCount", (value) => {
58+
if (atom.config.get("atom-typescript.largeFileLineCount") > 0) return
59+
if (typeof value === "number") this.largeFileLineCount = value / 6
60+
}),
61+
)
3462
}
3563

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

197-
this.editorScrolling = editor.onDidChangeCursorPosition(this.selectAtCursorLine)
198-
this.editorChanging = editor.onDidStopChanging(this.loadNavTree)
225+
const lineCount = this.lineCountIfLarge(editor)
226+
if (!atom.config.get("atom-typescript.largeFileNoFollowCursor") || lineCount === 0) {
227+
this.editorScrolling = editor.onDidChangeCursorPosition(this.selectAtCursorLine)
228+
}
229+
this.editorChanging = editor.onDidStopChanging(
230+
lineCount === 0 ? this.loadNavTree : debounce(this.loadNavTree, Math.max(lineCount / 5, 300)),
231+
)
232+
}
233+
234+
private lineCountIfLarge(editor: TextEditor) {
235+
const lineCount = editor.getLineCount()
236+
if (lineCount >= this.largeFileLineCount) {
237+
// large file detection
238+
return lineCount
239+
} else {
240+
// long line detection
241+
const buffer = editor.getBuffer()
242+
for (let i = 0, len = lineCount; i < len; i++) {
243+
if (buffer.lineLengthForRow(i) > this.longLineLength) {
244+
return this.longLineLength
245+
}
246+
}
247+
return 0 // small file
248+
}
199249
}
200250
}

lib/typings/atom-config.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ declare module "atom" {
4242
"atom-typescript.jsSyntaxScopes": string[]
4343
"atom-typescript.allowJS": boolean
4444
"atom-typescript.tsserverInstancePerTsconfig": boolean
45+
"atom-typescript.longLineLength": number
46+
"atom-typescript.largeFileLineCount": number
47+
"atom-typescript.largeFileNoFollowCursor": boolean
4548
"atom-typescript": {
4649
unusedAsInfo: boolean
4750
checkAllFilesOnSave: boolean
@@ -83,6 +86,9 @@ declare module "atom" {
8386
jsSyntaxScopes: string[]
8487
allowJS: boolean
8588
tsserverInstancePerTsconfig: boolean
89+
longLineLength: number
90+
largeFileLineCount: number
91+
largeFileNoFollowCursor: boolean
8692
}
8793
}
8894
}

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,27 @@
329329
"type": "boolean",
330330
"default": false,
331331
"order": 180
332+
},
333+
"longLineLength": {
334+
"title": "Single line length that triggers semantic view large file optimizations",
335+
"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",
336+
"type": "integer",
337+
"default": 0,
338+
"order": 200
339+
},
340+
"largeFileLineCount": {
341+
"title": "Number of lines that triggers semantic view large file optimizations",
342+
"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",
343+
"type": "integer",
344+
"default": 0,
345+
"order": 210
346+
},
347+
"largeFileNoFollowCursor": {
348+
"title": "Disable semantic view focus following text cursor on large files",
349+
"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",
350+
"type": "boolean",
351+
"default": false,
352+
"order": 220
332353
}
333354
},
334355
"deserializers": {

0 commit comments

Comments
 (0)