spica 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 455f7fc3f7147d6d59a3e1a640930d8599f078b8819aa465224a27022480e5e8
4
- data.tar.gz: 1dfa01ddc8f1a5afda5eb554091e18a9096f630df332b50dc9962009cdfb2337
3
+ metadata.gz: '08bd3e463725a188508e13a5e8b06cc3a13e23f800bbcffdc32497ae1049955e'
4
+ data.tar.gz: 74f3ad3e94f36f424639620009721d711454ed7bb3a4e8ed29075cdde42993b3
5
5
  SHA512:
6
- metadata.gz: 2eba4b4ccf8b945eef7a2456607af4deb934944ea8bb33d802e6d306b799089cbb2d9f209b0a722a30cd0f9d5ace8d05af134d058b6c22b93a7f645e3c5bc0b9
7
- data.tar.gz: 29ec465710dd68cdd5e50f2e71b3a634cac39a446929e98a046d96db2308aa91dff52f4bc5fc8f9d550df9e81c2d0f3e76977f3438f03df2bb94a9b629fde5af
6
+ metadata.gz: 8fd3732d8cd1f5a69a604e52574277bfa739c5ceb6b326980ff649603fdda32ad2db57bdda106cb21bf291b606d8ca9c06d359570fff121e6fc99bfec7b5fc8b
7
+ data.tar.gz: b87874f50294213f1c69e4d38af61670334d87be9039ec2563cebba293341fbefdbe9fc808175383668753325ac7c92c7e46e47fc2dd76b7f88c74b48e6d70a5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0 — 2026-09-24
4
+
5
+ - Add an optional Zaniah matcher adapter with stable duplicate indices and UTF-8 highlight ranges.
6
+
3
7
  ## 0.1.1 — 2026-09-21
4
8
 
5
9
  - Add a deterministic fuzzy-matching demo image and regeneration task.
data/README.md CHANGED
@@ -120,6 +120,20 @@ Indexes deduplicate identical text. Removing and re-adding a candidate assigns i
120
120
 
121
121
  `Match#text` aliases `candidate`; `Match#index` is the stable registration ID. A session keeps the active prefix chain, while an unrelated query restarts from the full index. Display limits never discard candidates needed by the next query.
122
122
 
123
+ ### Zaniah command palettes and comboboxes
124
+
125
+ The optional adapter requires Zaniah 0.7 or newer (below 1.0). It converts Spica's Unicode character positions to the UTF-8 byte ranges used by Zaniah's highlights:
126
+
127
+ ```ruby
128
+ require "spica/zaniah_matcher"
129
+
130
+ matcher = Spica::ZaniahMatcher.new
131
+ Zaniah::UI::CommandPalette.new(commands, matcher: matcher)
132
+ # Or: Zaniah.configure { |config| config.matcher = matcher }
133
+ ```
134
+
135
+ The adapter preserves duplicate labels and reports each label's input-array index. This differs from `Spica::Match#index`, which identifies a deduplicated index entry. Non-UTF-8 multibyte labels are rejected because their original byte offsets cannot be used as Zaniah highlight ranges. The adapter does not implement optional incremental `refine`; Zaniah calls `match` on each query.
136
+
123
137
  ## Configuration
124
138
 
125
139
  Pass settings directly or reuse an immutable `Spica::Options` instance:
data/lib/spica/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Spica
4
4
  # Library semantic version.
5
- VERSION = "0.1.1"
5
+ VERSION = "0.2.0"
6
6
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spica"
4
+ require "zaniah/ui"
5
+
6
+ module Spica
7
+ # Optional adapter for Zaniah's command palette and combobox matcher API.
8
+ class ZaniahMatcher
9
+ def match(query, labels)
10
+ matcher = Matcher.new(query)
11
+ if query.empty?
12
+ return labels.each_index.map { |index| Zaniah::UI::Matcher::Match.new(index: index, score: 0.0, ranges: []) }
13
+ end
14
+
15
+ labels.each_with_index.filter_map do |label, index|
16
+ result = matcher.match(Candidate.new(label, index, precompute_mask: false))
17
+ next unless result
18
+
19
+ unless label.encoding == Encoding::UTF_8 || label.ascii_only?
20
+ raise ArgumentError, "Zaniah labels must be UTF-8 text"
21
+ end
22
+
23
+ offsets = [0]
24
+ label.each_char { |char| offsets << offsets.last + char.bytesize }
25
+ ranges = result.positions.map { |position| offsets[position]...offsets[position + 1] }
26
+ Zaniah::UI::Matcher::Match.new(index: index, score: result.score, ranges: ranges)
27
+ end.sort_by { |result| [-result.score, labels[result.index].length, result.index] }
28
+ end
29
+ end
30
+ end
data/sig/spica.rbs CHANGED
@@ -81,4 +81,9 @@ module Spica
81
81
  def matches: (?Integer limit) -> Array[Match]
82
82
  def total_matches: () -> Integer
83
83
  end
84
+
85
+ # Load with `require "spica/zaniah_matcher"`; the optional Zaniah gem supplies the result type.
86
+ class ZaniahMatcher
87
+ def match: (String query, Array[String] labels) -> Array[untyped]
88
+ end
84
89
  end
metadata CHANGED
@@ -1,16 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spica
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yudai Takada
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2026-09-21 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
- description:
14
12
  email:
15
13
  - t.yudai92@gmail.com
16
14
  executables: []
@@ -25,6 +23,7 @@ files:
25
23
  - lib/spica/index.rb
26
24
  - lib/spica/matcher.rb
27
25
  - lib/spica/version.rb
26
+ - lib/spica/zaniah_matcher.rb
28
27
  - sig/spica.rbs
29
28
  homepage: https://github.com/noxdea/spica
30
29
  licenses:
@@ -34,7 +33,6 @@ metadata:
34
33
  changelog_uri: https://github.com/noxdea/spica/blob/main/CHANGELOG.md
35
34
  allowed_push_host: https://rubygems.org
36
35
  rubygems_mfa_required: 'true'
37
- post_install_message:
38
36
  rdoc_options: []
39
37
  require_paths:
40
38
  - lib
@@ -49,8 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
47
  - !ruby/object:Gem::Version
50
48
  version: '0'
51
49
  requirements: []
52
- rubygems_version: 3.3.27
53
- signing_key:
50
+ rubygems_version: 3.6.9
54
51
  specification_version: 4
55
52
  summary: Deterministic fuzzy subsequence matching with incremental filtering
56
53
  test_files: []