@chordbook/codemirror-lang-chordpro
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -1,6 +0,73 @@ | ||
import { ExternalTokenizer, LRParser } from '@lezer/lr'; | ||
import { syntaxTree, LRLanguage, LanguageSupport } from '@codemirror/language'; | ||
import { styleTags, tags } from '@lezer/highlight'; | ||
import { snippetCompletion, completeFromList } from '@codemirror/autocomplete'; | ||
import { ExternalTokenizer, LRParser } from '@lezer/lr'; | ||
import { linter } from '@codemirror/lint'; | ||
const ValueDirectives = [ | ||
"title", | ||
"subtitle", | ||
"artist", | ||
"album", | ||
"comment" | ||
]; | ||
const Directives = [ | ||
"start_of_verse", | ||
"end_of_verse", | ||
"start_of_chorus", | ||
"end_of_chorus", | ||
"start_of_tab", | ||
"end_of_tab" | ||
]; | ||
const snippets = [ | ||
.../*@__PURE__*/ValueDirectives.map(name => snippetCompletion(`{${name}: #{}}`, { label: name, type: "directive" })), | ||
.../*@__PURE__*/Directives.map(name => snippetCompletion(`{${name}}`, { label: name, type: "directive" })), | ||
/*@__PURE__*/snippetCompletion("\[${}\]", { label: "chord", type: "chord" }), | ||
/*@__PURE__*/snippetCompletion("{define: ${1:name} frets ${2:E} ${3:A} ${4:D} ${5:G} ${6:B} ${7:E} fingers ${8:E} ${9:A} ${10:D} ${11:G} ${12:B} ${13:E}}", { label: "define", type: "directive" }), | ||
/*@__PURE__*/snippetCompletion(/*@__PURE__*/` | ||
{start_of_tab} | ||
E | -#{1:-}--------------------------------| | ||
B | ----------------------------------| | ||
G | ----------------------------------| | ||
D | ----------------------------------| | ||
A | ----------------------------------| | ||
E | ----------------------------------| | ||
{end_of_tab} | ||
`.replaceAll(/^\s*/gm, ''), { label: "tab", type: "directive" }) | ||
]; | ||
// Get a list of all the chords used in the document | ||
function chordsUsed(state) { | ||
const chords = {}; | ||
syntaxTree(state).iterate({ | ||
enter(node) { | ||
if (node.type.name === "Chord") { | ||
const name = state.doc.sliceString(node.from, node.to); | ||
chords[name] = (chords[name] || 0) + 1; | ||
} | ||
} | ||
}); | ||
return chords; | ||
} | ||
function completeChords(context) { | ||
const word = context.matchBefore(/[^\[]*/); | ||
const chords = chordsUsed(context.state); | ||
return { | ||
from: word.from, | ||
options: Object.keys(chords).map(chord => { | ||
return { label: chord, type: "chord", boost: chords[chord] }; | ||
}) | ||
}; | ||
} | ||
const completeSnippets = /*@__PURE__*/completeFromList(snippets); | ||
function chordproCompletionSource(context) { | ||
let node = syntaxTree(context.state).resolveInner(context.pos, -1); | ||
if (node.name === "[" || node.name === "Chord") { | ||
return completeChords(context); | ||
} | ||
else { | ||
return completeSnippets(context); | ||
} | ||
} | ||
// This file was generated by lezer-generator. You probably shouldn't edit it. | ||
@@ -327,5 +394,9 @@ const Comment = 1, | ||
function ChordPro() { | ||
return new LanguageSupport(ChordProLanguage); | ||
return new LanguageSupport(ChordProLanguage, [ | ||
ChordProLanguage.data.of({ | ||
autocomplete: chordproCompletionSource | ||
}) | ||
]); | ||
} | ||
export { ChordPro, ChordProLanguage, exampleStringLinter }; |
{ | ||
"name": "@chordbook/codemirror-lang-chordpro", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "ChordPro language support for CodeMirror", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34852
809