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

Run linting in a Task #88

Merged
merged 11 commits into from
Aug 16, 2017
Merged

Run linting in a Task #88

merged 11 commits into from
Aug 16, 2017

Conversation

UziTech
Copy link
Member

@UziTech UziTech commented Aug 9, 2017

Run the core.coffee script as a Task in a separate process so it doesn't block the main UI thread on long files.

Fixes #87

TODO:

  • Upgrade to Linter v2
  • Run core.coffee in a Task
  • Test to make sure local coffeelint is used if available
  • Test to make sure local config file is used if available

@UziTech UziTech changed the title [wip] run core.coffee as a Task run core.coffee as a Task Aug 10, 2017
@UziTech
Copy link
Member Author

UziTech commented Aug 10, 2017

This seems to work great.

I did a little timing experiment:

lines sync async
100 ~50ms ~400ms
1000 ~6s ~800ms
2000 ~28s ~1.2s

400ms seems to be the amount of time to start a new child process on my machine so there might be a noticeable difference on small files, but large coffeescript files are now usable and can be linted on change 👍

Copy link
Member

@Arcanemagus Arcanemagus left a comment

Choose a reason for hiding this comment

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

Quick review just looking over the code, thanks for taking this on!


lint: (textEditor) ->
filePath = textEditor.getPath()
if filePath
Copy link
Member

Choose a reason for hiding this comment

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

You need an else here returning [] (to clear messages) or null (to tell Linter not to update any messages it might have for the file), otherwise you will return undefined and trigger a Linter message to the user that an invalid result was returned.

startCol = (textEditor.getTabLength() * indentLevel)
endCol = textEditor.getBuffer().lineLengthForRow(lineNumber - 1)

range = [[lineNumber - 1, startCol], [lineNumber - 1, endCol]]
Copy link
Member

Choose a reason for hiding this comment

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

Let's just bring in atom-linter and use generateRange here like almost every other provider. This function has a much smarter version of this logic in place 😉.

position: range
}

return new Promise (resolve) ->
Copy link
Member

Choose a reason for hiding this comment

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

Same story with the if above, you need to handle the Promise rejection and return a valid result ([] or null) to Linter.

lib/core.coffee Outdated

canImportModules: (coffeelint) ->
[major, minor, patch] = coffeelint.VERSION.split('.').map(toInt)
if major > 1
Copy link
Member

Choose a reason for hiding this comment

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

Any objection to just bringing in semver and using it here?

lib/core.coffee Outdated

coffeeLintPath = @_resolveCoffeeLint(filePath)
# Versions before 1.9.1 don't work with atom because of an assumption that
Copy link
Member

Choose a reason for hiding this comment

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

'atom' -> 'Atom'

@Arcanemagus Arcanemagus changed the title run core.coffee as a Task Run linting in a Task Aug 10, 2017
lib/core.coffee Outdated
lineNumber: 1
level: 'error'
message: 'CoffeeLint crashed, see console for error details.'
rule: 'none'
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm wondering if we should just let this throw a error instead of showing this on line 1

@Arcanemagus
Copy link
Member

@UziTech It seems like your npm version is out of date, I pushed a fixed package-lock.json up.

Copy link
Member

@Arcanemagus Arcanemagus left a comment

Choose a reason for hiding this comment

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

There is some room for future improvement such as making the Task a permanently running worker that doesn't need to take the initialization hit on each launch, but this is a great start.

Thanks @UziTech!

@Arcanemagus Arcanemagus merged commit 767972e into AtomLinter:master Aug 16, 2017
@Arcanemagus
Copy link
Member

Published in v1.3.0! 🎉

@UziTech UziTech deleted the async-Task branch January 29, 2020 22:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants