v2.4.1 release: scratchpad polish + demo cleanup
Maintenance release, no framework API changes. Scratchpad: Kill All Sound (⌘K) rename, mode-switch desync fix, code-completion prefix filtering restored (⌃Space Show Completions). Demos: GUIDemo voices + CLI EventPattern BlipVoice moved into Synthesizers/, EventPattern demo split into makeLead/makeBass, GUIDemo doc drift fixed (conductor default). LyrebirdScratch gains a SwiftPM package so the workspace shows it like GUIDemo (.xcodeproj kept for distribution). Linux live-coding scratchpad documented.
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
// SnippetCompletionFilterTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#if os(macOS) || os(Linux)
|
||||
import Testing
|
||||
@testable import LyrebirdLiveCompile
|
||||
|
||||
/// Unit coverage for the prefix narrowing that `SnippetCompletionService`
|
||||
/// applies to a raw sourcekit-lsp completion list. sourcekit-lsp returns a
|
||||
/// bare-identifier completion as the whole visible-symbol universe, unsorted and
|
||||
/// unfiltered; without this narrowing the editor floods with SDK globals and
|
||||
/// buries the real matches. No LSP server is launched — these exercise the pure
|
||||
/// `partialWord` / `filterAndRank` helpers.
|
||||
@Suite("Snippet completion prefix filtering")
|
||||
struct SnippetCompletionFilterTests {
|
||||
|
||||
private func item(_ label: String, sortText: String? = nil) -> LSPCompletionItem {
|
||||
LSPCompletionItem(
|
||||
label: label,
|
||||
detail: nil,
|
||||
insertText: label,
|
||||
kind: nil,
|
||||
sortText: sortText
|
||||
)
|
||||
}
|
||||
|
||||
// MARK: partialWord
|
||||
|
||||
@Test func partialWordReadsIdentifierBeforeCaretOnLaterLine() {
|
||||
let body: String = "// a comment line\ncontext.reportMessage(\"hi\")\nOscS"
|
||||
let prefix: String = SnippetCompletionService.partialWord(in: body, line: 2, character: 4)
|
||||
#expect(prefix == "OscS")
|
||||
}
|
||||
|
||||
@Test func partialWordIsEmptyRightAfterADot() {
|
||||
// Member completion: the char before the caret is `.`, not an identifier.
|
||||
let body: String = "let x = OscSin."
|
||||
let prefix: String = SnippetCompletionService.partialWord(in: body, line: 0, character: 15)
|
||||
#expect(prefix == "")
|
||||
}
|
||||
|
||||
@Test func partialWordIsEmptyAtLineStart() {
|
||||
let body: String = "foo\nbar"
|
||||
let prefix: String = SnippetCompletionService.partialWord(in: body, line: 1, character: 0)
|
||||
#expect(prefix == "")
|
||||
}
|
||||
|
||||
@Test func partialWordClampsCharacterPastLineEnd() {
|
||||
let body: String = "OscSin"
|
||||
let prefix: String = SnippetCompletionService.partialWord(in: body, line: 0, character: 999)
|
||||
#expect(prefix == "OscSin")
|
||||
}
|
||||
|
||||
@Test func partialWordStopsAtNonIdentifierBoundary() {
|
||||
let body: String = "Pan2(input: OscS"
|
||||
let prefix: String = SnippetCompletionService.partialWord(in: body, line: 0, character: 16)
|
||||
#expect(prefix == "OscS")
|
||||
}
|
||||
|
||||
// MARK: filterAndRank
|
||||
|
||||
@Test func filterDropsNonMatchingGlobalsAndKeepsPrefixMatches() {
|
||||
let items: [LSPCompletionItem] = [
|
||||
item("IOHIDTransactionSetDirection(_:_:)"),
|
||||
item("OscSaw"),
|
||||
item("kOSNotificationMessageID"),
|
||||
item("OscSin"),
|
||||
item("CFNetDiagnosticSetName(_:_:)"),
|
||||
]
|
||||
let out: [LSPCompletionItem] = SnippetCompletionService.filterAndRank(items, prefix: "OscS")
|
||||
let labels: [String] = out.map { $0.label }
|
||||
#expect(labels == ["OscSaw", "OscSin"])
|
||||
}
|
||||
|
||||
@Test func filterIsCaseInsensitiveAndRanksPrefixBeforeContains() {
|
||||
let items: [LSPCompletionItem] = [
|
||||
item("myOscSub"), // contains, not prefix
|
||||
item("oscSin"), // prefix (case-insensitive)
|
||||
item("Unrelated"),
|
||||
]
|
||||
let out: [LSPCompletionItem] = SnippetCompletionService.filterAndRank(items, prefix: "OSCS")
|
||||
let labels: [String] = out.map { $0.label }
|
||||
#expect(labels == ["oscSin", "myOscSub"])
|
||||
}
|
||||
|
||||
@Test func emptyPrefixKeepsEveryItemSortedBySortText() {
|
||||
// Member completion path: nothing is dropped, only ordered.
|
||||
let items: [LSPCompletionItem] = [
|
||||
item("Control", sortText: "2"),
|
||||
item("Audio", sortText: "1"),
|
||||
]
|
||||
let out: [LSPCompletionItem] = SnippetCompletionService.filterAndRank(items, prefix: "")
|
||||
#expect(out.map { $0.label } == ["Audio", "Control"])
|
||||
}
|
||||
|
||||
@Test func noMatchYieldsEmptyRatherThanGlobalFlood() {
|
||||
let items: [LSPCompletionItem] = [
|
||||
item("IOHIDTransactionSetDirection(_:_:)"),
|
||||
item("kOSNotificationMessageID"),
|
||||
]
|
||||
let out: [LSPCompletionItem] = SnippetCompletionService.filterAndRank(items, prefix: "OscS")
|
||||
#expect(out.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -97,7 +97,7 @@ struct LyrebirdScratchModelTests {
|
||||
await model.run(additive: false)
|
||||
model.clearTracked()
|
||||
#expect(model.trackedSynthCount == 0)
|
||||
#expect(model.statusMessage == "Cleared all synths (tracked + slots).")
|
||||
#expect(model.statusMessage == "Killed all sound (tracked synths + named slots cleared).")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user