antares 0.2.2 → 0.3.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: 1c2ea1e51f704d6c2181103ad704401abb9977724f6139c02df420bdb711f71d
4
- data.tar.gz: fe214d18846dfa84a061ea93dc35415a92597f6b376469251333fb45b9a19b9e
3
+ metadata.gz: 7dc02698aeba01c20d7c2b18bfb93a35f5120af7ffbfbbe3f3a75913d05ad5b1
4
+ data.tar.gz: 7d041d5ab1a00e613cb31749b4896a159f7e32dbe0c2c8065fa760ca377699b3
5
5
  SHA512:
6
- metadata.gz: 38f5e5db511a43618e51175b2440addf02ccd8c2cd5d3b5607b66520f391924d47979a2d565f0e4a2375a3d492ed79cb5e8c255c469a16e136d446f73fdcd32a
7
- data.tar.gz: 7aae8c8a2e1e0159f15e0d794906cd6262b95b46f95a4b3437761ffb71ea9be935a42571c013142de99d9b440895db4ccbf9c35760f92ba427d4b0801440bc9c
6
+ metadata.gz: afdaaa7687bf45869d8d57d54e47fd0874765a15ffcb4c29410836d93e260960ef37af73e6965d4bf52ebda61f22db5975ec304eb9b21f7d1ef6561de8e7a079
7
+ data.tar.gz: 522cc236f6365a1523d0a2b114eccfd7a8eba16e04e588ec5b64940cefb1dc11a09e04ab7e42c83530e6ae87fd28aa4f2bb80eb82e8319bef1300e352002b5b9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 — 2026-09-25
4
+
5
+ - Add a CodeEditor highlighter adapter that maps Rouge scopes to theme syntax tokens.
6
+
3
7
  ## 0.2.2 — 2026-09-21
4
8
 
5
9
  - Add a deterministic syntax-highlighting demo image and regeneration task.
data/README.md CHANGED
@@ -93,6 +93,26 @@ structure.selection_ranges(1, 3) # inner-to-outer Antares::Region values
93
93
  Update the provider before calling `edit`. Line indices are zero based;
94
94
  `removed` is the old line count and `inserted` is the new line count.
95
95
 
96
+ For Zaniah 0.10's `UI::CodeEditor`, load `antares/zaniah_highlighter` and
97
+ pass the same buffer to `Antares::ZaniahHighlighter.new(lexer:, buffer:)` and
98
+ `CodeEditor.new(buffer:, highlighter:)`. The optional adapter translates Rouge
99
+ tokens into byte ranges and `Theme::Syntax` scopes. It updates Antares after
100
+ the editor changes the buffer; Antares itself does not depend on Zaniah.
101
+
102
+ | Rouge scope prefix | Syntax scope |
103
+ | --- | --- |
104
+ | `Keyword` | `keyword` |
105
+ | `Literal.String` | `string` |
106
+ | `Literal.Number` | `number` |
107
+ | `Comment` | `comment` |
108
+ | `Name.Function`, `Name.Builtin` | `function` |
109
+ | `Name.Class`, `Name.Namespace`, `Name.Decorator` | `type` |
110
+ | `Name.Constant` | `constant` |
111
+ | `Name.Variable` | `variable` |
112
+ | `Operator` | `operator` |
113
+ | `Punctuation` | `punctuation` |
114
+ | other | `text` |
115
+
96
116
  The `lines` provider returns one valid UTF-8 logical line for each index,
97
117
  preferably including its newline. Tokens contain text rather than offsets: sum
98
118
  `text.bytesize` for byte offsets or `text.length` for character offsets.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Antares
4
- VERSION = "0.2.2"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../antares"
4
+
5
+ module Antares
6
+ # Optional CodeEditor highlighter; load with require "antares/zaniah_highlighter".
7
+ class ZaniahHighlighter
8
+ def initialize(lexer:, buffer:)
9
+ unless buffer.respond_to?(:line_count) && buffer.respond_to?(:line)
10
+ raise ArgumentError, "buffer must provide line_count and line"
11
+ end
12
+ @buffer = buffer
13
+ @snapshot = lines
14
+ @highlighter = Highlighter.new(lexer: lexer,
15
+ lines: ->(index) { @buffer.line(index) }, line_count: -> { @buffer.line_count })
16
+ end
17
+
18
+ def tokens(index, text)
19
+ raise TypeError, "line text must be a String" unless text.is_a?(String)
20
+ return [] if text.empty?
21
+
22
+ offset = 0
23
+ @highlighter.tokens_for(index).filter_map do |kind, value|
24
+ first = offset
25
+ offset += value.bytesize
26
+ last = [offset, text.bytesize].min
27
+ [first...last, scope(kind)].freeze if last > first
28
+ end
29
+ end
30
+
31
+ def edited(_range, _replacement)
32
+ updated = lines
33
+ old = @snapshot
34
+ first = 0
35
+ first += 1 while first < old.length && first < updated.length && old[first] == updated[first]
36
+ old_end, new_end = old.length, updated.length
37
+ while old_end > first && new_end > first && old[old_end - 1] == updated[new_end - 1]
38
+ old_end -= 1
39
+ new_end -= 1
40
+ end
41
+ @highlighter.edit(from_line: first, removed: old_end - first, inserted: new_end - first) if
42
+ old_end != first || new_end != first
43
+ @snapshot = updated
44
+ self
45
+ end
46
+
47
+ private
48
+
49
+ # ponytail: snapshots scan all lines after edits; incremental line deltas can replace this if large-buffer editing profiles slow.
50
+ def lines = Array.new(@buffer.line_count) { |index| @buffer.line(index).dup.freeze }
51
+
52
+ def scope(kind)
53
+ name = kind&.qualname.to_s
54
+ case name
55
+ when /\AKeyword/ then :keyword
56
+ when /\ALiteral\.String/ then :string
57
+ when /\ALiteral\.Number/ then :number
58
+ when /\AComment/ then :comment
59
+ when /\AName\.(Function|Builtin)/ then :function
60
+ when /\AName\.(Class|Namespace|Decorator)/ then :type
61
+ when /\AName\.Constant/ then :constant
62
+ when /\AName\.Variable/ then :variable
63
+ when /\AOperator/ then :operator
64
+ when /\APunctuation/ then :punctuation
65
+ else :text
66
+ end
67
+ end
68
+ end
69
+ end
data/sig/antares.rbs CHANGED
@@ -72,6 +72,12 @@ module Antares
72
72
  def structure: () -> _Structure
73
73
  end
74
74
 
75
+ class ZaniahHighlighter
76
+ def initialize: (lexer: untyped, buffer: untyped) -> void
77
+ def tokens: (Integer index, String text) -> Array[[Range[Integer], Symbol]]
78
+ def edited: (Range[Integer] range, String replacement) -> self
79
+ end
80
+
75
81
  class Bracket < Struct[untyped]
76
82
  attr_accessor open_line: Integer
77
83
  attr_accessor open_column: Integer
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: antares
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yudai Takada
@@ -62,6 +62,7 @@ files:
62
62
  - lib/antares/tm_language_lexer.rb
63
63
  - lib/antares/tm_language_plist.rb
64
64
  - lib/antares/version.rb
65
+ - lib/antares/zaniah_highlighter.rb
65
66
  - sig/antares.rbs
66
67
  homepage: https://github.com/noxdea/antares
67
68
  licenses: