MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / createBeatCompletions

Function createBeatCompletions

packages/lsp/src/server/completion.ts:141–213  ·  view source on GitHub ↗
(
    beat: alphaTab.importer.alphaTex.AlphaTexBeatNode,
    offset: number,
    endOfBeat: number
)

Source from the content-addressed store, hash-verified

139);
140
141function createBeatCompletions(
142 beat: alphaTab.importer.alphaTex.AlphaTexBeatNode,
143 offset: number,
144 endOfBeat: number
145): CompletionItem[] {
146 const completions: CompletionItem[] = [];
147
148 if (
149 beat.durationChange &&
150 beat.durationChange.start!.offset < offset &&
151 offset <= beat.durationChange!.end!.offset
152 ) {
153 const endOfDurationChange = beat.notes?.start?.offset ?? endOfBeat;
154 return createDurationChangeCompletions(beat.durationChange, offset, endOfDurationChange);
155 }
156
157 if (beat.notes && beat.notes.start!.offset < offset && offset <= beat.notes.end!.offset) {
158 const endOfNotes =
159 beat.notes?.closeParenthesis?.start?.offset ??
160 beat.durationDot?.start?.offset ??
161 beat.beatEffects?.start?.offset ??
162 beat.beatMultiplier?.start?.offset ??
163 endOfBeat;
164 const note = binaryNodeSearch(beat.notes.notes, offset, endOfNotes);
165 if (note) {
166 const noteIndex = beat.notes.notes.indexOf(note);
167 const endOfNote =
168 noteIndex === beat.notes.notes.length - 1 ? endOfNotes : beat.notes.notes[noteIndex + 1].start!.offset;
169 return createNoteCompletions(beat, note, offset, endOfNote);
170 }
171 }
172
173 const afterDuration = beat.beatMultiplier?.start?.offset ?? beat.beatEffects?.start?.offset ?? beat.end!.offset;
174
175 if (beat.durationDot && beat.durationDot.start!.offset < offset && (offset <= afterDuration || !beat.beatEffects)) {
176 const replacement: TextEdit[] | undefined = beat.durationValue
177 ? [
178 TextEdit.del({
179 start: {
180 line: beat.durationDot.end!.line - 1,
181 character: beat.durationDot.end!.col - 1
182 },
183 end: {
184 line: beat.durationValue!.end!.line - 1,
185 character: beat.durationValue!.end!.col - 1
186 }
187 })
188 ]
189 : undefined;
190
191 completions.push(
192 ...durationCompletionItems.map(
193 d =>
194 ({
195 ...d,
196 additionalTextEdits: replacement
197 }) satisfies CompletionItem
198 )

Callers 1

setupCompletionFunction · 0.85

Calls 8

binaryNodeSearchFunction · 0.90
createNoteCompletionsFunction · 0.85
indexOfMethod · 0.45
pushMethod · 0.45
mapMethod · 0.45
spliceMethod · 0.45

Tested by

no test coverage detected