Merge branch 'master' into dh-async-repo

This commit is contained in:
joshaber 2015-12-28 13:04:22 -05:00
commit 50e1095ae1
4 changed files with 89 additions and 21 deletions

View File

@ -22,7 +22,7 @@
"clear-cut": "^2.0.1",
"coffee-script": "1.8.0",
"color": "^0.7.3",
"event-kit": "^1.3.0",
"event-kit": "^1.5.0",
"find-parent-dir": "^0.3.0",
"first-mate": "^5.1.1",
"fs-plus": "^2.8.0",
@ -53,7 +53,7 @@
"service-hub": "^0.7.0",
"source-map-support": "^0.3.2",
"temp": "0.8.1",
"text-buffer": "8.1.1",
"text-buffer": "8.1.3",
"typescript-simple": "1.0.0",
"underscore-plus": "^1.6.6",
"yargs": "^3.23.0"
@ -76,14 +76,14 @@
"autocomplete-atom-api": "0.9.2",
"autocomplete-css": "0.11.0",
"autocomplete-html": "0.7.2",
"autocomplete-plus": "2.24.0",
"autocomplete-plus": "2.25.0",
"autocomplete-snippets": "1.9.0",
"autoflow": "0.26.0",
"autosave": "0.23.0",
"background-tips": "0.26.0",
"bookmarks": "0.38.0",
"bracket-matcher": "0.79.0",
"command-palette": "0.37.0",
"command-palette": "0.38.0",
"deprecation-cop": "0.54.0",
"dev-live-reload": "0.47.0",
"encoding-selector": "0.21.0",
@ -98,7 +98,7 @@
"keybinding-resolver": "0.33.0",
"line-ending-selector": "0.3.0",
"link": "0.31.0",
"markdown-preview": "0.157.0",
"markdown-preview": "0.157.1",
"metrics": "0.53.1",
"notifications": "0.62.1",
"open-on-github": "0.40.0",
@ -118,7 +118,7 @@
"whitespace": "0.32.1",
"wrap-guide": "0.38.1",
"language-c": "0.51.1",
"language-clojure": "0.19.0",
"language-clojure": "0.19.1",
"language-coffee-script": "0.46.0",
"language-csharp": "0.11.0",
"language-css": "0.36.0",
@ -128,14 +128,14 @@
"language-html": "0.43.1",
"language-hyperlink": "0.16.0",
"language-java": "0.17.0",
"language-javascript": "0.104.0",
"language-javascript": "0.105.0",
"language-json": "0.17.2",
"language-less": "0.29.0",
"language-make": "0.21.0",
"language-mustache": "0.13.0",
"language-objective-c": "0.15.1",
"language-perl": "0.32.0",
"language-php": "0.34.0",
"language-php": "0.36.0",
"language-property-list": "0.8.0",
"language-python": "0.42.1",
"language-ruby": "0.65.0",

View File

@ -26,8 +26,13 @@ describe "TokenizedBuffer", ->
describe "serialization", ->
describe "when the underlying buffer has a path", ->
it "deserializes it searching among the buffers in the current project", ->
beforeEach ->
buffer = atom.project.bufferForPathSync('sample.js')
waitsForPromise ->
atom.packages.activatePackage('language-coffee-script')
it "deserializes it searching among the buffers in the current project", ->
tokenizedBufferA = new TokenizedBuffer({
buffer, config: atom.config, grammarRegistry: atom.grammars, packageManager: atom.packages, assert: atom.assert
})
@ -38,10 +43,25 @@ describe "TokenizedBuffer", ->
expect(tokenizedBufferB.buffer).toBe(tokenizedBufferA.buffer)
it "does not serialize / deserialize the current grammar", ->
tokenizedBufferA = new TokenizedBuffer({
buffer, config: atom.config, grammarRegistry: atom.grammars, packageManager: atom.packages, assert: atom.assert
})
autoSelectedGrammar = tokenizedBufferA.grammar
tokenizedBufferA.setGrammar(atom.grammars.grammarForScopeName('source.coffee'))
tokenizedBufferB = TokenizedBuffer.deserialize(
JSON.parse(JSON.stringify(tokenizedBufferA.serialize())),
atom
)
expect(tokenizedBufferB.grammar).toBe(atom.grammars.grammarForScopeName('source.js'))
describe "when the underlying buffer has no path", ->
it "deserializes it searching among the buffers in the current project", ->
beforeEach ->
buffer = atom.project.bufferForPathSync(null)
it "deserializes it searching among the buffers in the current project", ->
tokenizedBufferA = new TokenizedBuffer({
buffer, config: atom.config, grammarRegistry: atom.grammars, packageManager: atom.packages, assert: atom.assert
})
@ -52,6 +72,38 @@ describe "TokenizedBuffer", ->
expect(tokenizedBufferB.buffer).toBe(tokenizedBufferA.buffer)
it "deserializes the previously selected grammar as soon as it's added when not available in the grammar registry", ->
tokenizedBufferA = new TokenizedBuffer({
buffer, config: atom.config, grammarRegistry: atom.grammars, packageManager: atom.packages, assert: atom.assert
})
tokenizedBufferA.setGrammar(atom.grammars.grammarForScopeName("source.js"))
atom.grammars.removeGrammarForScopeName(tokenizedBufferA.grammar.scopeName)
tokenizedBufferB = TokenizedBuffer.deserialize(
JSON.parse(JSON.stringify(tokenizedBufferA.serialize())),
atom
)
expect(tokenizedBufferB.grammar).not.toBeFalsy()
expect(tokenizedBufferB.grammar).not.toBe(tokenizedBufferA.grammar)
atom.grammars.addGrammar(tokenizedBufferA.grammar)
expect(tokenizedBufferB.grammar).toBe(tokenizedBufferA.grammar)
it "deserializes the previously selected grammar on construction when available in the grammar registry", ->
tokenizedBufferA = new TokenizedBuffer({
buffer, config: atom.config, grammarRegistry: atom.grammars, packageManager: atom.packages, assert: atom.assert
})
tokenizedBufferA.setGrammar(atom.grammars.grammarForScopeName("source.js"))
tokenizedBufferB = TokenizedBuffer.deserialize(
JSON.parse(JSON.stringify(tokenizedBufferA.serialize())),
atom
)
expect(tokenizedBufferB.grammar).toBe(tokenizedBufferA.grammar)
describe "when the buffer is destroyed", ->
beforeEach ->
buffer = atom.project.bufferForPathSync('sample.js')

