Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Adds configuration option for large file warning threshold. #12439

Merged
merged 6 commits into from
Aug 18, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 20 additions & 14 deletions spec/workspace-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -432,31 +432,37 @@ describe "Workspace", ->
runs ->
expect(editor.largeFileMode).toBe true

describe "when the file is over 20MB", ->
it "prompts the user to make sure they want to open a file this big", ->
spyOn(fs, 'getSizeSync').andReturn 20 * 1048577 # 20MB
describe "when the file is over user-defined limit", ->
test = (size, shouldPrompt) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give this helper a more descriptive name?

spyOn(fs, 'getSizeSync').andReturn size * 1048577
atom.applicationDelegate.confirm.andCallFake -> selectedButtonIndex
atom.applicationDelegate.confirm()
selectedButtonIndex = 1 # cancel

editor = null
waitsForPromise ->
workspace.open('sample.js').then (e) -> editor = e
if shouldPrompt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If shouldPrompt is false, we should assert that it didn't prompt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would I do that, exactly? I'm not 100% familiar with Atom's internal structure...

runs ->
expect(editor).toBeUndefined()
expect(atom.applicationDelegate.confirm).toHaveBeenCalled()

runs ->
expect(editor).toBeUndefined()
expect(atom.applicationDelegate.confirm).toHaveBeenCalled()

atom.applicationDelegate.confirm.reset()
selectedButtonIndex = 0 # open the file
atom.applicationDelegate.confirm.reset()
selectedButtonIndex = 0 # open the file

waitsForPromise ->
workspace.open('sample.js').then (e) -> editor = e
waitsForPromise ->
workspace.open('sample.js').then (e) -> editor = e

runs ->
expect(atom.applicationDelegate.confirm).toHaveBeenCalled()
expect(editor.largeFileMode).toBe true

it "prompts the user to make sure they want to open a file this big", ->
atom.config.set "core.warnOnLargeFileLimit", 20
test 20, true
it "doesn't prompt on files below the limit", ->
atom.config.set "core.warnOnLargeFileLimit", 30
test 20, false
it "prompts for smaller files with a lower limit", ->
atom.config.set "core.warnOnLargeFileLimit", 5
test 10, true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you space this stuff out?

describe "when passed a path that matches a custom opener", ->
it "returns the resource returned by the custom opener", ->
fooOpener = (pathToOpen, options) -> {foo: pathToOpen, options} if pathToOpen?.match(/\.foo/)
Expand Down
4 changes: 4 additions & 0 deletions src/config-schema.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ module.exports =
{value: 'no', description: 'Do not send any telemetry data'}
{value: 'undecided', description: 'Undecided (Atom will ask again next time it is launched)'}
]
warnOnLargeFileLimit:
description: 'Warn before opening files larger than this number of megabytes.'
type: 'number'
default: 20
editor:
type: 'object'
properties:
Expand Down
2 changes: 1 addition & 1 deletion src/workspace.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ class Workspace extends Model
fileSize = fs.getSizeSync(filePath)

largeFileMode = fileSize >= 2 * 1048576 # 2MB
if fileSize >= 20 * 1048576 # 20MB
if fileSize >= @config.get('core.warnOnLargeFileLimit') * 1048576 # 20MB by default
choice = @applicationDelegate.confirm
message: 'Atom will be unresponsive during the loading of very large files.'
detailedMessage: "Do you still want to load this file?"
Expand Down