-
Notifications
You must be signed in to change notification settings - Fork 7
Fixed compilation issues #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,15 @@ | ||
| {CompositeDisposable} = require 'atom' | ||
|
|
||
| renderer = require './less-renderer' | ||
|
|
||
| module.exports = | ||
| activate: (state) -> | ||
| @subscriptions = new CompositeDisposable | ||
|
|
||
| @subscriptions.add atom.commands.add 'atom-workspace', | ||
| 'core:save': => @render() | ||
| atom.workspace.observeTextEditors (editor) => | ||
| editor.onDidSave (event) => | ||
| @render event.path | ||
|
|
||
| deactivate: -> | ||
| @subscriptions.dispose() | ||
|
|
||
| serialize: -> | ||
|
|
||
| render: -> | ||
| editor = atom.workspace.getActiveTextEditor() | ||
| return if not editor | ||
|
|
||
| grammer = editor.getGrammar() | ||
| return if grammer.name.toLowerCase() != 'less' | ||
|
|
||
| filepath = editor.getPath() | ||
| render: (filepath) -> | ||
| renderer.render filepath | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,38 +3,10 @@ fs = require 'fs' | |
| class FirstLine | ||
| read: (filepath, callback) -> | ||
| @callback = callback | ||
| fs.open filepath, 'r', (err, fd) => | ||
| if (err) | ||
| callback err | ||
| else | ||
| @stats fd | ||
|
|
||
| stats: (fd) -> | ||
| fs.fstat fd, (err, stats) => | ||
| @startReading fd, stats.size | ||
|
|
||
| startReading: (fd, size) -> | ||
| @fd = fd | ||
|
|
||
| @buffer = new Buffer size | ||
| @buffer.fill 0 | ||
| @offset = 0 | ||
|
|
||
| @readFile() | ||
|
|
||
| readFile: -> | ||
| length = Math.min(16, @buffer.length - @offset) | ||
| fs.read @fd, @buffer, @offset, length, null, @onRead | ||
|
|
||
| onRead: (err, bytesRead, buffer) => | ||
| newline = buffer.indexOf '\n', @offset | ||
|
|
||
| if newline > -1 | ||
| fs.close @fd, (err) -> console.log err if err | ||
| line = buffer.toString undefined, 0, newline | ||
| @callback null, line | ||
| else | ||
| @offset += bytesRead | ||
| @readFile() | ||
| fs.readFile filepath, (err, fileData) => | ||
| if err != null | ||
| callback err | ||
| callback null, fileData.toString().match /.*/ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point of this file is to read the first line of a file in the most efficient way possible. So instead of reading in the entire file, which could be very large, we instead read as few bytes as possible while looking for the the newline separator. We then pass the first line to the callback. Your change is reading the entire file, and is actually passing a RegEx Match object, which is not what the callback is expecting, as far as I know. |
||
|
|
||
| module.exports = FirstLine | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably get rid of this too