View File

@ -1,5 +1,10 @@
'use strict'
// For now, we're not using babel or ES6 features like `let` and `const` in
// this file, because `apm` requires this file directly in order to pre-warm
// Atom's compile-cache when installing or updating packages, using an older
// version of node.js
var path = require('path')
var fs = require('fs-plus')
var CSON = null
@ -159,8 +164,7 @@ require('source-map-support').install({
})
var prepareStackTraceWithSourceMapping = Error.prepareStackTrace
let prepareStackTrace = prepareStackTraceWithSourceMapping
var prepareStackTrace = prepareStackTraceWithSourceMapping
function prepareStackTraceWithRawStackAssignment (error, frames) {
if (error.rawStack) { // avoid infinite recursion

View File

@ -36,7 +36,7 @@ class TokenizedBuffer extends Model
constructor: (params) ->
{
@buffer, @tabLength, @ignoreInvisibles, @largeFileMode, @config,
@grammarRegistry, @packageManager, @assert
@grammarRegistry, @packageManager, @assert, grammarScopeName
} = params
@emitter = new Emitter
@ -49,18 +49,26 @@ class TokenizedBuffer extends Model
@disposables.add @buffer.preemptDidChange (e) => @handleBufferChange(e)
@disposables.add @buffer.onDidChangePath (@bufferPath) => @reloadGrammar()
@reloadGrammar()
if grammar = @grammarRegistry.grammarForScopeName(grammarScopeName)
@setGrammar(grammar)
else
@reloadGrammar()
@grammarToRestoreScopeName = grammarScopeName
destroyed: ->
@disposables.dispose()
serialize: ->
deserializer: 'TokenizedBuffer'
bufferPath: @buffer.getPath()
bufferId: @buffer.getId()
tabLength: @tabLength
ignoreInvisibles: @ignoreInvisibles
largeFileMode: @largeFileMode
state = {
deserializer: 'TokenizedBuffer'
bufferPath: @buffer.getPath()
bufferId: @buffer.getId()
tabLength: @tabLength
ignoreInvisibles: @ignoreInvisibles
largeFileMode: @largeFileMode
}
state.grammarScopeName = @grammar?.scopeName unless @buffer.getPath()
state
observeGrammar: (callback) ->
callback(@grammar)
@ -76,7 +84,9 @@ class TokenizedBuffer extends Model
@emitter.on 'did-tokenize', callback
grammarAddedOrUpdated: (grammar) =>
if grammar.injectionSelector?
if @grammarToRestoreScopeName is grammar.scopeName
@setGrammar(grammar)
else if grammar.injectionSelector?
@retokenizeLines() if @hasTokenForSelector(grammar.injectionSelector)
else
newScore = @grammarRegistry.getGrammarScore(grammar, @buffer.getPath(), @getGrammarSelectionContent())
@ -89,6 +99,8 @@ class TokenizedBuffer extends Model
@rootScopeDescriptor = new ScopeDescriptor(scopes: [@grammar.scopeName])
@currentGrammarScore = score ? @grammarRegistry.getGrammarScore(grammar, @buffer.getPath(), @getGrammarSelectionContent())
@grammarToRestoreScopeName = null
@grammarUpdateDisposable?.dispose()
@grammarUpdateDisposable = @grammar.onDidUpdate => @retokenizeLines()
@disposables.add(@grammarUpdateDisposable)