-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from pulsar-edit/more-bundles
Additional Bundling of Core Packages
- Loading branch information
Showing
219 changed files
with
12,608 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# autocomplete+ snippet suggestions package | ||
|
||
Adds snippets to autocomplete+ suggestions | ||
|
||
## Features | ||
|
||
* Adds user snippets and language snippets to the autocomplete+ suggestions list |
26 changes: 26 additions & 0 deletions
26
packages/autocomplete-snippets/lib/autocomplete-snippets.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module.exports = { | ||
provider: null, | ||
|
||
activate() {}, | ||
|
||
deactivate() { | ||
this.provider = null | ||
}, | ||
|
||
provide() { | ||
if (this.provider == null) { | ||
const SnippetsProvider = require('./snippets-provider') | ||
this.provider = new SnippetsProvider() | ||
if (this.snippets != null) { | ||
this.provider.setSnippetsSource(this.snippets) | ||
} | ||
} | ||
|
||
return this.provider | ||
}, | ||
|
||
consumeSnippets(snippets) { | ||
this.snippets = snippets | ||
return (this.provider != null ? this.provider.setSnippetsSource(this.snippets) : undefined) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module.exports = | ||
class SnippetsProvider { | ||
constructor() { | ||
this.selector = '*' | ||
this.inclusionPriority = 1 | ||
this.suggestionPriority = 2 | ||
this.filterSuggestions = true | ||
|
||
this.showIcon = true | ||
this.snippetsSource = { | ||
snippetsForScopes(scopeDescriptor) { | ||
return atom.config.get('snippets', {scope: scopeDescriptor}) | ||
} | ||
} | ||
} | ||
|
||
setSnippetsSource(snippetsSource) { | ||
if (typeof (snippetsSource != null ? snippetsSource.snippetsForScopes : undefined) === "function") { | ||
return this.snippetsSource = snippetsSource | ||
} | ||
} | ||
|
||
getSuggestions({scopeDescriptor, prefix}) { | ||
if (!(prefix != null ? prefix.length : undefined)) { return } | ||
const scopeSnippets = this.snippetsSource.snippetsForScopes(scopeDescriptor) | ||
return this.findSuggestionsForPrefix(scopeSnippets, prefix) | ||
} | ||
|
||
findSuggestionsForPrefix(snippets, prefix) { | ||
if (snippets == null) { return [] } | ||
|
||
const suggestions = [] | ||
for (let snippetPrefix in snippets) { | ||
const snippet = snippets[snippetPrefix] | ||
if (!snippet || !snippetPrefix || !prefix || !firstCharsEqual(snippetPrefix, prefix)) { continue } | ||
suggestions.push({ | ||
iconHTML: this.showIcon ? undefined : false, | ||
type: 'snippet', | ||
text: snippet.prefix, | ||
replacementPrefix: prefix, | ||
rightLabel: snippet.name, | ||
rightLabelHTML: snippet.rightLabelHTML, | ||
leftLabel: snippet.leftLabel, | ||
leftLabelHTML: snippet.leftLabelHTML, | ||
description: snippet.description, | ||
descriptionMoreURL: snippet.descriptionMoreURL | ||
}) | ||
} | ||
|
||
suggestions.sort(ascendingPrefixComparator) | ||
return suggestions | ||
} | ||
|
||
onDidInsertSuggestion({editor}) { | ||
return atom.commands.dispatch(atom.views.getView(editor), 'snippets:expand') | ||
} | ||
} | ||
|
||
const ascendingPrefixComparator = (a, b) => a.text.localeCompare(b.text) | ||
|
||
const firstCharsEqual = (str1, str2) => str1[0].toLowerCase() === str2[0].toLowerCase() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "autocomplete-snippets", | ||
"main": "./lib/autocomplete-snippets", | ||
"version": "1.12.1", | ||
"description": "Adds snippets to autocomplete+ suggestions", | ||
"repository": "https://github.com/pulsa-edit/pulsar", | ||
"license": "MIT", | ||
"engines": { | ||
"atom": ">=0.174.0 <2.0.0" | ||
}, | ||
"providedServices": { | ||
"autocomplete.provider": { | ||
"versions": { | ||
"2.0.0": "provide" | ||
} | ||
} | ||
}, | ||
"consumedServices": { | ||
"snippets": { | ||
"versions": { | ||
"0.1.0": "consumeSnippets" | ||
} | ||
} | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
packages/autocomplete-snippets/spec/autocomplete-snippets-spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
describe('AutocompleteSnippets', () => { | ||
let [completionDelay, editor, editorView] = [] | ||
|
||
beforeEach(() => { | ||
atom.config.set('autocomplete-plus.enableAutoActivation', true) | ||
completionDelay = 100 | ||
atom.config.set('autocomplete-plus.autoActivationDelay', completionDelay) | ||
completionDelay += 100 // Rendering delay | ||
|
||
const workspaceElement = atom.views.getView(atom.workspace) | ||
jasmine.attachToDOM(workspaceElement) | ||
|
||
let autocompleteSnippetsMainModule = null | ||
let snippetsMainModule = null | ||
const autocompleteManager = null | ||
|
||
waitsForPromise(() => | ||
Promise.all([ | ||
atom.workspace.open('sample.js').then((e) => { | ||
editor = e | ||
editorView = atom.views.getView(editor) | ||
}), | ||
|
||
atom.packages.activatePackage('language-javascript'), | ||
atom.packages.activatePackage('autocomplete-snippets').then(({mainModule}) => autocompleteSnippetsMainModule = mainModule), | ||
|
||
atom.packages.activatePackage('autocomplete-plus'), | ||
atom.packages.activatePackage('snippets').then(({mainModule}) => { | ||
snippetsMainModule = mainModule | ||
snippetsMainModule.loaded = false | ||
}) | ||
]) | ||
) | ||
|
||
waitsFor('snippets provider to be registered', 1000, () => autocompleteSnippetsMainModule.provider != null) | ||
|
||
waitsFor('all snippets to load', 3000, () => snippetsMainModule.loaded) | ||
}) | ||
|
||
describe('when autocomplete-plus is enabled', () => { | ||
it('shows autocompletions when there are snippets available', () => { | ||
runs(() => { | ||
expect(editorView.querySelector('.autocomplete-plus')).not.toExist() | ||
|
||
editor.moveToBottom() | ||
editor.insertText('D') | ||
editor.insertText('o') | ||
|
||
advanceClock(completionDelay) | ||
}) | ||
|
||
waitsFor('autocomplete view to appear', 1000, () => editorView.querySelector('.autocomplete-plus span.word')) | ||
|
||
runs(() => { | ||
expect(editorView.querySelector('.autocomplete-plus span.word')).toHaveText('do') | ||
expect(editorView.querySelector('.autocomplete-plus span.right-label')).toHaveText('do') | ||
}) | ||
}) | ||
|
||
it("expands the snippet on confirm", () => { | ||
runs(() => { | ||
expect(editorView.querySelector('.autocomplete-plus')).not.toExist() | ||
|
||
editor.moveToBottom() | ||
editor.insertText('D') | ||
editor.insertText('o') | ||
|
||
advanceClock(completionDelay) | ||
}) | ||
|
||
waitsFor('autocomplete view to appear', 1000, () => editorView.querySelector('.autocomplete-plus span.word')) | ||
|
||
runs(() => { | ||
atom.commands.dispatch(editorView, 'autocomplete-plus:confirm') | ||
expect(editor.getText()).toContain('} while (true)') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('when showing suggestions', () => | ||
it('sorts them in alphabetical order', () => { | ||
const unorderedPrefixes = [ | ||
"", | ||
"dop", | ||
"do", | ||
"dad", | ||
"d" | ||
] | ||
|
||
const snippets = {} | ||
for (let x of Array.from(unorderedPrefixes)) { | ||
snippets[x] = {prefix: x, name: "", description: "", descriptionMoreURL: ""} | ||
} | ||
|
||
const SnippetsProvider = require('../lib/snippets-provider') | ||
const sp = new SnippetsProvider() | ||
sp.setSnippetsSource({snippetsForScopes(scope) { | ||
return snippets | ||
}}) | ||
const suggestions = sp.getSuggestions({scopeDescriptor: "", prefix: "d"}) | ||
|
||
const suggestionsText = suggestions.map(x => x.text) | ||
expect(suggestionsText).toEqual(["d", "dad", "do", "dop"]) | ||
}) | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("ohai"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Command Palette package | ||
|
||
Find and run available commands using <kbd>cmd-shift-p</kbd> (macOS) or <kbd>ctrl-shift-p</kbd> (Linux/Windows) in Pulsar. | ||
|
||
 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'.platform-darwin, .platform-darwin .command-palette atom-text-editor': | ||
'cmd-shift-p': 'command-palette:toggle' | ||
|
||
'.platform-win32, .platform-win32 .command-palette atom-text-editor': | ||
'ctrl-shift-p': 'command-palette:toggle' | ||
|
||
'.platform-linux, .platform-linux .command-palette atom-text-editor': | ||
'ctrl-shift-p': 'command-palette:toggle' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** @babel */ | ||
|
||
import {CompositeDisposable} from 'atom' | ||
import CommandPaletteView from './command-palette-view' | ||
|
||
class CommandPalettePackage { | ||
activate () { | ||
this.commandPaletteView = new CommandPaletteView() | ||
this.disposables = new CompositeDisposable() | ||
this.disposables.add(atom.commands.add('atom-workspace', { | ||
'command-palette:toggle': () => { | ||
this.commandPaletteView.toggle() | ||
}, | ||
'command-palette:show-hidden-commands': () => { | ||
this.commandPaletteView.show(true) | ||
} | ||
})) | ||
this.disposables.add(atom.config.observe('command-palette.useAlternateScoring', (newValue) => { | ||
this.commandPaletteView.update({useAlternateScoring: newValue}) | ||
})) | ||
this.disposables.add(atom.config.observe('command-palette.preserveLastSearch', (newValue) => { | ||
this.commandPaletteView.update({preserveLastSearch: newValue}) | ||
})) | ||
return this.commandPaletteView.show() | ||
} | ||
|
||
async deactivate () { | ||
this.disposables.dispose() | ||
await this.commandPaletteView.destroy() | ||
} | ||
} | ||
|
||
const pack = new CommandPalettePackage() | ||
export default pack |
Oops, something went wrong.