Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions lib/atom-less.coffee
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()

Copy link
Owner

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

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
36 changes: 4 additions & 32 deletions lib/firstline.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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 /.*/
Copy link
Owner

Choose a reason for hiding this comment

The 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "atom-less",
"main": "./lib/atom-less",
"version": "0.1.10",
"version": "0.1.11",
"description": "Atom plugin to compile .less files on save.",
"keywords": [
"atom",
Expand Down